Skip to content

Instantly share code, notes, and snippets.

daronwolff daronwolff

View GitHub Profile
@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;
}
@daronwolff
daronwolff / clear_string.php
Last active Jul 31, 2016
PHP, This function removes the accents, white-spaces and symbols from characters in a string. Can be used to clear the strings on usernames, filenames
View clear_string.php
/**
* Function clear_string
*
* Function used to user strings as usernames, filenames
* This function removes the accents, white-spaces and symbols from characters in a string
*/
if (! function_exists('clear_string'))
{
function clear_string($str = '')
{
View examples_prototype.js
function Triangle() {
this.a;
this.b;
this.c;
this.setSides = function(a, b, c) {
this.a = a;
this.b = b;
this.c = c;
};
You can’t perform that action at this time.