Posts

Showing posts from June, 2002

Filter Sqlalchemy Query Return Code Example

Example: sqlalchemy filter or from sqlalchemy import or_ filter ( or_ ( User.name == 'ed' , User.name == 'wendy' ))

Color Ids Minecraft Code Example

Example: minecraft color codes Color Chat Code MOTD Code Decimal Hexadecimal Dark Red § 4 \u00A74 11141120 AA0000 Red §c \u00A7c 16733525 FF5555 Gold § 6 \u00A76 16755200 FFAA00 Yellow §e \u00A7e 16777045 FFFF55 Dark Green § 2 \u00A72 43520 00 AA00 Green §a \u00A7a 5635925 55 FF55 Aqua §b \u00A7b 5636095 55 FFFF Dark Aqua § 3 \u00A73 43690 00 AAAA Dark Blue § 1 \u00A71 170 0000 AA Blue § 9 \u00A79 5592575 5555 FF Light Purple§d \u00A7d 16733695 FF55FF Dark Purple § 5 \u00A75 11141290 AA00AA White §f \u00A7f 16777215 FFFFFF Gray § 7 \u00A77 11184810 AAAAAA Dark Gray § 8 \u00A78 5592405 555555 Black § 0 \u00A70 0 000000

Can An Idempotent Matrix Be Complex?

Answer : A assume that by "can A A A be complex", you mean "can A A A have any non-real entries". Well, it can! For instance, take A = \pmatrix{1&i\\0&0} In general: for any complex column-vector x x x , A = x x ∗ x ∗ x A = \frac{xx^*}{x^*x} A = x ∗ x x x ∗ ​ (where ∗ * ∗ denotes the conjugate-transpose) is such a matrix. A projection to a subspace is idempotent. Therefore A A A has no reason to be real. For example, take a subspace S S S of C 2 \mathbb{C}^2 C 2 and A A A be the matrix of the projection on to S S S with respect to the standard basis. Any matrix A = \pmatrix{a&b\\c&1-a} will be idempotent provided that a 2 + b c = a a^2+bc=a a 2 + b c = a

Catching Errors In JavaScript Promises With A First Level Try ... Catch

