Posts

Showing posts from March, 2004

Create A Temp Table (if Not Exists) For Use Into A Custom Procedure

Answer : DROP Table each time before creating TEMP table as below: BEGIN DROP TABLE IF EXISTS temp_table1; create temp table temp_table1 -- Your rest Code comes here The problem of temp tables is that dropping and recreating temp table bloats pg_attribute heavily and therefore one sunny morning you will find db performance dead, and pg_attribute 200+ gb while your db would be like 10gb. So we're very heavy on temp tables having >500 rps and async i\o via nodejs and thus experienced a very heavy bloating of pg_attribute because of that. All you are left with is a very aggressive vacuuming which halts performance. All answers given here do not solve this, because they all bloat pg_attribute heavily. So the solution is elegantly this create temp table if not exists my_temp_table (description) on commit delete rows; So you go on playing with temp tables and save your pg_attribute. You want to DROP term table after commit (not DELETE ROWS), so: begin create temp table temp...

Android:java.lang.OutOfMemoryError: Failed To Allocate A 23970828 Byte Allocation With 2097152 Free Bytes And 2MB Until OOM

Answer : OutOfMemoryError is the most common problem that occurs in android while especially dealing with bitmaps. This error is thrown by the Java Virtual Machine (JVM) when an object cannot be allocated due to lack of memory space and also, the garbage collector cannot free some space. As mentioned by Aleksey, you can add the below entities in your manifest file android:hardwareAccelerated="false" , android:largeHeap="true" it will work for some environments. <application android:allowBackup="true" android:hardwareAccelerated="false" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:largeHeap="true" android:supportsRtl="true" android:theme="@style/AppTheme"> you should definitely read some of Androids Developer concept's, especially here:Displaying Bitmaps Efficiently Read all 5 topics and rewrite your code again. If it st...

Correct Path For Img On React.js

Answer : In create-react-app relative paths for images don't seem to work. Instead, you can import an image: import logo from './logo.png' // relative path to image class Nav extends Component { render() { return ( <img src={logo} alt={"logo"}/> ) } } If you used create-react-app to create your project then your public folder is accessible. So you need to add your image folder inside the public folder. public/images/ <img src="/images/logo.png" /> You're using a relative url, which is relative to the current url, not the file system. You could resolve this by using absolute urls <img src ="http://localhost:3000/details/img/myImage.png" /> But that's not great for when you deploy to www.my-domain.bike, or any other site. Better would be to use a url relative to the root directory of the site <img src="/details/img/myImage.png" />

Get Length Of Animationclip Unity Code Example

Example: how to get clip length of animation unity public float attackTime ; public float damageTime ; public float deathTime ; public float idleTime ; private Animator anim ; private AnimationClip clip ; // Use this for initialization void Start ( ) { anim = GetComponent < Animator > ( ) ; if ( anim == null ) { Debug . Log ( "Error: Did not find anim!" ) ; } else { //Debug.Log("Got anim"); } UpdateAnimClipTimes ( ) ; } public void UpdateAnimClipTimes ( ) { AnimationClip [ ] clips = anim . runtimeAnimatorController . animationClips ; foreach ( AnimationClip clip in clips ) { switch ( clip . name ) { case "Attacking" : attackTime = clip . length ; break ; case "Damage" : ...

Bootstrap Icons Fa Download Code Example

Example: download icon font awesome < i class = " fa fa-download " aria-hidden = " true " > </ i >

How To Convert Int To Char In Embedded C Code Example

Example: int to char in c c = i + '0' ;

Count Elements In Array Javascript Code Example

