Posts

Showing posts from April, 2016

Connect To MongoDB With Username And Password Command Line Code Example

Example: connect to mongodb with username and password ->First run mongoDB on terminal using mongod ->now run mongo shell use following commands use admin db.createUser( { user: "myUserAdmin", pwd: "abc123", roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] } ) ->Re-start the MongoDB instance with access control. mongod --auth ->Now authenticate yourself from the command line using mongo --port 27017 -u "myUserAdmin" -p "abc123" --authenticationDatabase "admin" ->You can read it from https://docs.mongodb.com/manual/tutorial/enable-authentication/

Add Android-studio/bin/ To PATH Environmental Variable

Answer : It looks like you edited this code snippet: if [ -d "$HOME/bin" ] ; then PATH="$HOME/bin:$PATH" fi which is included in ~/.profile by default. The answer which lead you to do so is confusing IMNSHO. I'd suggest that you change that code back to what it looked like before, and instead add a new line underneath it: if [ -d "$HOME/bin" ] ; then PATH="$HOME/bin:$PATH" fi PATH="$PATH:/usr/local/Android/android-studio/bin" Then, next time you log in, PATH ought to be altered, whether $HOME/bin exists or not.

Create Folder Github Repo Code Example

Example 1: how to create folder in github You cannot create an empty folder and then add files to that folder, but rather creation of a folder must happen together with adding of at least a single file. On GitHub you can do it this way: Go to the folder inside which you want to create another folder Click on New file On the text field for the file name, first write the folder name you want to create Then type /. This creates a folder You can add more folders similarly Finally, give the new file a name (for example, .gitkeep which is conventionally used to make Git track otherwise empty folders; it is not a Git feature though) Finally, click Commit new file. Example 2: github create directory cd NAME-OF-FILE

One Div Half Background Color Black And Half White Color In Css Code Example