Answer : You cannot use try-catch statements to handle exceptions thrown asynchronously, as the function has "returned" before any exception is thrown. You should instead use the promise.then and promise.catch methods, which represent the asynchronous equivalent of the try-catch statement. (Or use the async/await syntax noted in @Edo's answer.) What you need to do is to return the promise, then chain another .catch to it: function promise() { var promise = new Promise(function(resolve, reject) { throw('Oh no!'); }); return promise.catch(function(error) { throw(error); }); } promise().catch(function(error) { console.log('Caught!', error); }); Promises are chainable, so if a promise rethrows an error, it will be delegated down to the next .catch . By the way, you don't need to use parentheses around throw statements ( throw a is the same as throw(a) ). With the new async/await syntax you can achieve this

Change Font Size Without Messing With Tkinter Button Size

Answer : Typically, when you give a button a width, that width is measured in characters (ie: width=1 means the width of one average sized character). However, if the button has an image then the width specifies a size in pixels.   A button can contain both an image and text, so one strategy is to put a 1x1 pixel as an image so that you can specify the button size in pixels. When you do that and you change the font size, the button will not grow since it was given an absolute size. Here is an example that illustrates the technique. Run the code, then click on "bigger" or "smaller" to see that the text changes size but the button does not. import Tkinter as tk import tkFont def bigger(): size = font.cget("size") font.configure(size=size+2) def smaller(): size = font.cget("size") size = max(2, size-2) font.configure(size=size) root = tk.Tk() font = tkFont.Font(family="Helvetica", size=12) toolbar = tk.Fra

Arduino Substring Code Example

Example: arduino substring myString.substring(from, to)

Add Two Numbers In X86 Assembly Code Example

Example: add two numbers in assembly language data segment a db 09h b db 02h c dw ? data ends code segment assume cs:code,ds:data start: mov ax,data mov ds,ax mov al,a mov bl,b add al,bl mov c,ax int 3 code ends end start

Check If The File Exists In Bucket Ruby Code Example

Example: ruby check if a file exists # file? will only return true for files File.file?(filename) # Will also return true for directories File.exist?(filename)

Color Hex Code Generator Code Example

Example 1: rgb purple color ( 128 , 0 , 128 ) Hex # 800080 Example 2: html color codes < ! -- Check these best user friendly html color codes -- > # 1 ca69d #e31ce0 #c13e72 # 99 b34d # 3 affb9 # 6 c7093 #b35ba0 # 1 b1452

Can't Play This Video. Android VideoView Mp4 Recorded By Android Device

Answer : Please refer below code snippet...problem was with the path declaration.. String uriPath = "android.resource://"+getPackageName()+"/"+R.raw.aha_hands_only_cpr_english; Uri uri = Uri.parse(uriPath); mVideoView.setVideoURI(uri); Thats it... I tried everything mentioned before but it turns out that internet permission is needed to play a mp4 file. <uses-permission android:name="android.permission.INTERNET" />

Baguettebox Doesn't Show Next/previous Stepper

Answer : in your script add this {buttons: true} in baguetteBox try this baguetteBox.run('.labrador',{ buttons: true }); baguetteBox.run('.labrador',{ buttons: true }); <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"> <link href="https://feimosi.github.io/baguetteBox.js/css/baguetteBox.css" rel="stylesheet"/> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/baguettebox.js/1.10.0/baguetteBox.min.js"></script> <div class="labrador"> <a href="https:

Bootstrap Button Class With Icon Code Example

Example 1: bootstrap 4 button with icon <!-- Add icon library --> < link rel = " stylesheet " href = " https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css " > < button class = " btn " > < i class = " fa fa-home " > </ i > </ button > Example 2: how to icon button in html <! DOCTYPE html > < html > < head > < meta name = " viewport " content = " width=device-width, initial-scale=1 " > <!-- Add icon library --> < link rel = " stylesheet " href = " https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css " > < style > .btn { background-color : DodgerBlue ; border : none ; color : white ; padding : 12 px 16 px ; font-size : 16 px ; cursor : pointer ; } /* Darker background on mouse-over */ .btn :hover { background-color

Array Without First Element Code Example

Example 1: javascript remove first element from array var arr = [ 1 , 2 , 3 , 4 ] ; var theRemovedElement = arr . shift ( ) ; // theRemovedElement == 1 console . log ( arr ) ; // [2, 3, 4] Example 2: javascript remove first element from array let numbers = [ "I'm Not A Number!" , 1 , 2 , 3 ] ; numbers . shift ( ) ; Example 3: es6 remove first element of array var myarray = [ "item 1" , "item 2" , "item 3" , "item 4" ] ; //removes the first element of the array, and returns that element. alert ( myarray . shift ( ) ) ; //alerts "item 1" //removes the last element of the array, and returns that element. alert ( myarray . pop ( ) ) ; //alerts "item 4"

Bootstrap Class Float Right Code Example

Example 1: float right bootstrap < div class = " float-left " > Float left on all viewport sizes </ div > < br > < div class = " float-right " > Float right on all viewport sizes </ div > < br > < div class = " float-none " > Don't float on all viewport sizes </ div > Example 2: bootstrap align right To aligning div in bootstrap you can use bootstrap classes like 1. float-left 2. float-right 3. float-none < div class = " float-left " > Float left on all viewport sizes </ div > < br > < div class = " float-right " > Float right on all viewport sizes </ div > < br > < div class = " float-none " > Don't float on all viewport sizes </ div > Example 3: bootstrap 5 float right .float-start .float-end .float-none .float-sm-start .float-sm-end .float-sm-none .float-md-start .float-md-end .float-md-none .float-lg-s

Chart.js Number Format

Answer : There is no built-in functionality for number formatting in Javascript. I found the easiest solution to be the addCommas function on this page. Then you just have to modify your tooltipTemplate parameter line from your Chart.defaults.global to something like this: tooltipTemplate: "<%= addCommas(value) %>" Charts.js will take care of the rest. Here's the addCommas function: function addCommas(nStr) { nStr += ''; x = nStr.split('.'); x1 = x[0]; x2 = x.length > 1 ? '.' + x[1] : ''; var rgx = /(\d+)(\d{3})/; while (rgx.test(x1)) { x1 = x1.replace(rgx, '$1' + ',' + '$2'); } return x1 + x2; } Put tooltips in 'option' like this: options: { tooltips: { callbacks: { label: function(tooltipItem, data) { return tooltipItem.yLabel.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,'); } }

Check If Two Arrays Have Same Elements Javascript Code Example

Example 1: check if 2 arrays are equal javascript const a = [1, 2, 3]; const b = [4, 5, 6]; const c = [1, 2, 3]; function arrayEquals(a, b) { return Array.isArray(a) && Array.isArray(b) && a.length === b.length && a.every((val, index) => val === b[index]); } arrayEquals(a, b); // false arrayEquals(a, c); // true Example 2: check if 2 arrays are equal javascript var arraysMatch = function (arr1, arr2) { // Check if the arrays are the same length if (arr1.length !== arr2.length) return false; // Check if all items exist and are in the same order for (var i = 0; i < arr1.length; i++) { if (arr1[i] !== arr2[i]) return false; } // Otherwise, return true return true; }; Example 3: javascript Compare two arrays regardless of order const isEqual = (a, b) => JSON.stringify(a) === JSON.stringify(b); // Examples isEqual([1, 2, 3], [1, 2, 3]); // true isEqual([1, 2, 3], [1, '2', 3]); // false

