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
function multiMax(multi){
// Make an array of all but the first argument
var allButFirst = Array().slice.call(arguments);
// Find the largest number in that array of arguments
var largestAllButFirst = Math.max.apply(Math,allButFirst);
// Return the multiplied result
return multi * largestAllButFirst;
}
@daronwolff
daronwolff / exercise_9.js
Last active May 23, 2016 16:49
Write a function that returns two functions that implement up/down counter
function counterf(n) {
var n = n;
var inc = function() {
return n += 1;
};
var dec = function() {
return n -= 1;
};
return {
dec: dec,
@daronwolff
daronwolff / exercise_9.js
Last active May 23, 2016 16:51
Write a function that returns two functions to up/down counter
var counterf = (function(n){
var inc = function() {
return n += 1;
};
var dec = function() {
return n -= 1;
};
return {
dec: dec,
inc: inc
@daronwolff
daronwolff / exercise_10.js
Last active May 23, 2016 17:03
Make a revocable function that takes a nice function and returns a revoke function that denies the access to the nice function, and an invoke function it is invokes the nice function until be revoked
var revoke = (function(func) {
var tmp = func;
return {
invoke: function(p) {
tmp(p);
},
revoke: function() {
tmp = null;
}
}
@daronwolff
daronwolff / promises_example.js
Last active May 23, 2016 20:53
Promises Example
(function() {
var restante = 0;
'use strict';
function wait() {
return new Promise(function(done, reject) {
setTimeout(function() {
if (restante > 0) {
done();
} else {
@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;
};
@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 / 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 / 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');
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;