Posts

Showing posts from November, 2015

Create A Zip File From A Generator In Python?

Answer : The only solution is to rewrite the method it uses for zipping files to read from a buffer. It would be trivial to add this to the standard libraries; I'm kind of amazed it hasn't been done yet. I gather there's a lot of agreement the entire interface needs to be overhauled, and that seems to be blocking any incremental improvements. import zipfile, zlib, binascii, struct class BufferedZipFile(zipfile.ZipFile): def writebuffered(self, zipinfo, buffer): zinfo = zipinfo zinfo.file_size = file_size = 0 zinfo.flag_bits = 0x00 zinfo.header_offset = self.fp.tell() self._writecheck(zinfo) self._didModify = True zinfo.CRC = CRC = 0 zinfo.compress_size = compress_size = 0 self.fp.write(zinfo.FileHeader()) if zinfo.compress_type == zipfile.ZIP_DEFLATED: cmpr = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION, zlib.DEFLATED, -15) else: cmpr = None while

C++ Terminate Called Without An Active Exception

Answer : When a thread object goes out of scope and it is in joinable state, the program is terminated. The Standard Committee had two other options for the destructor of a joinable thread. It could quietly join -- but join might never return if the thread is stuck. Or it could detach the thread (a detached thread is not joinable). However, detached threads are very tricky, since they might survive till the end of the program and mess up the release of resources. So if you don't want to terminate your program, make sure you join (or detach) every thread. How to reproduce that error: #include <iostream> #include <stdlib.h> #include <string> #include <thread> using namespace std; void task1(std::string msg){ cout << "task1 says: " << msg; } int main() { std::thread t1(task1, "hello"); return 0; } Compile and run: el@defiant ~/foo4/39_threading $ g++ -o s s.cpp -pthread -std=c++11 el@defiant ~/foo4/39_threading

30inch To Cm Code Example

Example: inch to cm 1 inch = 2.54 cm

Composer Install Only One Package Code Example

Example 1: update particular package composer composer update doctrine/doctrine-fixtures-bundle Example 2: composer update php composer.phar update Example 3: composer update single package composer require { package/packagename }

How To Make Pill Button Code Example

Example: pill shape css border-radius : 5 px ; width : /* Optional */ ; height : /* Optional */ ;

Gcd Of N Numbers In C Code Example

Example 1: gcd of two numbers in c # include <stdio.h> int main ( ) { int n1 , n2 , i , gcd ; printf ( "Enter two integers: " ) ; scanf ( "%d %d" , & n1 , & n2 ) ; for ( i = 1 ; i <= n1 && i <= n2 ; ++ i ) { // Checks if i is factor of both integers if ( n1 % i == 0 && n2 % i == 0 ) gcd = i ; } printf ( "G.C.D of %d and %d is %d" , n1 , n2 , gcd ) ; return 0 ; } Example 2: gcd of two numbers in c # include <stdio.h> int main ( ) { int n1 , n2 ; printf ( "Enter two positive integers: " ) ; scanf ( "%d %d" , & n1 , & n2 ) ; while ( n1 != n2 ) { if ( n1 > n2 ) n1 -= n2 ; else n2 -= n1 ; } printf ( "GCD = %d" , n1 ) ; return 0 ; }

No Scrolling Css Code Example

Example 1: disable scroll css /* Answer to: "disable scroll css" */ /* You must set the height and overflow of the body, to disable scrolling. */ html , body { margin : 0 ; height : 100 % ; overflow : hidden } Example 2: css no scroll <!DOCTYPE html > <html > <head > <style > body { height : 5000 px ; /* Make this site really long */ width : 5000 px ; /* Make this site really wide */ overflow : hidden ; /* Hide scrollbars */ } </style> </head> <body> <h2>Hide scrollbars</h2> <p>This example will hide the scrollbars ( and the functionality - it is not possible to scroll inside the page ) .</p> <p>Try to remove <strong> overflow : hidden ; </strong> to see the effect.</p> </body> </html>

Std::thread Sleep Code Example