C# Wpf File Select Dialog Code Example

Example: wpf choose file dialog all the Source code really helpfull recomend to check OpenFileDialog openFileDialog = new OpenFileDialog ( ) ; if ( openFileDialog . ShowDialog ( ) == true ) //if user chose a file { //do something }
Note This module is part of ansible-base and included in all Ansible installations. In most cases, you can use the short module name shell even without specifying the collections: keyword. Despite that, we recommend you use the FQCN for easy linking to the module documentation and to avoid conflicting with other collections that may have the same module name. New in version 0.2: of ansible.builtin Synopsis Parameters Notes See Also Examples Return Values Synopsis The shell module takes the command name followed by a list of space-delimited arguments. Either a free form command or cmd parameter is required, see the examples. It is almost exactly like the ansible.builtin.command module but runs the command through a shell ( /bin/sh ) on the remote node. For Windows targets, use the ansible.windows.win_shell module instead. Note This module has a corresponding action plugin . Parameters Parameter Choices/Defaults Comments chdir path added

If Else In Assembly Language 8086 Code Example

Example: if statement in assembly x86 INCLUDE asmlib.inc .data prompt BYTE "Enter a number" ,0 evenMsg BYTE "That number is even " , 0 oddMsg BYTE "That number is odd" , 0 divisor DWORD 2 .code main PROC mov edx, OFFSET prompt ; output the prompt call writeLine call readInt ; read in a number mov edx, 0 ; clear the edx for division div divisor ; can't divide by an immediate ; use a variable .IF edx == 0 ; if the remainder is 0 mov edx, OFFSET evenMsg ; it is an even number .ELSE mov edx, OFFSET oddMsg .ENDIF call writeLine ; write the message to the screen. exit main ENDP END main

Base32 Decoding

Answer : I had a need for a base32 encoder/decoder, so I spent a couple hours this afternoon throwing this together. I believe it conforms to the standards listed here: http://tools.ietf.org/html/rfc4648#section-6. public class Base32Encoding { public static byte[] ToBytes(string input) { if (string.IsNullOrEmpty(input)) { throw new ArgumentNullException("input"); } input = input.TrimEnd('='); //remove padding characters int byteCount = input.Length * 5 / 8; //this must be TRUNCATED byte[] returnArray = new byte[byteCount]; byte curByte = 0, bitsRemaining = 8; int mask = 0, arrayIndex = 0; foreach (char c in input) { int cValue = CharToValue(c); if (bitsRemaining > 5) { mask = cValue << (bitsRemaining - 5); curByte = (byte)(curByte | mask); bitsRemaining -= 5;

Bootstrap Select Dropdown List Placeholder

Answer : Yes just "selected disabled" in the option. <select> <option value="" selected disabled>Please select</option> <option value="">A</option> <option value="">B</option> <option value="">C</option> </select> Link to fiddle You can also view the answer at https://stackoverflow.com/a/5859221/1225125 Use hidden: <select> <option hidden >Display but don't show in list</option> <option> text 1 </option> <option> text 2 </option> <option> text 3 </option> </select> dropdown or select doesn't have a placeholder because HTML doesn't support it but it's possible to create same effect so it looks the same as other inputs placeholder $('select').change(function() { if ($(this).children('option:first-child').is(':selected'))

Add Pygame Module In PyCharm IDE

Answer : Well, you don't have to download it for PyCharm here. You probably know how it checks your code. Through the interpreter! You don't need to use complex command lines or anything like that. You need to is: Download the appropriate interpreter with PyGame included Open your PyCharm IDE (Make sure it is up to date) Go to File Press Settings (Or Ctrl + Alt + S) Double click on the option that looks like Project: Name_of_Project Click on Project Interpreter Choose the interpreter you want to use that includes PyGame as a module Save your options And you are ready to go! Here is an alternate (I have never done this, please try to test it) Add PyGame in the same folder as your PyCharm file (Your PyCharm stuff is always in a specific file placed by you during installation/upgrade) Please consider putting your PyCharm stuff inside a folder for easy access. I hope this helps you! For PyCharm 2017 do the following: File - Settings Double click on y

C/C++ Why To Use Unsigned Char For Binary Data?

Answer : In C the unsigned char data type is the only data type that has all the following three properties simultaneously it has no padding bits, that it where all storage bits contribute to the value of the data no bitwise operation starting from a value of that type, when converted back into that type, can produce overflow, trap representations or undefined behavior it may alias other data types without violating the "aliasing rules", that is that access to the same data through a pointer that is typed differently will be guaranteed to see all modifications if these are the properties of a "binary" data type you are looking for, you definitively should use unsigned char . For the second property we need a type that is unsigned . For these all conversion are defined with modulo arihmetic, here modulo UCHAR_MAX+1 , 256 in most 99% of the architectures. All conversion of wider values to unsigned char thereby just corresponds to truncation to the leas