Posts

Showing posts from November, 2012

Create Clone Of Table Row And Append To Table In JavaScript

Answer : If you don't wish to use jQuery, there are a couple of simple functions you could use, like cloneNode() , createElement() and appendChild() . Here is a simple demonstration that appends a row to the end of the table using either the clone or create method. Tested in IE8 and FF3.5. <html> <head> <script type="text/javascript"> function cloneRow() { var row = document.getElementById("rowToClone"); // find row to copy var table = document.getElementById("tableToModify"); // find table to append to var clone = row.cloneNode(true); // copy children too clone.id = "newID"; // change id or other attributes/contents table.appendChild(clone); // add new row to end of table } function createRow() { var row = document.createElement('tr'); // create row node var col = document.createElement('td'); // create column node var col2 = document.createEl

Enable UnityEngine.Input Code Example

Example: unity how to get input using UnityEngine ; using System . Collections ; public class ExampleClass : MonoBehaviour { public void Update ( ) { if ( Input . GetButtonDown ( "Fire1" ) ) { Debug . Log ( Input . mousePosition ) ; } } }

Break Js Loops Code Example

Example: javascript break out of loop //break out of for loop for ( i = 0 ; i < 10 ; i ++ ) { if ( i === 3 ) { break ; } }

Bootstrap Infobox Example

Example 1: bootstrap errors < div class = " alert alert-primary " role = " alert " > This is a primary alert—check it out! </ div > < div class = " alert alert-secondary " role = " alert " > This is a secondary alert—check it out! </ div > < div class = " alert alert-success " role = " alert " > This is a success alert—check it out! </ div > < div class = " alert alert-danger " role = " alert " > This is a danger alert—check it out! </ div > < div class = " alert alert-warning " role = " alert " > This is a warning alert—check it out! </ div > < div class = " alert alert-info " role = " alert " > This is a info alert—check it out! </ div > < div class = " alert alert-light " role = " alert " > This is a light alert—check it out

Convert Tiff To Jpg In Php?

Answer : In the forum at http://www.php.net/gd the following comment is written: IE doesn't show TIFF files and standard PHP distribution doesn't support converting to/from TIFF. ImageMagick (http://www.imagemagick.org/script/index.php) is a free software that can read, convert and write images in a large variety of formats. For Windows users it includes a PHP extension php_magickwand_st.dll (and yes, it runs under PHP 5.0.4). When converting from TIFF to JPEG, you must also convert from CMYK color space to RGB color space as IE can't show CMYK JPGs either. Please note: -TIFF files may have RGB or CMYK color space -JPEG files may have RGB or CMYK color space Here are example functions using ImageMagick extension: - convert TIFF to JPEG file formats - convert CMIK to RGB color space - set image resolution to 300 DPIs (doesn't change image size in pixels) <?php function cmyk2rgb($file) { $mgck_wnd = NewMagickWand(); MagickReadImage($mgck_wnd, $file); $im

Cordova InAppBrowser - How To Disable URL And Navigation Bar?

Answer : To remove the URL, just set the ' location ' option to " no ". var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=no'); On Android, this removes the 'Back/Forward' buttons, URL and 'Done' button, not just the URL, but thankfully there’s a special Android-only ‘ hideurlbar ’ option to remove ONLY the URL. var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', ‘hideurlbar=yes’); The 'Done' button text can be changed by adding a ' closebuttoncaption ' option. (Now works on Android if using InAppBrowser plugin v2.0.2 or above.) var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'closebuttoncaption=My Button Name'); On iOS, the toolbar can be removed by setting the ' toolbar ' option to " no ". var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'toolbar=no'

Css Filter Color Code Example

Example 1: filter for css white color .custom-2 { filter: brightness(0) invert(1); } Example 2: how to filter css red /*Add this to a CSS selector to turn it red*/ filter: grayscale(100%) brightness(40%) sepia(100%) hue-rotate(-50deg) saturate(600%) contrast(0.8); Example 3: css filter color .text { background: rgba(0,0,0,.9); backdrop-filter: grayscale(1) contrast(3) blur(1px); }

Android Studio: Server's Certificate Is Not Trusted

