Posts

Showing posts from March, 2015

Android GetSharedPreferences Code Example

Example 1: android save int public void saveInt(int val, String key){ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mainActivity); SharedPreferences.Editor editor = prefs.edit(); editor.putInt(key, val); editor.apply(); } public int getInt(String key){ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mainActivity); int val = prefs.getInt(key, 0); return val; } Example 2: android sharedpreferences SharedPreferences sharedPref = getSharedPreferences("name", Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedPref.edit(); editor.putString("key", "Value"); editor.commit(); Example 3: set preference value android boolean committed = PreferenceManager.getDefaultSharedPreferences(yourContext).edit().putBoolean(key, mValue).commit(); //you can also use putInt, putFloat, putLong, putString, putStringSet and change the value of mValue //committed is true if everything we

Std::distance Include 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

Copy To Clipboard With Break Line

Answer : You have a few problems with the code. First problem in your code is the $(element).text() jquery text() strips your code from html including the <br> tags. So there is no newlines in the clipboard text since all html newlines are stripped away.. so nothing to replace. If you want to keep <br> as newlines you need to use .html() and parse your text more manually. Second problem is that you use <input> tag. <input> tag is only single lines so u cant have any newline in there. you need to use <textarea> for the conversion. The last problem is as above that you also should use \r\n for windows users. I updated your snippet with a working version. function copyToClipboard(element) { var $temp = $("<textarea>"); var brRegex = /<br\s*[\/]?>/gi; $("body").append($temp); $temp.val($(element).html().replace(brRegex, "\r\n")).select(); document.execCommand("copy"); $temp.remove(); } $

Page No Scroll 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: javascript keep scroll visible ::-webkit-scrollbar { -webkit-appearance : none ; width : 7 px ; } ::-webkit-scrollbar-thumb { border-radius : 4 px ; background-color : rgba ( 0 , 0 , 0 , .5 ) ; -webkit-box-shadow : 0 0 1 px rgba ( 255 , 255 , 255 , .5 ) ; }

How To Remove Arrows In Number Input Code Example

Example: remove arrows from input type number /* Chrome, Safari, Edge, Opera */ input ::-webkit-outer-spin-button , input ::-webkit-inner-spin-button { -webkit-appearance : none ; margin : 0 ; } /* Firefox */ input [ type = number ] { -moz-appearance : textfield ; }

50 Inch To Cm Code Example

Example 1: inch to cm 1 inch = 2.54 cm Example 2: cm to inch 1 cm = 0.3937 inch

Bootstrap Navbar-toggler-icon Code Example

Example 1: bootstrap navbar toggler icon color .custom-toggler .navbar-toggler-icon { background-image: url("data:image/svg+xml;charset=utf8,%3Csvg viewBox='0 0 32 32' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath stroke='rgba(255,102,203, 0.5)' stroke-width='2' stroke-linecap='round' stroke-miterlimit='10' d='M4 8h24M4 16h24M4 24h24'/%3E%3C/svg%3E"); } .custom-toggler.navbar-toggler { border-color: rgb(255,102,203); } Example 2: bootstrap navbar < nav class = " navbar navbar-expand-lg navbar-light bg-light " > < a class = " navbar-brand " href = " # " > Navbar </ a > < button class = " navbar-toggler " type = " button " data-toggle = " collapse " data-target = " #navbarNavAltMarkup " aria-controls = " navbarNavAltMarkup " aria-expanded = " false " aria-label = " Toggle navigation

LINUX LIST PROCESSES Code Example

Example 1: show all processes linux ps - aux | less Example 2: check running process in linux ps - aux # ( print all processes owned by a user named "x" ) Example 3: how to list running processes in linux ps - ef OR ps - ef | grep < process - to - filter > e . g ps - ef | grep node Example 4: command running processes linux ps - u [ username ]

Angular 2 Load Child Component On Click

Answer : You can use *ngIf directive for the initing component from parent, so your code will be like this <button (click)="loadMyChildComponent();">Load</button> <my-child-component *ngIf="loadComponent"></my-child-component> loadMyChildComponent() { loadComponent = true; ... } Make use of flag to control the load of child component. <button (click)="loadMyChildComponent();">Load</button> <div *ngIf= 'loadComponent'> <my-child-component></my-child-component> </div> In your parent component .ts private loadComponent = false; loadMyChildComponent(){ this.loadComponent = true; } You can use perhaps the most fundamental directive ngIf <button (click)="loadMyChildComponent();">Load</button> <my-child-component *ngIf="loaded"></my-child-component> In your component loadMyChildComponent(){ loaded=true; }

6,7 Oz To Grams Code Example

Example: oz to g 1 ounce (oz) = 28.3495231 grams (g)

Counting Associated Entries With Sequelize

Answer : Use findAll() with include() and sequelize.fn() for the COUNT : Location.findAll({ attributes: { include: [[Sequelize.fn("COUNT", Sequelize.col("sensors.id")), "sensorCount"]] }, include: [{ model: Sensor, attributes: [] }] }); Or, you may need to add a group as well: Location.findAll({ attributes: { include: [[Sequelize.fn("COUNT", Sequelize.col("sensors.id")), "sensorCount"]] }, include: [{ model: Sensor, attributes: [] }], group: ['Location.id'] }) Location.findAll({ attributes: { include: [[Sequelize.fn("COUNT", Sequelize.col("sensors.id")), "sensorCount"]] }, include: [{ model: Sensor, attributes: [] }] }); and it works. but when i add "limit", i got error: sensors undefined For Counting associated entries with Sequelize Location.fi

Convert String To Date Bigquery Code Example

Example: cast to date bigquery #standardSQL SELECT PARSE_DATE('%m/%d/%Y', '6/22/2017') 2017-06-22

Can A 2-prong AC/DC Converter Switch Polarity Based On Inverting The Plug?

Image
Answer : This circuit will do what you want (for a literal interpretation of the question): No way. Given just a differential, just a pair of connections, there's no way for a circuit to tell which is which. If you had access to phase information about the grid, you might be able to do it, but as the mains frequency isn't terribly constant, you would not be able to rely on predicting this. Your device would have to get information about the present phase angle of the mains from someplace. However, if you do have a real earth-ground reference from some place, you could build a circuit to look at the voltage of each supply line with respect to ground. One will be a small drop below the full 120 (or whatever the local mains supply) whereas the other will be slightly above ground. (Neutral return current vs your neutral run's resistance). This would just let you know which leg was 'hot', and you could swap your output polarity accordingly. A Second Thought

Gfg Online Ide Code Example

Example 1: Best online compiler onlinegbd . com is one of the best online compilers use it pls or DIE Example 2: gfg ide class A : def hello1 ( self ) : print ( "Super" ) class B ( A ) : def hello1 ( self ) : print ( "Child1" ) class C ( B ) : def hello ( self ) : print ( "Child2" ) ob = C ( ) ob . hello ( ) ob . hello1 ( )

Convert Number To Integer Python Code Example

Example 1: python string to int # Use the function int ( ) to turn a string into an integer string = '123' integer = int ( string ) integer # Output : # 123 Example 2: float to int in python # convert float to int int ( 2.0 ) #output : 2 Example 3: how to convert int in python score = 89 score = str ( score )

How To Make Sliding Text Html Code Example

Example: sliding text css <div class= "slide-" > <h2>Text that will slide in from the left</h2> </div>

Connect PHP To MSSQL Via PDO ODBC

Answer : There are several configuration files you need to have set up. /etc/odbc.ini , /etc/odbcinst.ini and /etc/freetds/freetds.conf (these locations are valid for Ubuntu 12.04 and probably correct for most *nixes). You'll need to install unixodbc and freetds (not sure what the package names are on CentOS). In Ubuntu this would be apt-get install unixodbc tdsodbc . For help installing these, look at this question Can't Install FreeTDS via Yum Package Manager /etc/odbc.ini (this file may be empty) # Define a connection to a Microsoft SQL server # The Description can be whatever we want it to be. # The Driver value must match what we have defined in /etc/odbcinst.ini # The Database name must be the name of the database this connection will connect to. # The ServerName is the name we defined in /etc/freetds/freetds.conf # The TDS_Version should match what we defined in /etc/freetds/freetds.conf [mssql] Description = MSSQL Server Driver = free

Convert String To Float C++ Stringstream Code Example

Example 1: how to change a string to an float in c++ # include <iostream> # include <string> int main ( ) { std :: string str = "123.4567" ; // convert string to float float num_float = std :: stof ( str ) ; // convert string to double double num_double = std :: stod ( str ) ; std :: cout << "num_float = " << num_float << std :: endl ; std :: cout << "num_double = " << num_double << std :: endl ; return 0 ; } Example 2: c++ std string to float std :: string num = "0.6" ; double temp = :: atof ( num . c_str ( ) ) ; std :: cout << temp << std :: endl ; // Output: 0.6

Allocatable Character Variables In Fortran

Answer : This character (len=:), allocatable :: input_trim is certainly syntactically correct in Fortran 2003. You don't say what the error that gfortran raises is, so I can't comment on why it doesn't accept the line -- perhaps you have an old version of the compiler installed. With an up-to-date Fortran compiler ( eg Intel Fortran v14.xxx) you don't need to allocate the character variable's size prior to assigning to it, you can simply write input_trim = trim(input) Note that read(*,*) input_trim won't work.