Difference between revisions of "User:Saul"

From Organic Design wiki
m (Useful Links In This Wiki: added editors link.)
(Added Javascript section)
Line 64: Line 64:
 
flex: 1; /* optional to equalize widths */
 
flex: 1; /* optional to equalize widths */
 
}
 
}
 +
</source>
 +
 +
=== Javascript ===
 +
==== Unpacking Objects And Arrays ====
 +
Arrays can be unpacked into a variables list like this example:
 +
<source lang="javascript">
 +
let list = ["apples", "bananas", "carrots", "pears", "corn"];
 +
 +
let [itemOne, itemTwo, ItemThree, ItemFour] = list;
 +
 +
console.log(itemOne); // Output: "apples"
 +
console.log(itemThree); // Output: "carrots"
 +
</source>
 +
You can use this syntax to switch the variables too!
 +
<source lang="javascript">
 +
[itemOne, itemTwo] = [itemTwo, itemOne];
 +
 +
console.log(itemOne); // Output: "bananas"
 +
</source>
 +
Objects can be unpacked using similar syntax:
 +
<source lang="javascript">
 +
let person = {
 +
name: "sam",
 +
height: 2,
 +
food: "pizza"
 +
}
 +
 +
{name, height, food} = person;
 +
 +
console.log(name); // Output: "sam"
 +
console.log(food); // Output: "pizza"
 +
 +
({height, food, name}) = person;
 +
 +
console.log(name); // Output: "sam"
 +
console.log(height); // Output: 2
 +
</source>
 +
Note that the variable names must match the object properties, if you want different names you can do it like this:
 +
<source lang="javascript">
 +
({name: n}) = person;
 +
 +
console.log(n); // Output: "sam"
 +
</source>
 +
Using this syntax you can also set default values for properties like so:
 +
<source lang="javascript">
 +
({name: n, pet: favouriteAnimal = "dragon"}) = person;
 
</source>
 
</source>
  

Revision as of 03:37, 13 June 2018

I like to be making notes for MySQL, MongoDB, PHP, Javascript, Node.js, Feathers.js and other technologies. I am a friend to linux and open-source programs.

Snippets:

BASH:

Copy File To Server

To copy a file from or to a server over ssh run:

# scp SOURCE DESTINATION
scp -r USER@IP:~/SOME_FOLDER ~/SOME_FOLDER

VPS Proxy

To proxy traffic over port 1080 run:

ssh -NCD 1080 user@ip

Then in Firefox go: Edit -> Preferences -> General -> Network Proxy (near the bottom) and modify the following settings:

Manual Proxy Configuration
Socks Host: localhost
port: 1080

Alias

To save a command run:

alias COMMANDNAME="COMMAND"

This will be lost on reboot however so to save it run:

echo "alias COMMANDNAME=\"COMMAND\";" >> ~/.bashrc

Random Password Generation

A useful command to generate a random password of 10 characters:

</dev/urandom tr -dc 'A-Za-z0-9!"#$%&'\''()*+,-./:;<=>?@[\]^_`{|}~' | head -c 10 ; echo

CSS:

CSS Sticky Footer:

body .site{
	display: flex !important;
	min-height: 100vh !important;
	flex-direction: column !important;
}

#content {
	flex: 1 !important;
}

Note: in Wordpress the user bar will make the page need to scroll so logout to see it properly.

CSS Same Height Columns:

.Container{
	display: flex;
}

.Column{
	flex: 1; /* optional to equalize widths */
}

Javascript

Unpacking Objects And Arrays

Arrays can be unpacked into a variables list like this example:

let list = ["apples", "bananas", "carrots", "pears", "corn"];

let [itemOne, itemTwo, ItemThree, ItemFour] = list;

console.log(itemOne); // Output: "apples"
console.log(itemThree); // Output: "carrots"

You can use this syntax to switch the variables too!

[itemOne, itemTwo] = [itemTwo, itemOne];

console.log(itemOne); // Output: "bananas"

Objects can be unpacked using similar syntax:

let person = {
	name: "sam",
	height: 2,
	food: "pizza"
}

{name, height, food} = person;

console.log(name); // Output: "sam"
console.log(food); // Output: "pizza"

({height, food, name}) = person;

console.log(name); // Output: "sam"
console.log(height); // Output: 2

Note that the variable names must match the object properties, if you want different names you can do it like this:

({name: n}) = person;

console.log(n); // Output: "sam"

Using this syntax you can also set default values for properties like so:

({name: n, pet: favouriteAnimal = "dragon"}) = person;

Useful Links In This Wiki

My Crypto Links In This Wiki

My Troubleshooting Pages

Cool Projects