Posts

Showing posts from March, 2005

Append Python Dictionary Code Example

Example 1: add new keys to a dictionary python d = { 'key' : 'value' } print ( d ) # {'key': 'value'} d [ 'mynewkey' ] = 'mynewvalue' print ( d ) # {'mynewkey': 'mynewvalue', 'key': 'value'} Example 2: Python dictionary append # to add key-value pairs to a dictionary: d1 = { "1" : 1 , "2" : 2 , "3" : 3 } # Define the dictionary d1 [ "4" ] = 4 # Add key-value pair "4" is key and 4 is value print ( d1 ) # will return updated dictionary Example 3: how to append to a dictionary in python d = { 'a' : 1 , 'b' : 2 } print ( d ) d [ 'a' ] = 100 # existing key, so overwrite d [ 'c' ] = 3 # new key, so add d [ 'd' ] = 4 print ( d ) Example 4: python append to dictionary dict = { 1 : 'one' , 2 : 'two' } # Print out the dict print ( dict )

Add Heading On Export Using Fputcsv Php

Answer : This worked for me. function downloadCSV($data) { $filename = date("Y-m-d").".csv"; header('Content-type: application/csv'); header('Content-Disposition: attachment; filename=' . $filename); header("Content-Transfer-Encoding: UTF-8"); $f = fopen('php://output', 'a'); fputcsv($f, array_keys($data[0])); foreach ($data as $row) { fputcsv($f, $row); } fclose($f); } Try this after opening the file, you want to write in e.g. i want to write a file at below path: $fp = fopen('csvfiles/myfile.csv','w') You have to enter headers separately, so for this make an array of headers like: $csv_fields=array(); $csv_fields[] = 'Enquiry id'; $csv_fields[] = 'Date'; $csv_fields[] = 'Name'; $csv_fields[] = 'Email'; $csv_fields[] = 'Telephone'; $csv_fields[] = 'Customer Request'; $csv_fields[] = 'Special R

Clear Table Mysql Code Example

Example 1: clear a table in mysql truncate tableName Example 2: mysql empty a table -- If you do not need a condition or limit the rows: TRUNCATE TABLE tblYourTable ; -- Not Foreign key constrained -- Or SET FOREIGN_KEY_CHECKS = 0 ; TRUNCATE YourTable1 ; TRUNCATE YourTable2 ; SET FOREIGN_KEY_CHECKS = 1 ; -- -------------------------------------------------------- -- Otherwise: DELETE FROM tblYourTable WHERE condition ; -- Or DELETE FROM tblYourTable LIMIT row_count ; Example 3: remove all records from table mysql /* Will delete all rows from your table. Next insert will take next auto increment id. */ DELETE from tableName ; /* Will delete all rows from your table but it will start from new row with 1. */ TRUNCATE tableName ; Example 4: delete all content in table mysql TRUNCATE tablename Example 5: how to delete all the rows in a table without deleting the table in mysql delete from tableName ;

Std::distance C++ Code Example

Example: std distance // Calculates the number of elements between first and last. # include <iterator> // std::distance # include <vector> // std::vector # include <algorithm> // Just if you use std::find vector < int > arr = { 2 , 5 , 3 , 8 , 1 } ; int size = std :: distance ( arr . begin ( ) , arr . end ( ) ) ; // 5 auto it = std :: find ( arr . begin ( ) , arr . end ( ) , 8 ) ; int position = std :: distance ( arr . begin ( ) , it ) ; // 3

