Posts

Showing posts from May, 2020

2d List In Python Code Example

Example 1: python initialize a 2d array x = [ [ foo for i in range ( 10 ) ] for j in range ( 10 ) ] # x is now a 10 x10 array of 'foo' ( which can depend on i and j if you want ) Example 2: how to input 2-d array in python matrix = [ input ( ) . split ( ) for i in range ( no_of_rows ) ] # if only row is given and the number of coloumn has to be decide by user matrix = [ [ input ( ) for j in range ( no_of_cols ) ] for i in range ( no_of_rows ) ] # if both row and coloumn has been taken as input from user Example 3: how to create 2d list in python o = [ ] for i in range ( 0 , rows ) : x = [ ] for j in range ( 0 , cols ) : x . append ( 0 ) o . append ( x ) # if you use [ [ 0 ] * cols ] * rows all rows will become the same list # so editing in one row will edit all rows Example 4: 2d array python array = [ [ value ] * lenght ] * height //example array = [ [ 0 ] * 5 ] * 10 print ( array ) Example 5: crea

Bcrypt Decrypt Nodejs Code Example

Example 1: how to hash password in node js npm i bcrypt const bcrypt = require('bcrypt'); async function hashIt(password){ const salt = await bcrypt.genSalt(6); const hashed = await bcrypt.hash(password, salt); } hashIt(password); // compare the password user entered with hashed pass. async function compareIt(password){ const validPassword = await bcrypt.compare(password, hashedPassword); } compareIt(password); Example 2: bcrypt compare hash and password var bcrypt = dcodeIO.bcrypt; /** One way, can't decrypt but can compare */ var salt = bcrypt.genSaltSync(10); /** Encrypt password */ bcrypt.hash('anypassword', salt, (err, res) => { console.log('hash', res) hash = res compare(hash) }); /** Compare stored password with new encrypted password */ function compare(encrypted) { bcrypt.compare('aboveusedpassword', encrypted, (err, res) => { // res == true or res

Brew Uninstall Node Code Example

Example 1: brew uninstall node brew uninstall node; which node; sudo rm -rf /usr/local/bin/node; sudo rm -rf /usr/local/lib/node_modules/npm/; brew doctor; brew cleanup --prune-prefix; Example 2: uninstall node js from mac sudo rm -rf ~/.npm ~/.nvm ~/node_modules ~/.node-gyp ~/.npmrc ~/.node_repl_history sudo rm -rf /usr/local/bin/npm /usr/local/bin/node-debug /usr/local/bin/node /usr/local/bin/node-gyp sudo rm -rf /usr/local/share/man/man1/node* /usr/local/share/man/man1/npm* sudo rm -rf /usr/local/include/node /usr/local/include/node_modules sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /usr/local/lib/dtrace/node.d sudo rm -rf /opt/local/include/node /opt/local/bin/node /opt/local/lib/node sudo rm -rf /usr/local/share/doc/node sudo rm -rf /usr/local/share/systemtap/tapset/node.stp brew uninstall node brew doctor brew cleanup --prune-prefix

Void Value Not Ignored As It Ought To B\ Code Example

Example: void value not ignored as it ought to be you ' re trying to capture the return value of a function for which the return type is void .

Coding Ninjas Referral Code Code Example

Example: referral coding ninjas Coding Ninjas Referral - Get Rs 1200 Discount on Coding Ninjas Course. Visit: https://cnoffers.github.io

Alert In Html W3 School Code Example

Example: javascript alert alert ( "string" ) ;

Clear Cmd Command Code Example

Example 1: clear terminal windows cls =============================== will clear the windows terminal Example 2: clear cmd just type cls and hit enter Example 3: clear in windows cmd cls #this command clears the command window in Windows Command Prompt Example 4: clear terminal on windows ; ------------------------------------------------------------------------- ; Cntr-L should clear screen ; ------------------------------------------------------------------------- #IfWinActive ahk_class ConsoleWindowClass ^L:: Send cls{Enter} return #IfWinActive

