Posts

Showing posts from September, 2008

Creating BSON Object From JSON String

Answer : ... And, since 3.0.0, you can: import org.bson.Document; final Document doc = new Document("myKey", "myValue"); final String jsonString = doc.toJson(); final Document doc = Document.parse(jsonString); Official docs: Document.parse(String) Document.toJson() Official MongoDB Java Driver comes with utility methods for parsing JSON to BSON and serializing BSON to JSON. import com.mongodb.DBObject; import com.mongodb.util.JSON; DBObject dbObj = ... ; String json = JSON.serialize( dbObj ); DBObject bson = ( DBObject ) JSON.parse( json ); The driver can be found here: https://mongodb.github.io/mongo-java-driver/ The easiest way seems to be to use a JSON library to parse the JSON strings into a Map and then use the putAll method to put those values into a BSONObject . This answer shows how to use Jackson to parse a JSON string into a Map .

Green Gradient Background For Image Code Example

Example: background with image and gradient body { background : #eb01a5 ; background-image : url ( "IMAGE_URL" ) ; /* fallback */ background-image : url ( "IMAGE_URL" ) , linear-gradient ( #eb01a5 , #d13531 ) ; /* W3C */ }

Contenteditable Not Working In Safari But Works In Chrome

Answer : Safari has the user-select CSS setting as none by default. You can use: [contenteditable] { -webkit-user-select: text; user-select: text; } To make it work.

Cannot GET /assets/vendor/swiper/swiper-bundle.min.js.map Code Example

Example: Cannot GET /assets/vendor/swiper/swiper-bundle.min.js.map /*! jQuery v2.0.3 | (c) 2005, 2013 jQuery Foundation, Inc. | jquery.org/license //@ sourceMappingURL=jquery.min.map */

Access Auth In Blade Laravel Code Example

Example 1: laravel auth composer require laravel / ui php artisan ui vue -- auth npm install && npm run dev Example 2: get user auth in laravel Auth :: user ( ) ; Example 3: laravel auth composer require laravel / ui : ^ 2.4 php artisan ui vue -- auth

Angular Material Icons Not Working

Answer : Add CSS stylesheet for Material Icons! Add the following to your index.html: <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> Refer - https://github.com/angular/material2/issues/7948 For Angular 6+: npm install this: npm install material-design-icons add the styles to angular.json: "styles": [ "node_modules/material-design-icons/iconfont/material-icons.css" ] If using SASS you only need to add this line to your main .scss file: @import url("https://fonts.googleapis.com/icon?family=Material+Icons"); If you prefer to avoid fetching icons from google you can also self-host the icons as described in Material Icons Guide: For those looking to self host the web font, some additional setup is necessary. Host the icon font in a location, for example https://example.com/material-icons.woff and add the following CSS rule: @font-face { font-family: '

C Puts() Without Newline

Answer : Typically one would use fputs() instead of puts() to omit the newline. In your code, the puts(input); would become: fputs(input, stdout); puts() adds the newline character by the library specification. You can use printf instead, where you can control what gets printed with a format string: printf("%s", input); You can also write a custom puts function: #include <stdio.h> int my_puts(char const s[static 1]) { for (size_t i = 0; s[i]; ++i) if (putchar(s[i]) == EOF) return EOF; return 0; } int main() { my_puts("testing "); my_puts("C puts() without "); my_puts("newline"); return 0; } Output: testing C puts() without newline

Angular 4 - Please Include Either "BrowserAnimationsModule" Or "NoopAnimationsModule" In Your Application

Answer : Adding the lines import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; and imports: [ BrowserAnimationsModule, ... ] to app.module.ts actually solves it One point is definitely you need to add BrowsersAnimationModule in your active Module. But apart from that you need to mention animations for that Synthetic selector (here @routerAnimations ) which is Angular Component Meta @Component({ selector: 'app-card-grid', templateUrl: './card-grid.component.html', styleUrls: ['./card-grid.component.scss'], animations: [ trigger('routerAnimations', [ state('collapsed', style({ height: '0px', minHeight: '0' })), state('expanded', style({ height: '*' })), transition('expanded <=> collapsed', animate('225ms cubic-bezier(0.4, 0.0, 0.2, 1)')), ]), ], Response in comment if you still have any doubts

Brew: Command Not Found Code Example

Example 1: mac brew: command not found ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" Example 2: install brew on mac /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" Example 3: how to install homebrew on mac mkdir homebrew && curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew

Adddate Sql Code Example

Example: sql server current date minus 5 years SELECT GETDATE ( ) 'Today' , DATEADD ( day , - 2 , GETDATE ( ) ) 'Today - 2 Days' SELECT GETDATE ( ) 'Today' , DATEADD ( dd , - 2 , GETDATE ( ) ) 'Today - 2 Days' SELECT GETDATE ( ) 'Today' , DATEADD ( d , - 2 , GETDATE ( ) ) 'Today - 2 Days'

Connections % Of Configured Limit Has Gone Above 80 From Mongo Atlas

Answer : removing all IP address and waiting 5 minutes works also for me . seems like it kills all opened connections. Don't forget to allow your ip after that see my cluster connections there is an opened issue with mongoose. it might be the root cause https://github.com/Automattic/mongoose/issues/8059 I resolved it by deleting all IP whitelist and wait for 5 minutes. We can monitor that, the connections are decreasing in mongo atlas cluster. At last, it became Zero. Then added IP whitelist from anywhere to access(Not secure. Just to work. Or whitelist current IP and server Ip). Its work fine.

Button Prevent Postback Asp Net Code Example

Example: prevent asp button from postback < asp : button runat = "server" .. .. OnClientClick = "myfunction(); return false;" / >

Ionic Icon Color Code Example

Example: ionic color <ion-button>Default</ion-button> <ion-button color= "primary" >Primary</ion-button> <ion-button color= "secondary" >Secondary</ion-button> <ion-button color= "tertiary" >Tertiary</ion-button> <ion-button color= "success" >Success</ion-button> <ion-button color= "warning" >Warning</ion-button> <ion-button color= "danger" >Danger</ion-button> <ion-button color= "light" >Light</ion-button> <ion-button color= "medium" >Medium</ion-button> <ion-button color= "dark" >Dark</ion-button>

React Cxs Styles Code Example

Example 1: Styling React Using CSS class MyHeader extends React .Component { render ( ) { return ( <div > <h1 style= { { color : "red" } } >Hello Style!</h1> <p>Add a little style!</p> </div> ) ; } } Example 2: use styles in react const useStyles = makeStyles ( theme = > ( { textField: { marginLeft : theme. spacing ( 1 ) , marginRight : theme. spacing ( 1 ) , border : '1px solid red' , } , } ) ) ; function App ( ) { const classes = useStyles ( ) ; return ( <TextField id="outlined-name" label="Name" className= { classes.textField } margin= "normal" variant= "outlined" /> ) ; }

Cron Job Once Every 2 Hours Code Example

Example 1: cron every 3 hours 0 */3 * * * Example 2: cron every two hours 0 */2 * * *

Difference Between Synchronous And Asynchronous In Javascript Code Example

Example: difference between synchronous and asynchronous in node js // Example 1 - Synchronous (blocks) var result = database . query ( "SELECT * FROM hugetable" ) ; console . log ( "Query finished" ) ; console . log ( "Next line" ) ; // Example 2 - Asynchronous (doesn't block) database . query ( "SELECT * FROM hugetable" , function ( result ) { console . log ( "Query finished" ) ; } ) ; console . log ( "Next line" ) ;

Activate Office Cmd Code Code Example

Example: cmd code to activate microsoft office 2016 @echo off title Activate Microsoft Office 2016 ALL versions for FREE!&cls&echo ============================================================================&echo #Project: Activating Microsoft software products for FREE without software&echo ============================================================================&echo.&echo #Supported products:&echo - Microsoft Office Standard 2016&echo - Microsoft Office Professional Plus 2016&echo.&echo.&(if exist "%ProgramFiles%\Microsoft Office\Office16\ospp.vbs" cd /d "%ProgramFiles%\Microsoft Office\Office16")&(if exist "%ProgramFiles(x86)%\Microsoft Office\Office16\ospp.vbs" cd /d "%ProgramFiles(x86)%\Microsoft Office\Office16")&(for /f %%x in ('dir /b ..\root\Licenses16\proplusvl_kms*.xrm-ms') do cscript ospp.vbs /inslic:"..\root\Licenses16\%%x" >nul)&(for /f %%x in ('

Javascript Toint Code Example

Example 1: how to convert string to int js let string = "1" ; let num = parseInt ( string ) ; //num will equal 1 as a int Example 2: intval js parseInt ( value ) ; let string = "321" console . log ( string ) ; // "321" <= string let number = parseInt ( string ) ; console . log ( number ) // 321 <=int Example 3: Javascript string to int var myInt = parseInt ( "10.256" ) ; //10 var myFloat = parseFloat ( "10.256" ) ; //10.256 Example 4: how to change a string to number in javascript let theInt = parseInt ( "5.90123" ) ; //5 let theFloat = parseFloat ( "5.90123" ) ; //5.90123 Example 5: converst strig in number in js const numberInString = "20" ; console . log ( typeof ( numberInString ) ) // typeof is string this is string in double quote " " const numInNum = parseInt ( numberInString ) // now numberInStrings variable converted in an Integer due to

'adb' Is Not Recognized As An Internal Or External Command, Operable Program Or Batch Code Example

Example: adb is not recognized set PATH : C:\Users\YOUR_USERNAME\AppData\Local\Android\Sdk\platform-tools

Android WebView JavaScript From Assets

Answer : Answer: 1. You MUST load the HTML into string: private String readHtml(String remoteUrl) { String out = ""; BufferedReader in = null; try { URL url = new URL(remoteUrl); in = new BufferedReader(new InputStreamReader(url.openStream())); String str; while ((str = in.readLine()) != null) { out += str; } } catch (MalformedURLException e) { } catch (IOException e) { } finally { if (in != null) { try { in.close(); } catch (IOException e) { e.printStackTrace(); } } } return out; } 2. Load WebView with base URL: String html = readHtml("http://mydomain.com/my.html"); mWebView.loadDataWithBaseURL("file:///android_asset/", html, "text/html", "utf-8", ""); In this particular case you should have all .js files you want to use on the page to reside som

Mouseover And Mouseout In Javascript Examples

Example: on mouseover in javascript The mouseover event is fired at an Element when a pointing device ( such as a mouse or trackpad ) is used to move the cursor onto the element or one of its child elements.

Can Anyone Confirm That PhpMyAdmin AllowNoPassword Works With MySQL Databases?

Answer : Copy config.sample.inc.php to config.inc.php . In most cases you will find the config file on linux: /etc/phpmyadmin/config.inc.php on mac: /Library/WebServer/Documents/phpmyadmin/config.inc.php If you are trying to log in as root, you should have the following lines in your config: c f g [ ′ S e r v e r s ′ ] [ cfg['Servers'][ c f g [ ′ S er v er s ′ ] [ i]['user'] = 'root'; c f g [ ′ S e r v e r s ′ ] [ cfg['Servers'][ c f g [ ′ S er v er s ′ ] [ i]['AllowNoPassword'] = true; According to this: https://www.simplified.guide/phpmyadmin/enable-login-without-password This $cfg['Servers'][$i]['AllowNoPassword'] = TRUE; should be added twice in /etc/phpmyadmin/config.inc.php if (!empty($dbname)) { // other configuration options $cfg['Servers'][$i]['AllowNoPassword'] = TRUE; // it should be placed before the following line $i++; } // other configuration options $cf

Add Header To Pandas Dataframe Code Example

Example 1: how to add column headers in pandas #suppose team is a df that has unnamed columns (0,1...) team . columns = [ 'Name' , 'Code' , 'Age' , 'Weight' ] Example 2: how to add headings to data in pandas Cov = pd . read_csv ( "path/to/file.txt" , sep = '\t' ) Frame = pd . DataFrame ( Cov . values , columns = [ "Sequence" , "Start" , "End" , "Coverage" ] ) Frame . to_csv ( "path/to/file.txt" , sep = '\t' ) Example 3: how to create new header of a dataframe in python pythonCopy # python 3.x import pandas as pd import numpy as np df = pd . DataFrame ( data = np . random . randint ( 0 , 10 , ( 6 , 4 ) ) ) df . columns = [ "a" , "b" , "c" , "d" ] print ( df ) Example 4: pandas heading pd . read_csv ( "directory" , heading = None )

Add Arraylist Java Code Example

Example 1: java insert into arraylist ArrayList < Integer > str = new ArrayList < Integer > ( ) ; str . add ( 0 ) ; str . add ( 1 ) ; // Result = [0, 1] str . add ( 1 , 11 ) ; // Result = [0, 11, 1] Example 2: insert element into arraylist java ArrayList < String > arrayList = new ArrayList < > ( ) ; // Adds element at the back of the list arrayList . add ( "foo" ) ; arrayList . add ( "bar" ) ; // Result = ["foo", "bar"] // Adds element at the specified index arrayList . add ( 1 , "baz" ) ; // Result = ["foo", "baz", "bar"] Example 3: how to add to an arraylist java import java . util . ArrayList ; public class Details { public static void main ( String [ ] args ) { //ArrayList<String> Declaration ArrayList < String > al = new ArrayList < String > ( ) ; //add method for String ArrayList