Bootstrap V4.3.1 (https://getbootstrap.com/) Code Example

Example 1: bootstrap <!-- CSS --> < link rel = " stylesheet " href = " https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css " integrity = " sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2 " crossorigin = " anonymous " > <!-- jQuery and JS bundle w/ Popper.js --> < script src = " https://code.jquery.com/jquery-3.5.1.slim.min.js " integrity = " sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj " crossorigin = " anonymous " > </ script > < script src = " https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.bundle.min.js " integrity = " sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx " crossorigin = " anonymous " > </ script > Example 2: bootstrap 4 <!-- CSS only --> < link rel = " stylesheet " href = " ht

Bootstrap-vue B-table With Filter In Header

Answer : You can use the top-row slot to customise your own first-row. See below for a bare-bones example. new Vue({ el: '#app', data: { filters: { id: '', issuedBy: '', issuedTo: '' }, items: [{id:1234,issuedBy:'Operator',issuedTo:'abcd-efgh'},{id:5678,issuedBy:'User',issuedTo:'ijkl-mnop'}] }, computed: { filtered () { const filtered = this.items.filter(item => { return Object.keys(this.filters).every(key => String(item[key]).includes(this.filters[key])) }) return filtered.length > 0 ? filtered : [{ id: '', issuedBy: '', issuedTo: '' }] } } }) <link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap/dist/css/bootstrap.min.css"/><link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap-

Combining JQuery Isotope And Lazy Load

Answer : If you want to use isotope's sorting/filtering functions, you will need to set the failure_limit of lazyload and trigger the event with isotope's onLayout callback. jQuery(document).ready(function($) { var $win = $(window), $con = $('#container'), $imgs = $("img.lazy"); $con.isotope({ onLayout: function() { $win.trigger("scroll"); } }); $imgs.lazyload({ failure_limit: Math.max($imgs.length - 1, 0) }); }); Explanation According to the docs ( http://www.appelsiini.net/projects/lazyload ) After scrolling page Lazy Load loops though unloaded images. In loop it checks if image has become visible. By default loop is stopped when first image below the fold (not visible) is found. This is based on following assumption. Order of images on page is same as order of images in HTML code. With some layouts assumption this might be wrong. With an isotope sorted/filtered list, the p

Angular: How To Download A File From HttpClient?

Answer : Blobs are returned with file type from backend. The following function will accept any file type and popup download window: downloadFile(route: string, filename: string = null): void{ const baseUrl = 'http://myserver/index.php/api'; const token = 'my JWT'; const headers = new HttpHeaders().set('authorization','Bearer '+token); this.http.get(baseUrl + route,{headers, responseType: 'blob' as 'json'}).subscribe( (response: any) =>{ let dataType = response.type; let binaryData = []; binaryData.push(response); let downloadLink = document.createElement('a'); downloadLink.href = window.URL.createObjectURL(new Blob(binaryData, {type: dataType})); if (filename) downloadLink.setAttribute('download', filename); document.body.appendChild(downloadLink); downloadLink.click(); }

Best Way To Encode Degree Celsius Symbol Into Web Page?

Image
Answer : Try to replace it with &deg; , and also to set the charset to utf-8, as Martin suggests. &deg;C will get you something like this: If you really want to use the DEGREE CELSIUS character “℃”, then copy and paste is OK, provided that your document is UTF-8 encoded and declared as such in HTTP headers. Using the character reference &#x2103; would work equally well, and would work independently of character encoding, but the source would be much less readable. The problem with Blackberry is most probably a font issue. I don’t know about fonts on Blackberry, but the font repertoire might be limited. There’s nothing you can do about this in HTML, but you can use CSS, possibly with @font face . But there is seldom any reason to use the DEGREE CELSIUS. It is a compatibility character, included in Unicode due to its use in East Asian writing. The Unicode Standard explicitly says in Chapter 15 (section 15.2, page 497): “In normal use, it is better to represent

Assets File Project.assets.json Not Found. Run A NuGet Package Restore

Answer : To fix this error from Tools > NuGet Package Manager > Package Manager Console simply run: dotnet restore The error occurs because the dotnet cli does not create the all of the required files initially. Doing dotnet restore adds the required files. In my case the error was the GIT repository. It had spaces in the name, making my project unable to restore If this is your issue, just rename the GIT repository when you clone git clone http://Your%20Project%20With%20Spaces newprojectname In case when 'dotnet restore' not works, following steps may help: Visual Studio >> Tools >> Options >> Nuget Manager >> Package Sources Unchecked any third party package sources. Rebuild solution.

Bootstrap 4 Min .css Cdn Code Example

Example 1: jquery for bootstrap 4 < link rel = "stylesheet" href = "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity = "sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin = "anonymous" > Example 2: bootstrap 4 < ! doctype html > < html lang = "en" > < head > < ! -- Required meta tags -- > < meta charset = "utf-8" > < meta name = "viewport" content = "width=device-width, initial-scale=1, shrink-to-fit=no" > < ! -- Bootstrap CSS -- > < link rel = "stylesheet" href = "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity = "sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin = "anonymous" > < title > Hello , world ! < / title >

Await Vs Task.Wait - Deadlock?

Answer : Wait and await - while similar conceptually - are actually completely different. Wait will synchronously block until the task completes. So the current thread is literally blocked waiting for the task to complete. As a general rule, you should use " async all the way down"; that is, don't block on async code. On my blog, I go into the details of how blocking in asynchronous code causes deadlock. await will asynchronously wait until the task completes. This means the current method is "paused" (its state is captured) and the method returns an incomplete task to its caller. Later, when the await expression completes, the remainder of the method is scheduled as a continuation. You also mentioned a "cooperative block", by which I assume you mean a task that you're Wait ing on may execute on the waiting thread. There are situations where this can happen, but it's an optimization. There are many situations where it can't

Break For Javascript Code Example

Example 1: javascript line break //in JavaScript, you can declare a line break (or new line) //with the \n character. var linebreak = '\n' ; Example 2: javascript break out of loop //break out of for loop for ( i = 0 ; i < 10 ; i ++ ) { if ( i === 3 ) { break ; } } Example 3: break in if statement js breakme : if ( condition ) { // Do stuff if ( condition2 ) { // do stuff } else { break breakme ; } // Do more stuff } Example 4: javascript exeit from loop To stop a for loop early in JavaScript , you use break :

CharAt Java String Code Example

Example 1: get certain character from string java String words = "Hi There"; //creating a string var named 'words' char index = words.charAt(0); /* setting a variable 'index' to letter '0' of variable 'words'. In this case, index = 'H'.*/ System.out.println(index); //print var 'index' which will print "H" Example 2: String charAt() method in java // String charAt() method in java example public class StringCharAtMethodJava { public static void main(String[] args) { String strInput = "HelloWorldJava"; char ch1 = strInput.charAt(1); char ch2 = strInput.charAt(6); char ch3 = strInput.charAt(10); System.out.println("Character at 1st index is: " + ch1); System.out.println("Character at 6th index is: " + ch2); System.out.println("Character at 10th index is: " + ch3); } } Example 3: string char at java char ch=name.charAt(4);

Chrome - Disable Cache For Localhost Only?

Image
Answer : You can certainly prevent all your file from hitting the cache, but this is an all-or-nothing setting. You can't decide which files get cleared from the cache and which files stay in the cache. During development, since you are using Chrome, I'd recommend to enable the setting for "Disable cache (while DevTools is open)": If you are like me, cache will be disabled every time you have the DevTools panel opened. Another thing you can do is to instruct your server to bypass cache altogether for all your resources. Since jQuery is coming from a CDN, this no-cache setting won't apply for it. To disable cache for resources you can include the following response header: Cache-Control:no-cache, no-store In the browser, use this to refresh the page: Ctrl + Shift + R this will ignore the cache (whereas Ctrl+r will use the cache). yw :) If you are using Apache you can disable cache on your server (localhost) by placing .htaccess file into your htd

Android: Getting A File URI From A Content URI?

Answer : Just use getContentResolver().openInputStream(uri) to get an InputStream from a URI. http://developer.android.com/reference/android/content/ContentResolver.html#openInputStream(android.net.Uri) This is an old answer with deprecated and hacky way of overcoming some specific content resolver pain points. Take it with some huge grains of salt and use the proper openInputStream API if at all possible. You can use the Content Resolver to get a file:// path from the content:// URI: String filePath = null; Uri _uri = data.getData(); Log.d("","URI = "+ _uri); if (_uri != null && "content".equals(_uri.getScheme())) { Cursor cursor = this.getContentResolver().query(_uri, new String[] { android.provider.MediaStore.Images.ImageColumns.DATA }, null, null, null); cursor.moveToFirst(); filePath = cursor.getString(0); cursor.close(); } else { filePath = _uri.getPath(); } Log.d(&qu

Ascii Value Of Char In Python Code Example

Example 1: how to write the character from its ascii value in python c = 'p' x = ord ( c ) #it will give you the ASCII value stored in x chr ( x ) #it will return back the character Example 2: python convert ascii to char >> > chr ( 104 ) 'h' >> > chr ( 97 ) 'a' >> > chr ( 94 ) '^' Example 3: python convert ascii to char >> > ord ( 'h' ) 104 >> > ord ( 'a' ) 97 >> > ord ( '^' ) 94 Example 4: ascii values in python of c = 'p' print ( "The ASCII value of '" + c + "' is" , ord ( c ) )

Android ADB Device Offline, Can't Issue Commands

Answer : Try running adb devices after running adb kill-server . Security question pops up after that. Worked for me. I just got the same problem today after my Nexus 7 and Galaxy Nexus were updated to Android 4.2.2. The thing that fixed it for me was to upgrade the SDK platform-tools to r16.0.1. For me, this version was not displayed in my SDK Manager, so I pulled it down from http://dl.google.com/android/repository/platform-tools_r16.0.1-windows.zip directly. You then need to rename the platform-tools directory and unzip it to android-sdk-windows/platform-tools . Using the SDK Manager, I had also updated to the latest sdk-tools before this. If your whole Eclipse and ADT are ancient, you may need to update them as well, but I didn't need to. Note: you may need to run SDK Manager twice (once to update itself) before you will see the latest packages. It also seems to occur frequently when you connect to the device using the Wi-Fi mode (in Android Studio or in the cons

Android Sdk Missing Android Studio Code Example

Example: android stdio doesnt come with the sdk Go to the SDK Manager and click Edit... next to the field for the location of the SDK. Then an "SDK Setup" window should display. There you can download the SDK.