Facebook Fa Fa Icon Code Example

Example 1: fa fa-facebook < i class = "fa fa-facebook-square" aria - hidden = "true" > < / i > Example 2: font awesome facebook Font Awesome 5 : Letter F : < i class = "fab fa-facebook-f" > < / i > Round : < i class = "fab fa-facebook" > < / i > Square : < i class = "fab fa-facebook-square" > < / i > Messenger : < i class = "fab fa-facebook-messenger" > < / i >

Bootstrap Dropdown Not Working

Answer : I had the same problem. After a couple of hours of trouble shooting found that, I had <script type="text/javascript" src="Scripts/bootstrap.min.js"></script> <script type="text/javascript" src="Scripts/jquery-2.1.1.min.js"></script> instead of, <script type="text/javascript" src="Scripts/jquery-2.1.1.min.js"></script> <script type="text/javascript" src="Scripts/bootstrap.min.js"></script> Hope this helps someone I had the same problem when I included the bootstrap.min.js twice. Removed one of them and it began working. FYI: If you have bootstrap.js, you should not add bootstrap-dropdown.js. I'm unsure of the result with bootstrap.min.js.

What Does Error Expected Declaration Or Statement At End Of Input Code Example

Example: error: expected declaration or statement at end of input /*Normally that error occurs when a } was missed somewhere in the code*/

ApplicationDidEnterBackground And ApplicationWillEnterForeground Method Are Not Called When Pressed Home Button In IOS Simulator

Answer : On iOS13+, if you implement UIWindowSceneDelegate, it calls func sceneDidEnterBackground(_ scene: UIScene) , instead. The reason why applicationDidEnterBackground: and applicationDidEnterForeground: are never called is because these methods are used in joint with Application does not run in background this option can be found in your ***-info.plist . If this option is set to YES than your app will never call these methods, because these when you press the home button with an app that has set the option to YES the instance of the app that is running will get terminated so everytime you press the home button and then select the app icon a new instance is being created so it is using applicationWillTerminate: . The methods that Kirti mali has said would also be the incorrect methods to use for want you are after, the reason being is that applicationDidBecomeActive: and applicationWillResignActive: are used when something like when you answer a phone call. The instan

AddEntityFrameworkStores Can Only Be Called With A Role That Derives From IdentityRole In .NET Core 2.0

Answer : Long time since I asked this question, but here's how I deal with nowadays: Startup.cs services.AddIdentity<User, Role>() .AddEntityFrameworkStores<ApplicationDbContext>() .AddDefaultTokenProviders(); services.AddScoped<RoleManager<Role>>(); Entites: public class User : IdentityUser<int> { } public class Role : IdentityRole<int> { } For same issue, you can look at this:https://github.com/aspnet/Identity/issues/1364

Can We Change Package Name Of My Flutter App In Future Code Example

Example 1: change package name flutter flutter create --org com.yourdomain appname Example 2: flutter change package name Go to build.gradle in app module and rename applicationId "com.company.name" Go to Manifest.xml in app/src/main and rename package="com.company.name" and android:label="App Name" Go to Manifest.xml in app/src/debug and rename package="com.company.name" Go to Manifest.xml in app/src/profile and rename package="com.company.name" Go to app/src/main/kotlin/com/something/something/MainActivity.kt and rename package="com.company.name" Go to app/src/main/kotlin/ and rename each directory so that the structure looks like app/src/main/kotlin/com/company/name/ Go to pubspec.yaml in your project and change name: something to name: name, example :- if package name is com.abc.xyz the name: xyz Go to each dart file in lib folder and rename the imports to the modified name. Open XCode and open the runner f

Bootstrap-select Add Item And Select It