Answer : Android Studio has a configuration for Server Certificates (This works for other IntelliJ platforms like PyCharm as well) Go to File->Settings . In the IDE Settings section select Server Certificates Myself I just selected the Accept Automatically check box, hit Apply and never had to deal with it. If you are worried about security, there is also the option to add them 1 at a time as they come up. In my case I did this because I already had a *.google.com certificate configured as accepted, but I still got the popup. I suspect that the fingerprint changed and if I would have deleted and then accepted the error would have gone away, but I decided to just make it go away by selecting the check box. It is not safe to ignore that warning. Someone could be attempting a man-in-the-middle attack with a fake certificate in order to install malicious software on your computer through the update process. This probably isn't happening but it's always better to do

Chemistry - A Monocyclic 6 Carbon Ring With 6 Double Bonds

Image
Answer : Solution 1: There are several monocyclic \ce C 6 \ce{C6} \ce C 6 isomers. Three of them are pictured below A - the compound you've drawn above, cyclohexahexaene B - cyclohexatriyne C - cyclohexa-2,5-diyne-bis-1,4-ylidene While all of the carbons in these molecules are (more or less) \ce s p \ce{sp} \ce s p hybridized, the molecules are different from one another due to differences in bond lengths and bond angles. For example, all of the bonds in A are exactly the same length due to symmetry, whereas the triple bonds in B will be shorter than the adjacent single bonds. Therefore, A-C are isomers, not resonance structures. Ideally the atoms attached to an \ce s p \ce{sp} \ce s p hybridized carbon form a linear arrangement (180° bond angle) with the central \ce s p \ce{sp} \ce s p carbon, acetylene and the central carbon in allene serve as examples. (image source) (image source) However in the cyclic \ce C 6 \ce{C6} \ce C 6 compounds A-C, th

Get Pc Info Ip And Name C# Code Example

Example: c# get pc ip address public static string GetLocalIPAddress ( ) { var host = Dns . GetHostEntry ( Dns . GetHostName ( ) ) ; foreach ( var ip in host . AddressList ) { if ( ip . AddressFamily == AddressFamily . InterNetwork ) { return ip . ToString ( ) ; } } throw new Exception ( "No network adapters with an IPv4 address in the system!" ) ; }

Exit Game Unity Code Example

Example 1: application.stop unity using UnityEngine ; using System . Collections ; // Quits the player when the user hits escapepublic class ExampleClass : MonoBehaviour { void Update ( ) { if ( Input . GetKey ( "escape" ) ) { Application . Quit ( ) ; } } } Example 2: exit game unity //Quit/Stop Game Application . Quit ( ) ; Example 3: unity exit script //C# public static class AppHelper { # if UNITY_WEBPLAYER public static string webplayerQuitURL = "http://google.com" ; # endif public static void Quit ( ) { # if UNITY_EDITOR UnityEditor . EditorApplication . isPlaying = false ; # elif UNITY_WEBPLAYER Application . OpenURL ( webplayerQuitURL ) ; # else Application . Quit ( ) ; # endif } }

Html Tag To Make Text Italic Code Example

Example 1: html italic text <i>This text will be in italics</i> Example 2: how to italicize in html <!-- You have 2 options --> <i>This text is the original italic</i> <em>This is actually emphasising a phrase , but will do just the same</em> Example 3: how to make html text italic <!-- To make text italic in HTML --> <p> You have to use <em> To make you text italic instead of </em> <i> because this tag styles the text to be italic not changes real text</i> </p>

All Compiler Errors Have To Be Fixed Before Entering Playmode Code Example

Example: all compiler errors have to be fixed before entering playmode HOW TO GET RID OF All "compiler errors have to be fixed before you can enter playmode" 1 - check in the console tab if you have some errors in a code you wrote //the ones in red are the ones that probably are bothering you 2 - if you already fixed all the errors and you didnt get rid of it, try restarting unity 3 - if it didnt work just make another project 4 - if it DIDNT work reinstall unity 5 - if it didnt work call the the tech support 6 - if it didnt work restart yourselve

Hide Scroll Bar Html Code Example