Example: how to give 2 different background color css background : repeating-linear-gradient ( #74ABDD , #74ABDD 49.9 % , #498DCB 50.1 % , #498DCB 100 % ) ;

C# How To Use WM_GETTEXT / GetWindowText API / Window Title

Answer : public class GetTextTestClass{ [System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "SendMessage", CharSet = System.Runtime.InteropServices.CharSet.Auto)] public static extern bool SendMessage(IntPtr hWnd, uint Msg, int wParam, StringBuilder lParam); [System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)] public static extern IntPtr SendMessage(int hWnd, int Msg, int wparam, int lparam); const int WM_GETTEXT = 0x000D; const int WM_GETTEXTLENGTH = 0x000E; public string GetControlText(IntPtr hWnd){ // Get the size of the string required to hold the window title (including trailing null.) Int32 titleSize = SendMessage((int)hWnd, WM_GETTEXTLENGTH, 0, 0).ToInt32(); // If titleSize is 0, there is no title so return an empty string (or null) if (titleSize == 0) return String.Empty; StringBuilder title = new StringBuilder(

Add A Horizontal Line To Plot And Legend In Ggplot2

Image
Answer : (1) Try this: cutoff <- data.frame( x = c(-Inf, Inf), y = 50, cutoff = factor(50) ) ggplot(the.data, aes( year, value ) ) + geom_point(aes( colour = source )) + geom_smooth(aes( group = 1 )) + geom_line(aes( x, y, linetype = cutoff ), cutoff) (2) Regarding your comment, if you don't want the cutoff listed as a separate legend it would be easier to just label the cutoff line right on the plot: ggplot(the.data, aes( year, value ) ) + geom_point(aes( colour = source )) + geom_smooth(aes( group = 1 )) + geom_hline(yintercept = 50) + annotate("text", min(the.data$year), 50, vjust = -1, label = "Cutoff") Update This seems even better and generalizes to mulitple lines as shown: line.data <- data.frame(yintercept = c(50, 60), Lines = c("lower", "upper")) ggplot(the.data, aes( year, value ) ) + geom_point(aes( colour = source )) + geom_smooth(aes( group

Convert XMLGregorianCalendar To Date I.e "MM/DD/YYYY Hh:mm:ss AM"

Answer : You can do this to return a Date : calendar.toGregorianCalendar().getTime() I found that code from this tutorial. From there, you can use a SimpleDateFormat to turn it into a string in the format you want. But, if you're using JDBC to save the date in the database, you probably can pass in the Date directly with this method: preparedStatement.setDate(colNum, myDate); Here is more clear answer: Get instance of Date from XMLGregorianCalendar instance: Date date = xmlCalendar.toGregorianCalendar().getTime(); I found that code from Convert XMLGregorianCalendar to Date in Java Format that Date instance with format "MM/dd/yyyy hh:mm:ss a", you will get MM/DD/YYYY hh:mm:ss AM format DateFormat formatter = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a"); String formattedDate = formatter.format(date) From Convert Date to String in Java For inserting database you would do what Daniel suggested If you want to insert your date on a database I would first do w

Grid Mdn Css Code Example

Example: css grid mdn /* Answer to: "css grid mdn" */ /* The grid CSS property is a shorthand property that sets all of the explicit grid properties (grid-template-rows, grid-template-columns, and grid-template-areas), and all the implicit grid properties (grid-auto-rows, grid-auto-columns, and grid-auto-flow), in a single declaration. For more information, go to: https://developer.mozilla.org/en-US/docs/Web/CSS/grid */

How To Print Pointer Address In C Code Example

Example: how to print the address of a pointer in c int a = 42 ; printf ( "%p\n" , ( void * ) & a ) ;

"Connect Via Network" Wireless Debugging Not Working Xcode 9

Image
Answer : I was having the same issue and performed the following steps to get things working: Open "Devices and Simulators" Connect your device and check the "Connect via network" checkbox Disconnect your device Right click listing for your device in the left hand column (Under Disconnected) Select "Connect via IP Address.." and enter your device's IP address After numerous Wi-fi resets and device restarts (for iOS 12, Xcode 10) I found the solution for me was: Disconnect iOS device from Mac Go to Settings -> Develop on the iOS device Tap "Clear Trusted Computers" Reconnect iOS device to Mac via cable On iOS device tap "Trust This Computer" and enter passcode Go to Device Manager in Xcode and enable "Connect Via Network" The network symbol appeared and I was good to go.

Can I Use Ufw To Setup A Port Forward?

Answer : Solution 1: Let's say you want to forward requests going to 80 to a server listening on port 8080. Note that you will need to make sure port 8080 is allowed, otherwise ufw will block the requests that are redirected to 8080. sudo ufw allow 8080/tcp There are no ufw commands for setting up the port forwards, so it must be done via configuraton files. Add the lines below to /etc/ufw/before.rules , before the filter section, right at the top of the file: *nat :PREROUTING ACCEPT [0:0] -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080 COMMIT Then restart and enable ufw to start on boot: sudo ufw enable Solution 2: Since ufw 0.34 ufw supports forward rules. example: sudo ufw route allow in on eth0 out on eth1 to 10.0.0.0/8 port 8080 from 192.168.0.0/16 port 80 You also need to make sure you have the sysctl net.ipv4.ip_forward enabled. For most distributions, that's done by editing /etc/sysctl.conf and running sysctl -p or rebooting.

Anaconda Prompt Environment List Code Example

Example 1: list conda environments conda info --envs conda env list Example 2: conda create env from yml conda env create -f environment.yml

Yto Mp3 Code Example

Example: yt to mp3 Youtube - DL works great . Download from https : //youtube-dl.org/. To use, type youtube-dl <url> --audio-format mp3

Calculation In Javascript Code Example

Example: js calculate answer_Add = 5 + 1 ; //answer = 6 answer_Sub = 5 - 1 ; //answer = 4 answer_Multi = 5 * 5 ; //answer = 25 answer_Divi = 10 / 2 ; //answer = 5 Total = answer_Add + answer_Sub + answer_Multi + answer_Divi ;

Correct Way Of Importing And Using Lodash In Angular

Answer : (if you care about tree shaking see update ) I suppose in order to bring lodash in to your project you already done npm install lodash --save npm install @types/lodash --save-dev If you want to import just required functions you should do: import * as debounce from 'lodash/debounce' or import { debounce } from "lodash"; Use it as: debounce() BTW: You might have to downgrade your typescript version to 2.0.10 as you are using angular 2.x. npm install typescript@2.0.10 --save-dev UPDATE: Recently I realised that lodash package is just not tree shakable, so if you need tree shaking just use lodash-es instead. npm install lodash-es --save npm install @types/lodash-es --save-dev import debounce from 'lodash-es/debounce' Importing lodash or any javascript library inside angular: step-1: Install the libarary(lodash) npm i --save lodash step-2: import it inside the component and use it. import it as follow: import 'lodash'; declare var _:any; o

Android Library Project Using Android Studio

Answer : Simplest way to do this : Right click on your opened project in Android Studio and select New > Module In the left Pane choose Android Library and click on next. Enter all details, untick Create Activity, Theme and all if not required. Choose API level same as your project and Next, Next, Next . Now you will see an another directory inside your project, build.gradle for library will be automatically configured for you. If your module/library name is "mylibrary" , include ':mylibrary' will be automatically added in settings.gradle file inside root directory of your project. Now open your main module and insert this line in dependency block : compile project(':mylibrary') If you want to use same library in other projects, you have to copy the library module to that particular project using File Explore and have to configure settings.gradle and main module's build.gradle manually. An old question, but even now there d

Paypal Recurring Payments Api Php Example

Example: paypal recurring payments api for create plan curl -k -v -H “Content-Type : application/json” -H “Authorization : Bearer ACCESS_TOKEN” -d ' { “name”:”Test REST Club Plan” , “description”:”Template creation.” , “type”:”fixed” , “payment_definitions”:[ { “name”:”Regular Payments” , “type”:”REGULAR” , “frequency”:”MONTH” , “frequency_interval”:”2” , “amount”: { “value” : ” 100 ” , “currency” : ”USD” } , “cycles”:”12” , “charge_models”:[ { “type”:”SHIPPING” , “amount”: { “value” : ” 10 ” , “currency” : ”USD” } } , { “type”:”TAX” , “amount”: { “value” : ” 12 ” , “currency” : ”USD” } } ] } ] , “merchant_preferences”: { “setup_fee”: { “value” : ” 1 ” , “currency” : ”USD” } , “return_url” : ”http : //returnurl” , “cancel_url” : ”http : //cancelurl” , “auto_bill_amount” : ”YES” , “initial_fail_amount_action” : ”CONTINUE” , “max_fail_attempts” : ” 0 ” } } ' https : //api.sandbox.paypal.com/v1/payments/billing-plans

How To Get The First Child Of An Element In Javascript Code Example

Example 1: first child element javascript Both these will give you the first child node : console. log ( parentElement.firstChild ) ; // or console. log ( parentElement.childNodes[ 0 ] ) ; If you need the first child that is an element node then use : console. log ( parentElement.children[ 0 ] ) ; Example 2: how to add first child using js var eElement ; // some E DOM instance var newFirstElement ; //element which should be first in E eElement. insertBefore ( newFirstElement , eElement.firstChild ) ;

12 Oz To Grams Code Example

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

About_Execution_Policies Em Https://go.microsoft.com/fwlink/?LinkID=135170. Code Example

Example: fwlink/?LinkID=135170 set-executionpolicy remotesigned