Skip to content

Instantly share code, notes, and snippets.

View daronwolff's full-sized avatar
🏠
Working from home

daronwolff daronwolff

🏠
Working from home
  • Me
  • México
View GitHub Profile
@daronwolff
daronwolff / sequentially.js
Created June 16, 2017 20:18
Executing promises sequentially
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 April 13, 2017 16:43
This function is similar to Promise.all but this receives an object. The param names from promisesObject is used to clasify the information
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 March 29, 2017 15:54
CapitalizeString and remove white spaces
function capitalize(str) {
return str.replace(/\b\w/g, l => l.toUpperCase())
.replace(/\s/g, '');
}
@daronwolff
daronwolff / webpack.config.js
Created February 13, 2017 22:10
boilerplate webpack react
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 March 1, 2017 21:20
Create and send ssh key. Ubuntu 16
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
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 January 9, 2017 16:19
This Javascript module design patternsis used for keeping particular pieces of code independent of other components
// 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 August 18, 2016 17:51
This function can be used to decode a string with token_id from openId response
//
// 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 July 31, 2016 05:14
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
/**
* 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 = '')
{
@daronwolff
daronwolff / examples_prototype.js
Created May 23, 2016 21:58
Prototype examples
function Triangle() {
this.a;
this.b;
this.c;
this.setSides = function(a, b, c) {
this.a = a;
this.b = b;
this.c = c;
};