Example 1: hide scrollbar css /* Hide scrollbar for Chrome, Safari and Opera */ .scrollbar-hidden ::-webkit-scrollbar { display : none ; } /* Hide scrollbar for IE, Edge add Firefox */ .scrollbar-hidden { -ms-overflow-style : none ; scrollbar-width : none ; /* Firefox */ } Example 2: hide scrollbar css /* A very quick an applicable solution is to use this piece of code: */ html { overflow : scroll ; overflow-x : hidden ; } ::-webkit-scrollbar { width : 0 px ; /* remove scrollbar space / background: transparent; / optional: just make scrollbar invisible / } / optional: show position indicator in red */ ::-webkit-scrollbar-thumb { background : #FF0000 ; } Example 3: hide scrollbar html css /* On Chrome */ .hide-scrollbar ::-webkit-scrollbar { display : none ; } /* For Firefox and IE */ .hide-scrollbar { scrollbar-width : none ; -ms-overflow-style : none ; }

Convert JSONObject To Map

Answer : use Jackson (https://github.com/FasterXML/jackson) from http://json.org/ HashMap<String,Object> result = new ObjectMapper().readValue(<JSON_OBJECT>, HashMap.class); You can use Gson() (com.google.gson) library if you find any difficulty using Jackson. HashMap<String, Object> yourHashMap = new Gson().fromJson(yourJsonObject.toString(), HashMap.class); This is what worked for me: public static Map<String, Object> toMap(JSONObject jsonobj) throws JSONException { Map<String, Object> map = new HashMap<String, Object>(); Iterator<String> keys = jsonobj.keys(); while(keys.hasNext()) { String key = keys.next(); Object value = jsonobj.get(key); if (value instanceof JSONArray) { value = toList((JSONArray) value); } else if (value instanceof JSONObject) { value = toMap((JSONObject) value); } map.put(key,

Angular Material - Change Color Of Mat-list-option On Selected

Answer : You can use aria-selected="true" attribute from mat-list-option tag to target the selected option, and provide corresponding css properties for the same. mat-list-option[aria-selected="true"] { background: rgba(0, 139, 139, 0.7); } Stackblitz Working Demo The accepted answer works fine, but it uses a hardcoded color value ( background: rgba(0, 139, 139, 0.7) ). This approach will actually break your styles and colors if you decide to switch to another pre-build material theme or use a custom theme (as described in Theming your Angular Material app page). So, if you use SCSS, you can use the following code in your component's style file: @import '~@angular/material/theming'; mat-list-option[aria-selected="true"] { background: mat-color($mat-light-theme-background, hover, 0.12); } The above code is adapted from mat-select options - in this way, you will have a consistent look in the entire app: .mat-option.mat-s

How To Make Random Code Generator In C Code Example

Example 1: c generate random number # import < stdlib . h > # import < time . h > int r ; srand ( time ( NULL ) ) ; r = rand ( ) ; /* This will give you a pseudo random integer between 0 and RAND_MAX. srand(time(NULL)) is used to give it a random starting seed, based on the current time. rand() could be used without it, but would always return the same sequence of numbers. To generate a random number in between 0 (included) and X (excluded), do the following: */ # import < stdlib . h > # import < time . h > int r ; srand ( time ( NULL ) ) ; r = rand ( ) % X ; Example 2: random number generator c rand ( ) % ( maxlimit + 1 - minlimit ) + minlimit ;

Convert RGBA PNG To RGB With PIL

Image
Answer : Here's a version that's much simpler - not sure how performant it is. Heavily based on some django snippet I found while building RGBA -> JPG + BG support for sorl thumbnails. from PIL import Image png = Image.open(object.logo.path) png.load() # required for png.split() background = Image.new("RGB", png.size, (255, 255, 255)) background.paste(png, mask=png.split()[3]) # 3 is the alpha channel background.save('foo.jpg', 'JPEG', quality=80) Result @80% Result @ 50% By using Image.alpha_composite , the solution by Yuji 'Tomita' Tomita become simpler. This code can avoid a tuple index out of range error if png has no alpha channel. from PIL import Image png = Image.open(img_path).convert('RGBA') background = Image.new('RGBA', png.size, (255,255,255)) alpha_composite = Image.alpha_composite(background, png) alpha_composite.save('foo.jpg', 'JPEG', quality=80) The transparent parts mostly have RGBA valu