Example: cpp thread sleep // this_thread::sleep_for example # include <iostream> // std::cout, std::endl # include <thread> // std::this_thread::sleep_for # include <chrono> // std::chrono::seconds int main ( ) { std :: cout << "countdown:\n" ; for ( int i = 10 ; i > 0 ; -- i ) { std :: cout << i << std :: endl ; std :: this_thread :: sleep_for ( std :: chrono :: seconds ( 1 ) ) ; } std :: cout << "Lift off!\n" ; return 0 ; }

Android Studio - Android Emulator Wifi Connected With No Internet

Image
Answer : Stated below are the solutions for Windows and Mac, but similar solutions will work on any OS: On Windows Open Network and Sharing Center and click on current Connection Click on Properties Double Click on Internet Protocol Version 4 (TCP/IPv4) Set the Preferred and Alternate DNS servers as (Screenshot below) : 8.8.8.8 8.8.4.4 On Mac Go to Settings > Network > Advanced... > DNS Delete whatever entries you have there and add these two entries (Screenshot below): 8.8.8.8 8.8.4.4 Note: For Mac users, if the entries field is disabled and you're not able to edit it, click on the 'Lock' icon in the bottom area of that window and enter the password to be able to make changes Restart the emulator, and it should solve: Screenshots: Windows Mac Edit: This is the fix for a situation when the emulator's wifi has changed the DNS to some non-working DNS. While this works most of the time, there might also be other rea

Convert SVG To Transparent PNG With Antialiasing, Using ImageMagick

Answer : As a side note, I found that getting transparency was a bit tricky. Instead of using transparent , I had to use none . convert -background none in.svg out.png Inkscape will do this: inkscape \ --export-png=out.png --export-dpi=200 \ --export-background-opacity=0 --without-gui in.svg Update The terminology has changed: all the export params suppress gui, and the output parameter is now simply based on the file type. For example, a type of png will cause a file in /path/to/picture.svg to be exported as /path/to/picture.png (caution: this overwrites output). inkscape \ --export-type=png --export-dpi=200 \ --export-background-opacity=0 picture.svg Note cited wiki has quotes on --export-type=png , which is incorrect. Also if don't have Inkscape command line, MacOS can access via bash directly: /Applications/Inkscape.app/Contents/MacOS/inkscape Actually, reading imagemagick documentation: -antialias Enable/Disable of the rendering of anti-aliasing pix

Conda Install Matplotlib Python 2.7 Code Example

Example 1: install matplotlib conda conda install -c conda-forge matplotlib Example 2: conda install matplotlib conda install matplotlib

Completely Uninstall Node Windows Code Example

Example 1: how to uninstall node.JS How to remove / uninstall Node . js from Windows : 1. Run npm cache clean -- force 2. Uninstall from Programs & Features with the uninstaller . 3. Reboot ( or you probably can get away with killing all node - related processes from Task Manager ) . 4. Look for these folders and remove them ( and their contents ) if any still exist . Depending on the version you installed , UAC settings , and CPU architecture , these may or may not exist : C : \ Program Files ( x86 ) \ Nodejs C : \ Program Files \ Nodejs C : \ Users \ { User } \ AppData \ Roaming \ npm ( or % appdata % \npm ) C : \ Users \ { User } \ AppData \ Roaming \npm - cache ( or % appdata % \npm - cache ) C : \ Users \ { User } \ . npmrc ( and possibly check for that without the . prefix too ) C : \ Users \ { User } \ AppData \ Local \ Temp \npm - * 5. Check your % PATH % environment variable to ensure no references to No

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

Get Classes Of Element Jquery Code Example

Example 1: jquery get class name //jQuery get class name of element var className=$ ( '#myElementID' ) . attr ( 'class' ) ; Example 2: jquery class list $ ( '#elementID' ) . prop ( 'classList' ) ; Example 3: get all classes of element jquery var classList = $ ( '#divId' ) . attr ( 'class' ) . split ( /\s+/ ) ; $ .each ( classList , function ( index , item ) { if ( item === 'someClass' ) { //do something } } ) ; Example 4: jquery: get class list using element id $ ( '#elementID' ) . prop ( 'classList' ) . add ( 'yourClassName' ) $ ( '#elementID' ) . prop ( 'classList' ) . remove ( 'yourClassName' ) Example 5: jquery get all classes of a div var classes = $ ( '#test' ) . attr ( 'class' ) . split ( ' ' ) ; alert ( classes[ 0 ] ) ; // first class alert ( classes[ 1 ] ) ; // second class alert ( classes[ 2 ] ) ; // third class Example 6: h