Example 1: count number of each element in array javascript var arr = [ 5 , 5 , 5 , 2 , 2 , 2 , 2 , 2 , 9 , 4 ] ; var counts = { } ; for ( var i = 0 ; i < arr . length ; i ++ ) { var num = arr [ i ] ; counts [ num ] ? counts [ num ] + 1 : 1 ; } console . log ( counts [ 5 ] , counts [ 2 ] , counts [ 9 ] , counts [ 4 ] ) ; Example 2: use .map to count length of each element in an array var lengths = chars . map ( function ( word ) { return word . length } ) Example 3: use .map to count length of each element in an array var words = [ 'Hello' , 'world' ] ; var lengths = words . map ( function ( word ) { return word + ' = ' + word . length ; } ) ; console . log ( lengths ) ; Example 4: typescript count array condition let data = [ { "id" : 1 , "is_read" : true , } , { "id" : 2 , "is_read" : true , } , { "id" : 3 , "is_read" : false ...

Create Substring Column In Spark Dataframe

Answer : Such statement can be used import org.apache.spark.sql.functions._ dataFrame.select(col("a"), substring_index(col("a"), ",", 1).as("b")) Suppose you have the following dataframe: import spark.implicits._ import org.apache.spark.sql.functions._ var df = sc.parallelize(Seq(("foobar", "foo"))).toDF("a", "b") +------+---+ | a| b| +------+---+ |foobar|foo| +------+---+ You could subset a new column from the first column as follows: df = df.select(col("*"), substring(col("a"), 4, 6).as("c")) +------+---+---+ | a| b| c| +------+---+---+ |foobar|foo|bar| +------+---+---+ You would use the withColumn function import org.apache.spark.sql.functions.{ udf, col } def substringFn(str: String) = your substring code val substring = udf(substringFn _) dataframe.withColumn("b", substring(col("a"))

Update Multiple Columns In Sql Server Code Example

Example 1: sql update multiple columns from another table -- Oracle UPDATE table2 t2 SET ( VALUE1 , VALUE2 ) = ( SELECT COL1 AS VALUE1 , COL1 AS VALUE2 FROM table1 t1 WHERE t1 . ID = t2 . ID ) ; -- SQL Server UPDATE table2 t2 SET t2 . VALUE1 = t1 . COL1 , t2 . VALUE2 = t1 . COL2 FROM table1 t1 INNER JOIN t2 ON t1 . ID = t2 . ID ; -- MySQL UPDATE table2 t2 INNER JOIN table1 t1 USING ( ID ) SET T2 . VALUE1 = t1 . COL1 , t2 . VALUE2 = t1 . COL2 ; Example 2: sql server update multiple columns at once UPDATE Person . Person Set FirstName = 'Kenneth' , LastName = 'Smith' WHERE BusinessEntityID = 1 Example 3: update multiple columns in sql UPDATE table - name SET column - name = value , column - name = value WHERE condition = value

C++ Vs. The Arduino Language?

Answer : My personal experience as professor (programming, mechatronics) is that if you have previous programming experience and you are aware of concepts as OOP, it is better to go for C/C++. The arduino language is really great for beginners, but have some limitations (e.g. you must have all your files in the same folder). And it is basically a simplification of C/C++ (you can practically copy&paste arduino code to a C/C++ file, and it will work). Also it makes sense that you can go and use a full well known IDE as eclipse: http://playground.arduino.cc/Code/Eclipse Initially it is required a bit more of setup and configuration of your dev environment, but IMHO it is worth it for programmers with experience in any other language. In any case, it won't harm you to start using the arduino language and the arduino IDE for a few days to get familiar with the arduino hardware and then move to C/C++ with Eclipse for really developing your project. In theory... There isn...

Js Get Attribute Data Code Example

Example 1: js get data attribute var element = document. querySelector ( '.element' ) ; var dataAttribute = element. getAttribute ( 'data-name' ) ; // replace "data-name" with your data attribute name console. log ( dataAttribute ) ; Example 2: html javascript find data attribute //javascript get html data attribute <button data-id= "1" >Click</button> <button data-id= "2" >Click</button> <button data-id= "3" >Click</button> const btns=document. querySelectorAll ( 'button[data-id]' ) ; [...btns]. forEach ( btn => console. log ( btn. getAttribute ( 'data-id' ) ) ) Example 3: get data attribute javascript // <div id= "element" data-name= "john" ></div> const el = document. querySelector ( '#element' ) el.dataset.name // 'john' Example 4: javascript get data attribute value const article = document. querySelector ( '#ele...

Convert Ascii String To Decimal Javascript Code Example

Example 1: javascript convert string to 2 decimal var twoPlacedFloat = parseFloat(yourString).toFixed(2) Example 2: javascript convert between string and ascii let ascii = 'a'.charCodeAt(0); // 97 let char = String.fromCharCode(ascii); // 'a' Example 3: convert binary to decimal javascript var digit = parseInt(binary, 2); Example 4: js ASCII value { "31": "", "32": " ", "33": "!", "34": "\"", "35": "#", "36": "$", "37": "%", "38": "&", "39": "'", "40": "(", "41": ")", "42": "*", "43": "+", "44": ",", "45": "-", "46": ".", "47": "/", "48": "0...

Dynamic 2d List In Python Code Example

Example: 2d array in python from array import * T = [ [ 11 , 12 , 5 , 2 ] , [ 15 , 6 , 10 ] , [ 10 , 8 , 12 , 5 ] , [ 12 , 15 , 8 , 6 ] ] for r in T : for c in r : print ( c , end = " " ) print ( )

Can I Catch Shiny Pokémon?

Answer : Prior to March 22, there were no shiny Pokemon in the game. After this update, it was possible to catch a Shiny Magikarp, which can could later be evolved into a Shiny Gyarados. It was first reported by users on the Sylph Road Reddit, then confirmed via photographic evidence. Since then, other Shiny Pokemon have been included in the game. Here is the current list: Pikachu Raichu Magikarp Gyarados Sableye Shuppet Banette Duskull Dusclops Mawile Absol Snorunt Swablu Altaria As of right now, there have been no shiny Pokemon encountered in Pokemon GO. As the game has been release for multiple days, more than 8192 Pokemon have been encountered by the install base of multiple hundreds of thousands. Its incredibly unlikely that there are shiny Pokemon in Pokemon GO. EDIT: Here's an online list of shinies that is updated regularly: https://www.imore.com/pokemon-go-shiny Posting an updated answer since the old one is outdated. Legendaries are in italics, a...

Concat Strings Javascript Code Example

Example 1: string concatenation in js var str1 = "Hello " ; var str2 = "world!" ; var res = str1 . concat ( str2 ) ; console . log ( res ) ; Example 2: how to concatenate strings javascript var str1 = "Hello " ; var str2 = "world!" ; var res = str1 . concat ( str2 ) ; // does not change the existing strings, but // returns a new string containing the text // of the joined strings. Example 3: string concat javascript //This method adds two or more strings and returns a new single string. let str1 = new String ( "This is string one" ) ; let str2 = new String ( "This is string two" ) ; let str3 = str1 . concat ( str2 . toString ( ) ) ; console . log ( "str1 + str2 : " + str3 ) output : str1 + str2 : This is string oneThis is string two Example 4: javascript string concat vs + It is strongly recommended to use the string concatenationoperators ( + , += ) instead of String . concat met...

How To Compare Two Char Arrays In Cpp Code Example

Example: c++ compare char array // syntax # include <cstring> // this needs to be at the top of the script/code std :: strcmp ( < 1 st - char > , < 2 nd - char > ) // example (assuming: char_1 = 'Compare me'; char_2 = 'Compare_me') # include <cstring> if ( std :: strcmp ( char_1 , char_2 ) == 0 ) { std :: cout << "The char's that you compared match!" << std :: endl ; } else { std :: cout << "The char's that you compared DON'T match" << std :: endl ; } // OUTPUT: The char's that you compared match! /* NOTE: the following outputs of std::strcmp indicate: [less than zero] : left-hand-side appears before right-hand-side in lexicographical order [zero] : the chars are equal [greater than zero] : left-hand-side appears after right-hand-side in lexicographical order */

Css :last-of-type Example

The :last-of-type CSS pseudo-class represents the last element of its type among a group of sibling elements. /* Selects any <p> that is the last element of its type among its siblings */ p:last-of-type { color : lime ; } Note : As originally defined, the selected element had to have a parent. Beginning with Selectors Level 4, this is no longer required. Syntax :last-of-type Examples Styling the last paragraph HTML < h2 > Heading </ h2 > < p > Paragraph 1 </ p > < p > Paragraph 2 </ p > CSS p:last-of-type { color : red ; font-style : italic ; } Result Nested elements This example shows how nested elements can also be targeted. Note that the universal selector ( * ) is implied when no simple selector is written. HTML < article > < div > This `div` is first. </ div > < div > This < span > nested `span` is last </ span > ! </ div > < div > This < em > nested ...

Bundle Install Returns "Could Not Locate Gemfile"

Answer : You just need to change directories to your app, THEN run bundle install :) You may also indicate the path to the gemfile in the same command e.g. BUNDLE_GEMFILE="MyProject/Gemfile.ios" bundle install I had this problem as well on an OSX machine. I discovered that rails was not installed... which surprised me as I thought OSX always came with Rails. To install rails sudo gem install rails to install jekyll I also needed sudo sudo gem install jekyll bundler cd ~/Sites jekyll new <foldername> cd <foldername> OR cd !$ (that is magic ;) bundle install bundle exec jekyll serve Then in your browser just go to http://127.0.0.1:4000/ and it really should be running

Normalize Css O Que é? Code Example

Example: normalize css npm install normalize.css

How To Make Rounded Button In Bootstrap Code Example

Example 1: round button css .btn { display : block ; height : 300 px ; width : 300 px ; border-radius : 50 % ; border : 1 px solid red ; } Example 2: button radius bootstrap 4 <span class= "border" ></span> <span class= "border-top" ></span> <span class= "border-right" ></span> <span class= "border-bottom" ></span> <span class= "border-left" ></span>

AlamoFire Download In Background Session

Image
Answer : Update Based on this amazing tutorial, I have put together an example project available on GitHub. It has an example for background session management. According to Apple's URL Loading System Programming Guide: In both iOS and OS X, when the user relaunches your app, your app should immediately create background configuration objects with the same identifiers as any sessions that had outstanding tasks when your app was last running, then create a session for each of those configuration objects. These new sessions are similarly automatically reassociated with ongoing background activity. So apparently by using the appropriate background session configuration instances, your downloads will never be "in flux". I have also found this answer really helpful. Original answer From Alamofire's GitHub page: Applications can create managers for background and ephemeral sessions, as well as new managers that customize the default ses...

What Is Volatile Variable In C Code Example

Example 1: declaring a volatile in c //volatile keyword usage in C # include <stdio.h> int main ( ) { //different methods of declaring and initializing volatile variables //method 1 - volatile int int volatile number1 = 10 ; //method 2 - volatile int volatile int number2 ; number2 = 20 ; //method 3 - volatile pointer int volatile * p1 ; p1 = & number1 ; //method 4 - volatile double pointer volatile int * * p2 ; p2 = & p1 ; printf ( "%d %d %d %d" , number1 , number2 , * p1 , * * p2 ) ; return 0 ; } Example 2: volatile keyword in c C's volatile keyword is a qualifier that is applied to a variable when it is declared . It tells the compiler that the value of the variable may change at any time -- without any action being taken by the code the compiler finds nearby .

A Href Button Html Code Example

Example 1: href on a button < button onclick = " window.location.href= ' /page2 ' " > Continue </ button > Example 2: buton html href <!-- if you are on Window : --> < button onclick = " window.location.href= ' page2.html ' " > Button </ button > <!-- if you are on linux or macOS : --> < button onclick = " location.href= ' page2.html ' " > Button </ button > Example 3: html button click url # Wrap whole button in a 'a' tag. < a href = " https://google.com " class = " button " > < button class = " pixel " > Button text </ button > </ a >

Adding Custom Property To Marker (Google Map Android API V2)

Answer : You cannot directly extend Marker , because it is a final class, but you have some options: 0) As of Google Maps Android API v2 version 9.4.0, you can use Marker::getTag and Marker::setTag . This is most likely the preferred option. 1) Create a map to store all additional information: private Map<Marker, MyData> allMarkersMap = new HashMap<Marker, MyData>(); When creating a marker, add it to this map with your data: Marker marker = map.addMarker(...); allMarkersMap.put(marker, myDataObj); Later in your render function: MyData myDataObj = allMarkersMap.get(marker); if (myDataObj.customProp) { ... 2) Another way would be to use Marker.snippet to store all the info as a String and later parse it, but that's kinda ugly and unmaintainable solution. 3) Switch from plain Google Maps Android API v2 to Android Maps Extensions. This is very similar to point 1, but you can directly store MyData into marker, using marker.setData(myDataObj)...

