This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
IP=`ifconfig | grep "inet " | grep -v 127.0.0.1 | cut -d\ -f2` | |
echo "$IP" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// use ES6 unshift | |
TheArray.unshift(TheNewElement); | |
// use splice | |
TheArray.splice(0, 0, TheNewElement); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Array.prototype.diff = function(a) { | |
return this.filter(function(i) {return a.indexOf(i) < 0;}); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const arr1 = [3, 5, 6, 10, 11, 20]; | |
const arr2 = [1, 2, 7, 8, 15, 19]; | |
mergeTwo(arr1, arr2); // [1, 2, 3, 5, 6, 7, 8, 10, 11, 15, 19, 20] | |
// First Approach | |
// O(n log n) time & O(n) space | |
function mergeTwo(arr1, arr2) { | |
let result = [...arr1, ...arr2]; | |
return result.sort((a,b) => a-b); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const arr = [1,2,3,4,5]; | |
// Spread Operator | |
const arr1 = [...arr]; | |
// Slice Operator | |
const arr2 = arr.slice(); | |
// Concat | |
const arr3 = [].concat(arr) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. Use .toString() | |
['a', 'b', 'c'].toString(); // 'a,b,c' | |
// 2. Coerce to string | |
['a', 'b', 'c'] + []; // 'a,b,c' | |
['a', 'b', 'c'] + ''; // 'a,b,c' | |
// 3. Use .join() | |
['a', 'b', 'c'].join(); // 'a,b,c' (defaults to ',' separator) | |
['a', 'b', 'c'].join(''); // 'abc' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// use Set | |
const names = ['John', 'Paul', 'George', 'Ringo', 'John']; | |
let unique = [...new Set(names)]; | |
console.log(unique); // 'John', 'Paul', 'George', 'Ringo' | |
// use Filter | |
const names = ['John', 'Paul', 'George', 'Ringo', 'John']; | |
let x = (names) => names.filter((v,i) => names.indexOf(v) === i) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function range(start, edge, step) { | |
// If only one number was passed in make it the edge and 0 the start. | |
if (arguments.length == 1) { | |
edge = start; | |
start = 0; | |
} | |
// Validate the edge and step numbers. | |
edge = edge || 0; | |
step = step || 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// register an application | |
// https://api.imgur.com/oauth2/addclient | |
// get registered apps info | |
// https://imgur.com/account/settings/apps | |
const imgur = require('imgur'); | |
imgur.setClientId(`${CLIENT_ID}`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
export DISPLAY=:0 | |
export GPU_MAX_ALLOC_PERCENT=100 | |
export GPU_USE_SYNC_OBJECTS=1 | |
./bfgminer --scrypt --url=stratum+tcp://litecoinpool.org:3333 --userpass=h0yang.1:1 --url=stratum+tcp://us.litecoinpool.org:3333 --userpass=h0yang.1:1 --failover-only |