Posts

Showing posts from September, 2021

Access To Xmlhttprequest At Has Been Blocked By Cors Policy No 'access-control-allow-origin' Code Example

Example 1: has been blocked by CORS policy: Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response. response.setHeader("Access-Control-Allow-Origin", "*"); response.setHeader("Access-Control-Allow-Credentials", "true"); response.setHeader("Access-Control-Allow-Methods", "GET,HEAD,OPTIONS,POST,PUT"); response.setHeader("Access-Control-Allow-Headers", "Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers"); Example 2: javascript access to xmlhttprequest at from origin 'null' has been blocked by cors policy //Open the HTML file using live server, it will work

Count Number Of Lines In A Git Repository

Answer : xargs will do what you want: git ls-files | xargs cat | wc -l But with more information and probably better, you can do: git ls-files | xargs wc -l git diff --stat 4b825dc642cb6eb9a060e54bf8d69288fbee4904 This shows the differences from the empty tree to your current working tree. Which happens to count all lines in your current working tree. To get the numbers in your current working tree, do this: git diff --shortstat `git hash-object -t tree /dev/null` It will give you a string like 1770 files changed, 166776 insertions(+) . If you want this count because you want to get an idea of the project’s scope, you may prefer the output of CLOC (“Count Lines of Code”), which gives you a breakdown of significant and insignificant lines of code by language. cloc $(git ls-files) (This line is equivalent to git ls-files | xargs cloc . It uses sh ’s $() command substitution feature.) Sample output: 20 text files. 20 unique files. 6 fi

Convert Pandas Timestamp To Datetime Code Example

Example 1: convert date time to date pandas df [ 'date_column' ] = pd . to_datetime ( df [ 'datetime_column' ] ) . dt . date Example 2: pandas change dtype to timestamp pd . to_datetime ( df . column ) Example 3: convert column to timestamp pandas df2 = pd . to_datetime ( df [ 'col1' ] ) df2 Example 4: convert datetime to date pandas [ dt . to_datetime ( ) . date ( ) for dt in df . dates ]

Console Logging For React?