How To Give Div Border Color In Html Code Example

Example 1: border color css border : 1 px solid #000000 ; Example 2: border color css border : 1 px ; border-color : #3581fc ;

Difference Between Xpath And Css Selector In Selenium Code Example

Example: difference between xpath and css selector - We can create custom locators with both of them - CSS Selector : - Works only one way. We can only go from parent to child using CSS Selector. - CssSelector is technically faster than XPATH. - XPATH : - Works both ways. We can go both from parent to child , and child to parent using XPATH. - We can work with displayed TEXTS.

Obtain A Palindrome By Replacing ? Python Code Code Example

Example 1: string palindrome in python n = input ( "Enter the word and see if it is palindrome: " ) #check palindrome if n == n [ :: - 1 ] : print ( "This word is palindrome" ) else : print ( "This word is not palindrome" ) Example 2: palindrome python # A palindrome is a word , number , phrase , or other sequence of characters which reads the same backward as forward . # Ex : madam or racecar . def is_palindrome ( w ) : if w == w [ :: - 1 ] : # w [ :: - 1 ] it will reverse the given string value . print ( "Given String is palindrome" ) else : print ( "Given String is not palindrome" ) is_palindrome ( "racecar" )

Get A Random Color Unity Code Example

Example 1: unity generate random color //using Color Color randomColor = new Color ( Random . Range ( 0f , 1f ) , //Red Random . Range ( 0f , 1f ) , //Green Random . Range ( 0f , 1f ) , //Blue 1 , //Alpha (transparency) ) ; //using Color32 Color32 randomColor = new Color32 ( Random . Range ( 0 , 255 ) , //Red Random . Range ( 0 , 255 ) , //Green Random . Range ( 0 , 255 ) , //Blue 255 , //Alpha (transparency) ) ; Example 2: unity random color using UnityEngine ; public class ColorOnClick : MonoBehaviour { void OnMouseDown ( ) { // Pick a random, saturated and not-too-dark color GetComponent < Renderer > ( ) . material . color = Random . ColorHSV ( 0f , 1f , 1f , 1f , 0.5f , 1f ) ; } }