Answer : You have a typo. Instead of: $('#myselect').append('<option val="'+newitemnum+'">'+newitemdesc+'</option>'); You need: $('#myselect').append('<option value="'+newitemnum+'">'+newitemdesc+'</option>'); Here is a JSFiddle demo: http://jsfiddle.net/xbr5agqt/ The "Add and select 'Soy Sauce' option" button does the following: $("#myselect").append('<option value="'+newitemnum+'">'+newitemdesc+'</option>'); $("#myselect").val(4); $("#myselect").selectpicker("refresh"); One slightly faster approach (used by the "Add and select 'Relish' option" button) is to append the new <option> element with the selected attribute already applied: $("#myselect").append('<option value="'+newitemnum+'" selected=&

Best Data Type For Storing Currency Values In A MySQL Database

Answer : Something like Decimal(19,4) usually works pretty well in most cases. You can adjust the scale and precision to fit the needs of the numbers you need to store. Even in SQL Server, I tend not to use " money " as it's non-standard. The only thing you have to watch out for is if you migrate from one database to another you may find that DECIMAL(19,4) and DECIMAL(19,4) mean different things ( http://dev.mysql.com/doc/refman/5.1/en/precision-math-decimal-changes.html ) DBASE: 10,5 (10 integer, 5 decimal) MYSQL: 15,5 (15 digits, 10 integer (15-5), 5 decimal) Assaf's response of Depends on how much money you got... sounds flippant, but actually it's pertinant. Only today we had an issue where a record failed to be inserted into our Rate table, because one of the columns (GrossRate) is set to Decimal (11,4), and our Product department just got a contract for rooms in some amazing resort in Bora Bora, that sell for several million Pacif

100% Width Background Image With An 'auto' Height

Answer : Tim S. was much closer to a "correct" answer then the currently accepted one. If you want to have a 100% width, variable height background image done with CSS, instead of using cover (which will allow the image to extend out from the sides) or contain (which does not allow the image to extend out at all), just set the CSS like so: body { background-image: url(img.jpg); background-position: center top; background-size: 100% auto; } This will set your background image to 100% width and allow the height to overflow. Now you can use media queries to swap out that image instead of relying on JavaScript. EDIT: I just realized (3 months later) that you probably don't want the image to overflow; you seem to want the container element to resize based on it's background-image (to preserve it's aspect ratio), which is not possible with CSS as far as I know. Hopefully soon you'll be able to use the new srcset attribute on the img element

Yt 2 Mp3 Code Example

Example: yt to mp3 Youtube - DL works great . Download from https : //youtube-dl.org/. To use, type youtube-dl <url> --audio-format mp3

Background Color Css Gradient Code Example

Example 1: gradient image css #show_bg_2 { background-image : /*two color gradient over an image*/ linear-gradient ( to bottom , rgba ( 245 , 246 , 252 , 0.52 ) , rgba ( 117 , 19 , 93 , 0.73 ) ) , url ( 'images/background.jpg' ) ; width : 80 % ; height : 400 px ; background-size : cover ; } Example 2: css linear gradient #grad { background-image : linear-gradient ( to right , #f1b1b1 , #82e6e8 ) ; } Example 3: css horizontal gradient background color .foo { background-image : linear-gradient ( red , blue ) ; } Example 4: gradient css background /*From bottom to top*/ background : rgb ( 166 , 166 , 166 ) ; background : linear-gradient ( 0 deg , rgba ( 166 , 166 , 166 , 1 ) 0 % , rgba ( 255 , 255 , 255 , 1 ) 29 % ) ; Example 5: css gradient Here a codePen with cool gradient animations : https : //codepen.io/DevLorenzo/pen/ExgpvJM

Bar Graph From Dataframe Groupby

Image
Answer : copying data from your link and running df = pd.read_clipboard() then using your code df = df.replace(np.nan,0) df = df.groupby(['home_team'])['arrests'].mean() df.plot.bar() Good one by @piRSuared, and I just buitified his answer :) ## referenced to the answer by @piRSquared df = df.replace(np.nan,0) df = df.groupby(['home_team'])['arrests'].mean() ax = df.plot(kind='bar', figsize=(10,6), color="indigo", fontsize=13); ax.set_alpha(0.8) ax.set_title("My Bar Plot", fontsize=22) ax.set_ylabel("Some Heading on Y-Axis", fontsize=15); plt.show()