Image
Answer : If you're just after console logging here's what I'd do: export default class App extends Component { componentDidMount() { console.log('I was triggered during componentDidMount') } render() { console.log('I was triggered during render') return ( <div> I am the App component </div> ) } } Shouldn't be any need for those packages just to do console logging. Here are some more console logging "pro tips": console.table var animals = [ { animal: 'Horse', name: 'Henry', age: 43 }, { animal: 'Dog', name: 'Fred', age: 13 }, { animal: 'Cat', name: 'Frodo', age: 18 } ]; console.table(animals); console.trace Shows you the call stack for leading up to the console. You can even customise your consoles to make them stand out console.todo = function(msg) { console.log(‘ % c % s % s % s‘, ‘color: yellow; background - color: black;’, ‘–‘, msg, ‘

Guid C# Length Code Example

Example: c# guid length Guid . NewGuid ( ) . ToString ( ) => 36 characters ( Hyphenated ) e . g . 12345678 - 1234 - 1234 - 1234 - 123456789abc

ADB Over Wireless

Answer : Rooting is not required. With USB cable connected, port 5555 opened across all involved firewalls and debug mode enabled adb tcpip 5555 then look into wireless properties of your device and the network you use, to see which IP address have been granted to device (or configure your DHCP always to use the same for the device mac address). Then adb connect 192.168.1.133 (were 192.168.1.133 is a sample IP address). This is all. You can now use adb shell or adb install or adb upload or the like with USB cable plugged out. To switch back to USB mode, adb usb The device may also revert back to USB mode after reboot. This mode is needed for development of applications that use attached USB devices directly (USB port is used by device so cannot be used by ADB). It is briefly covered in the USB debugging section of the Android website. I ran into the same problem today and find that things are fine on my non-rooted 4.2 Galaxy Nexus device, but does not work on m

Js Add Style Display Block Code Example

Example 1: javascript display block document. getElementById ( "someElementId" ) .style.display = "block" ; Example 2: style display block js document. getElementById ( "myDIV" ) .style.display = "block" ;

What Is The Best Bastion Remnant In Minecraft Code Example

Example 1: types of bastions minecraft lol no i'm a speedrunner Example 2: types of bastion minecraft hey , are you into modding or something ?

After Windows 10 Upgrade I Can No Longer Access BIOS

Answer : This is a common problem in all Lenovo laptops. I also have faced this problem so many times. For solving this please go to the link(link of official Lenovo's support site) and download latest bios setup and install it. It will update your bios and all will be all right. Download bios set for window 8.1 and install it. The manual also is given in PDF format. http://support.lenovo.com/in/hi/products/laptops-and-netbooks/lenovo-g-series-laptops/lenovo-g580-notebook Update: After this again the same problem happens with me but this time I already have latest BIOS version installed in my system and the Lenovo don't allow the installation of same or lower version of the BIOS in existing latest BIOS. So I stuck there and can not do anything. I also approached to the Lenovo service center but they are also helpless they suggest me to change the motherboard which cost me around 10000 INR.

Format Specifier For Double Code Example

Example 1: format specifier fro float in printf printf ( "%0k.yf" float_variable_name ) Here k is the total number of characters you want to get printed . k = x + 1 + y ( + 1 for the dot ) and float_variable_name is the float variable that you want to get printed . Suppose you want to print x digits before the decimal point and y digits after it . Now , if the number of digits before float_variable_name is less than x , then it will automatically prepend that many zeroes before it . Example 2: what are format specifiers it is used during taking input and out put Int ( "%d" ) : Long ( "%ld" ) : Char ( "%c" ) : Float ( "%f" ) : Double ( "%lf" ) example : char ch = 'd' ; double d = 234.432 ; printf ( "%c %lf" , ch , d ) ; char ch ; double d ; scanf ( "%c %lf" , & ch , & d ) ; Example 3: double data type format in c % lf you can try

Tailwind UI Grid Code Example

Example 1: tailwind grid <div class= "grid grid-cols-3 gap-4" > <div> 1 </div> <!-- ... --> <div> 9 </div> </div> Example 2: tailwind grid <div class= "grid grid-cols-1 md:grid-cols-6" > <!-- ... --> </div>

Css Right Align In Center Of Screen Code Example

Example 1: css align center vertical and horizontal . parent - class { display : flex ; align - items : center ; justify - content : space - around ; } Example 2: how to center align the html element in css examples #inner { width : 50 % ; margin : 0 auto ; } # center text . center { text - align : center ; border : 3 px solid green ; }

Ng Class With Ngif Angular2 Code Example

Example 1: Angular 8 ngClass If [ngClass]= " { 'my-class' : step== 'step1' } " Example 2: add classon ng if [ngClass]= " { 'my-class' : step === 'step1' } "

Can Scp Copy Directories Recursively?

Answer : Solution 1: Yup, use -r : scp -rp sourcedirectory user@dest:/path -r means recursive -p preserves modification times, access times, and modes from the original file. Note: This creates the sourcedirectory inside /path thus the files will be in /path/sourcedirectory Solution 2: While the previous answers are technically correct, you should also consider using rsync instead. rsync compares the data on the sending and receiving sides with a diff mechanism so it doesn't have to resend data that was already previously sent. If you are going to copy something to a remote machine more than once, use rsync . Actually, it's good to use rsync every time because it has more controls for things like copying file permissions and ownership and excluding certain files or directories. In general: $ rsync -av /local/dir/ server:/remote/dir/ will synchronize a local directory with a remote directory. If you run it a second time and the contents of the loca

MiniCssExtractPlugin In Webpack Why Usage Code Example

Example 1: mini-css-extract-plugin sass //installation npm install --save-dev mini-css-extract-plugin //configuration const MiniCssExtractPlugin = require ( 'mini-css-extract-plugin' ) ; module .exports = { plugins: [ new MiniCssExtractPlugin () ] , module: { rules: [ { test : /\.css$/i , use : [MiniCssExtractPlugin.loader , 'css-loader' ] , } , ] , } , } ; Example 2: mini-css-extract-plugin npm install --save-dev mini-css-extract-plugin

Can A Div Have Multiple Classes (Twitter Bootstrap)

Answer : Sure, a div can have as many classes as you want (this is both regarding to bootstrap and HTML in general): <div class="active dropdown-toggle"></div> Just separate the classes by space. Also: Keep in mind some bootstrap classes are supposed to be used for the same stuff but in different cases (for example alignment classes, you might want something aligned left, right or center, but it has to be only one of them) and you shouldn't use them together, or you'd get an unexpected result, basically what will happen is that the class with the highest specificity will be the one applied (or if they have the same then it'll be the one that's defined last on the CSS). So you better avoid doing stuff like this: <p class="text-center text-left">Some text</p> Absolutely, divs can have more than one class and with some Bootstrap components you'll often need to have multiple classes for them to function as you w

Android Viewmode Import Code Example

Example 1: android viewmodel dependency dependencies { def lifecycle_version = "2.2.0" def arch_version = "2.1.0" // ViewModel implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version" // LiveData implementation "androidx.lifecycle:lifecycle-livedata:$lifecycle_version" // Lifecycles only (without ViewModel or LiveData) implementation "androidx.lifecycle:lifecycle-runtime:$lifecycle_version" // Saved state module for ViewModel implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:$lifecycle_version" // Annotation processor annotationProcessor "androidx.lifecycle:lifecycle-compiler:$lifecycle_version" // alternately - if using Java8, use the following instead of lifecycle-compiler implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version" // optional - helpers for implementing

Add Spaces In Equation Latex Code Example

Example 1: latex space in math mode \; - a thick space. \: - a medium space. \, - a thin space. \! - a negative thin space. Example 2: space latex math Spaces in mathematical mode. \begin{align*} f(x) &= x^2\! +3x\! +2 \\ f(x) &= x^2+3x+2 \\ f(x) &= x^2\, +3x\, +2 \\ f(x) &= x^2\: +3x\: +2 \\ f(x) &= x^2\; +3x\; +2 \\ f(x) &= x^2\ +3x\ +2 \\ f(x) &= x^2\quad +3x\quad +2 \\ f(x) &= x^2\qquad +3x\qquad +2 \end{align*}

Print Bottom View Of Binary Tree Code Example

Example: gfg bottom view of tree /* This is not the entire code. It's just the function which implements bottom view. You need to write required code. */ // Obj class is used to store node with it's distance from parent. class Obj { public : Node * root ; int dis ; Obj ( Node * node , int dist ) { root = node ; dis = dist ; } } ; // bottom view logic below. void bottomView ( Node * root ) { queue < Obj * > q ; q . push ( new Obj ( root , 0 ) ) ; map < int , int > m ; while ( ! q . empty ( ) ) { Obj * ob = q . front ( ) ; q . pop ( ) ; m [ ob -> dis ] = ob -> root -> data ; if ( ob -> root -> left != NULL ) q . push ( new Obj ( ob -> root -> left , ob -> dis - 1 ) ) ; if ( ob -> root -> right != NULL ) q . push ( new Obj ( ob -&

Android Webview Flutter Example

Example: add web view in flutter A Flutter plugin that provides a WebView widget . On iOS the WebView widget is backed by a WKWebView ; On Android the WebView widget is backed by a WebView . Usage Add webview_flutter as a dependency in your pubspec . yaml file . You can now include a WebView widget in your widget tree . See the WebView widget's Dartdoc for more details on how to use the widget . Android Platform Views The WebView is relying on Platform Views to embed the Android ’s webview within the Flutter app . By default a Virtual Display based platform view backend is used , this implementation has multiple keyboard . When keyboard input is required we recommend using the Hybrid Composition based platform views implementation . Note that on Android versions prior to Android 10 Hybrid Composition has some performance drawbacks . Using Hybrid Composition To enable hybrid composition , set WebView . platform

Configuring Supervisor For Daphne (Django Channels)

Answer : In the supervisor ASGI config file, in the following line command=/home/ubuntu/django_app/venv/bin/daphne -u /run/daphne/daphne%(process_num)d.sock --fd 0 --access-log - --proxy-headers mysite.asgi:application replace --fd 0 with --endpoint fd:fileno=0 . Issue: https://github.com/django/daphne/issues/234 Fabio's answer, with replacing the file descriptor parameter for the endpoint parameter, presents a quick workaround for this problem (which appeared to be a bug in the Daphne code). However, the fix in Daphne repository was quickly committed so that the original instructions work well. As a side note (for people still getting critical listen failures which I wrote about in the original question), please be sure that the physical location for socket files ( /run/daphne/ in my case) is accessible - I spent too much time just to discover that simply creating the daphne folder in /run catalog does the job (even though I run everything with sudo )... For precautionary m

First Child Selector Jquery Code Example

Example 1: firstElementChild jquery equivalent $ ( '#myList > li:first-child' ) ; // or $ ( '#myList' ) . children ( 'li:first-child' ) ; // or $ ( '#myList > li' ) . first ( ) ; // or $ ( '#myList' ) . children ( ) . first ( ) ; // and so on Example 2: jquery first child $ ( 'div:first-child' ) Example 3: jquery first child $ ( "li" ) . first ( ) . css ( "background-color" , "red" ) ;

Can One Use Environment Variables In Inno Setup Scripts?

Answer : I ran into the same problem when trying to specify the source location of files in the [Files] section. I used the GetEnv function to define a new constant. #define Qt5 GetEnv('QT5') [Files] Source: {#Qt5}\bin\Qt5Concurrent.dll; DestDir: {app}; According to this page in the Inno Setup documentation, the value of environment variables can be retrieved using the following syntax: {%name|default} On install-time If you need to resolve the variable on the target machine, while installing, you can use the {%NAME|DefaultValue} "constant". [Files] Source: "MyApp.dat"; Dest: "{%MYAPP_DATA_PATH|{app}}" If you need to resolve the variable on the target machine in Pascal Script code, you can use GetEnv support function. Path := GetEnv('MYAPP_DATA_PATH'); On compile-time If you need to resolve the variable on the source machine, while compiling the installer, you can use GetEnv preprocessor function: [Files] Sourc

Bootstrap Radio Button "checked" Flag

Answer : Assuming you want a default button checked. <div class="row"> <h1>Radio Group #2</h1> <label for="year" class="control-label input-group">Year</label> <div class="btn-group" data-toggle="buttons"> <label class="btn btn-default"> <input type="radio" name="year" value="2011">2011 </label> <label class="btn btn-default"> <input type="radio" name="year" value="2012">2012 </label> <label class="btn btn-default active"> <input type="radio" name="year" value="2013" checked="">2013 </label> </div> </div> Add the active class to the button ( label tag) you want defaulted and checked="" to

Enlever Puce Automatique Ul Css Code Example

Example: css retirer les puces list-style : none ;

Js Window Scroll To Top Code Example

Example 1: Scroll to the top of the page using JavaScript? // Get The Id var topPage = document .getElementById ( `top-page` ) // On Click , Scroll to the Top of Page topPage .onclick = ( ) = > window .scrollTo ( { top : 0 , behavior : 'smooth' } ) // On scroll , Show/Hide the button window .onscroll = ( ) = > { window.scrollY > 500 ? ( topPage.style.display = 'block' ) : ( topPage.style.display = 'none' ) } // CSS body { background-color : #111 ; height : 5000 px ; } #top-page { width : 50 px ; position : fixed ; right : 30 px ; bottom : 30 px ; cursor : pointer ; color : white ; display : none ; } // HTML <img id= "top-page" src= "https://svgshare.com/i/LW3.sv" alt= "Top" > Example 2: scrool to top jquerry $ ( "a [ href = '#top' ] " ) .click ( function ( ) { $ ( "html , body" ) .animate ( { scrollTop : 0 } , "slow&q

Can Villagers Open Iron Doors Minecraft Code Example

Example: can villagers open iron doors Villagers can't open fence gates or trap doors, nor can they use buttons or levers, allowing you to use iron doors, iron trapdoors, or just about any redstone-based door mechanism without them being able to escape.

Fontawesome.com Cdn Code Example

Example 1: fontawesome cdn < link href = "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/css/all.min.css" rel = "stylesheet" > Example 2: font awesome cdn < link rel = "stylesheet" href = "https://pro.fontawesome.com/releases/v5.10.0/css/all.css" integrity = "sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin = "anonymous" / > Example 3: font awesome 4.7 cdn < link rel = "stylesheet" href = "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" integrity = "sha256-eZrrJcwDc/3uDhsdt61sL2oOBY362qM3lon1gyExkL0=" crossorigin = "anonymous" / > Example 4: font awesome icons cdn To load all styles : < link rel = "stylesheet" href = "https://pro.fontawesome.com/releases/v5.10.0/css/all.css" integrity = "sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfG

Compute Date Out Of Timestamp From Binance-API (Python)

Answer : You could use this: from datetime import datetime datetime.fromtimestamp(int("1518308894652")) But python says the year is out of range (understandably, considering it says it's 50087). So I suspect that serverTime is not a normal timestamp. But assuming the response that you got was the timestamp, so you don't need to do any other conversions other than turning the string into an int. Edit: Turns out the docs say "All time and timestamp related fields are in milliseconds." So just divide the response by 1000 and you'll be fine: datetime.fromtimestamp(int("1518308894652")/1000) . Source Your response is in milliseconds when datetime.fromtimestamp requires seconds. import datetime print(datetime.datetime.fromtimestamp(1518308894652/1000)) # 2018-02-10 19:28:14.652000