Cristiano Ronaldo Stream Code Example

Example: cristiano ronaldo CR7 is the GOAT

Hide Scrollbars But Keep Functionality 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: css hide scrollbar but allow scroll html { overflow : scroll ; } ::-webkit-scrollbar { width : 0 px ; background : transparent ; /* make scrollbar transparent */ } Example 3: hide scrollbars //Hides scrollbars but does not allow scrolling body { overflow-y : hidden ; /* Hide vertical scrollbar */ overflow-x : hidden ; /* Hide horizontal scrollbar */ } //Hides scrollbars but keep the ability to scroll /* Hide scrollbar for Chrome, Safari and Opera */ .example ::-webkit-scrollbar { display : none ; } /* Hide scrollbar for IE, Edge and Firefox */ .example { -ms-overflow-style : none ; /* IE and Edge */ scrollbar-width : none ; /* Firefox */ } Example 4:...

Getaxis Unity Code Example

Example 1: get axis mouse unity using UnityEngine ; using System . Collections ; // Performs a mouse look. public class ExampleClass : MonoBehaviour { float horizontalSpeed = 2.0f ; float verticalSpeed = 2.0f ; void Update ( ) { // Get the mouse delta. This is not in the range -1...1 float h = horizontalSpeed * Input . GetAxis ( "Mouse X" ) ; float v = verticalSpeed * Input . GetAxis ( "Mouse Y" ) ; transform . Rotate ( v , h , 0 ) ; } } Example 2: unity input get axis float movement = Input . GetAxis ( "Horizontal" ) * speed ;

Css Flex Css Tricks Code Example

Example 1: flex css end .item { align-self : flex-start | flex-end | center | baseline | stretch ; } Example 2: css flex /* Flex */ .anyclass { display : flex ; } /* row is the Default, if you want to change choose */ .anyclass { display : flex ; flex-direction : row | row-reverse | column | column-reverse ; } .anyclass { /* Alignment along the main axis */ justify-content : flex-start | flex-end | center | space-between | space-around | space-evenly | start | end | left | right ... + safe | unsafe ; } Example 3: flex parameters flex : none | [ < 'flex-grow' > < 'flex-shrink' >? || < 'flex-basis' > ] Example 4: flex box css tricks .container { flex-direction : row | row-reverse | column | column-reverse ; }