Skip to content

Instantly share code, notes, and snippets.

Daron Wolff daronwolff

View GitHub Profile
@daronwolff
daronwolff / plugin.js
Created Feb 14, 2018
HapiJs 17 plugin
View plugin.js
const plugin = {
register: async (server, options) => {
// Do your registration stuff
},
name: 'pluginName',
version: '1.0.1',
once: true,
options: {}
};
@daronwolff
daronwolff / 0_reuse_code.js
Created Jul 24, 2017
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@daronwolff
daronwolff / sequentially.js
Created Jun 16, 2017
Executing promises sequentially
View sequentially.js
const times = [ 1, 3, 4, 2 ];
const sleep = ms =>
new Promise(res => {
const t = ms * 1000;
setTimeout(res, t)
})
const myPromise = num =>
sleep(num).then(() => {
@daronwolff
daronwolff / resolveObject.js
Created Apr 13, 2017
This function is similar to Promise.all but this receives an object. The param names from promisesObject is used to clasify the information
View resolveObject.js
function resolveObject(promisesObject) {
const data = {};
let ready = Promise.resolve(null);
Object.keys(promisesObject).forEach((name) => {
const promise = promisesObject[name];
ready = ready.then(() => promise)
.then((value) => {
data[name] = value;
});
});
@daronwolff
daronwolff / capitalize.js
Created Mar 29, 2017
CapitalizeString and remove white spaces
View capitalize.js
function capitalize(str) {
return str.replace(/\b\w/g, l => l.toUpperCase())
.replace(/\s/g, '');
}
@daronwolff
daronwolff / webpack.config.js
Created Feb 13, 2017
boilerplate webpack react
View webpack.config.js
var webpack = require('webpack');
var path = require('path');
module.exports = {
devtool: 'inline-source-map',
entry: [
'webpack-dev-server/client?http://127.0.0.1:8080/',
'webpack/hot/only-dev-server',
'./src'
],
@daronwolff
daronwolff / create_ssh_key
Last active Mar 1, 2017
Create and send ssh key. Ubuntu 16
View create_ssh_key
ssh-keygen -t rsa
echo "alias myserver='ssh myuser@192.168.0.1'" >> $HOME/.bashrc
cat $HOME/.ssh/id_rsa.pub | ssh myuser@192.168.0.1 'cat >> .ssh/authorized_keys'
source $HOME/.bashrc
myserver
View gist:66abb36f3a5b59c6df0dbfaf260f99e0
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /home/javier/sites/sitename/public;
index index.php index.html index.htm;
server_name server_domain_or_IP;
location / {
try_files $uri $uri/ /index.php?$query_string;
@daronwolff
daronwolff / design_pattern_javascript_module.js
Created Jan 9, 2017
This Javascript module design patternsis used for keeping particular pieces of code independent of other components
View design_pattern_javascript_module.js
// Module Design Pattern
var Car = (function() {
var manufacturer = "hyundai";
var wheels = 4;
var price = 149000;
var isAdmin = false;
var loginAdmin = function(u, p) {
if (u === 'admin' && p === '123') {
isAdmin = true;
console.log('Welcome admin');
@daronwolff
daronwolff / decode_tokenid.js
Created Aug 18, 2016
This function can be used to decode a string with token_id from openId response
View decode_tokenid.js
//
// This function can be used to decode a string with token_id from openId response
//
function decode_tokenid(token){
var elements = Array();
elements[0] = atob(token.split(".")[0]);
elements[1] = atob(token.split(".")[1]);
return elements;
}
You can’t perform that action at this time.