Tb6600 Stepper Motor Driver Arduino Code Code Example

Example: tb6600 stepper motor driver arduino code int PUL = 7 ; //define Pulse pin int DIR = 6 ; //define Direction pin int ENA = 5 ; //define Enable Pin void setup ( ) { pinMode ( PUL , OUTPUT ) ; pinMode ( DIR , OUTPUT ) ; pinMode ( ENA , OUTPUT ) ; } void loop ( ) { for ( int i = 0 ; i < 6400 ; i ++ ) //Forward 5000 steps { digitalWrite ( DIR , LOW ) ; digitalWrite ( ENA , HIGH ) ; digitalWrite ( PUL , HIGH ) ; delayMicroseconds ( 50 ) ; digitalWrite ( PUL , LOW ) ; delayMicroseconds ( 50 ) ; } for ( int i = 0 ; i < 6400 ; i ++ ) //Backward 5000 steps { digitalWrite ( DIR , HIGH ) ; digitalWrite ( ENA , HIGH ) ; digitalWrite ( PUL , HIGH ) ; delayMicroseconds ( 50 ) ; digitalWrite ( PUL , LOW ) ; delayMicroseconds ( 50 ) ; } }

Css Text Strikethrough Code Example

Example 1: text-decoration css h1 { text-decoration : overline ; } h2 { text-decoration : line-through ; } h3 { text-decoration : underline ; } h4 { text-decoration : underline overline ; } Example 2: css strikethrough h1 { text-decoration : overline ; } h2 { text-decoration : line-through ; } h3 { text-decoration : underline ; } Example 3: css text strike h2 { text-decoration : line-through ; } Example 4: underline text using css /* Using 'text-decoration' property with 'underline' value. we can draw underline below the text using css */ <style > p { text-decoration : underline ; } </style> <p>Hello all Welcome here !!!</p> Example 5: css strikethrough html text style= "text-decoration: line-through;" Example 6: how to underline font in css h3 { text-decoration : underline ; }

An Iframe I Need To Refresh Every 30 Seconds (but Not The Whole Page)

Answer : You can put a meta refresh Tag in the irc_online.php <meta http-equiv="refresh" content="30"> OR you can use Javascript with setInterval to refresh the src of the Source... <script> window.setInterval("reloadIFrame();", 30000); function reloadIFrame() { document.frames["frameNameHere"].location.reload(); } </script> Let's assume that your iframe id= myIframe here is the code: <script> window.setInterval("reloadIFrame();", 30000); function reloadIFrame() { document.getElementById("myIframe").src="YOUR_PAGE_URL_HERE"; } </script> Okay... so i know that i'm answering to a decade question, but wanted to add something! I wanted to add a google calendar with special iframe parameters. Problem is that the calendar didn't work without it. 30 seconds is a bit short for my use, so i changed that in my own file to 15 minutes This worked for me. <script>

Adding Custom Fonts To IOS App Finding Their Real Names

Image
Answer : Use +[UIFont familyNames] to list all of the font family names known to the system. For each family name, you can then use +[UIFont fontNamesForFamilyName:] to list all of the font names known to the system. Try printing those out to see what name the system expects. Example code: static void dumpAllFonts() { for (NSString *familyName in [UIFont familyNames]) { for (NSString *fontName in [UIFont fontNamesForFamilyName:familyName]) { NSLog(@"%@", fontName); } } } Put that in your app, call it, and see what you get. If you see a name in the output that looks appropriate for your font, use it. Otherwise, perhaps you haven't properly added the font to your app. In swift 4.2+ use code given below: func dumpAllFonts() { for familyName in UIFont.familyNames { for fontName in UIFont.fontNames(forFamilyName: familyName) { print("\(fontName)") } } }