Skip to content

Instantly share code, notes, and snippets.

View pixelsnob's full-sized avatar

Luis A. Echeverria pixelsnob

View GitHub Profile
function quicksort([ ...arr ]) {
if (!arr.length) {
return [];
}
let left = [], pivot = arr[0], right = [];
for (let i = 1; i < arr.length; i++) {
if (arr[i] < pivot) {
left.push(arr[i]);
} else {
const pp = function() {
return new Promise((resolve, reject) => {
let r = (Math.round(Math.random() * 5, 0));
if (r > 3) {
setTimeout(() => resolve(r), r * 1000);
} else {
reject(`${r} is not enough`);
}
});
};
function fib(n) {
if (n < 1) {
return 1;
}
let a = 1, b = 0;
while (n >= 0) {
[ a, b ] = [ b, a + b ];
n--;
}
return b;
const Node = function(value, next) {
this.value = value;
this.next = next;
};
const List = function() {
this.length = 0;
this.head = null;
};
function Parent() {
console.log('hi from parent');
}
Parent.prototype.exampleMethod = function() {
console.log('hi from parent method');
};
function Child() {
Parent.call(this);
@pixelsnob
pixelsnob / classical.js
Last active September 13, 2018 20:53
Simulated "classical inheritance" in JS
const Parent = function(x) {
this.x = x;
console.log('Parent called');
};
const Child = function() {
Parent.call(this, 'xxxxx');
console.log('Child called');
};
@pixelsnob
pixelsnob / number-string-sort.js
Last active September 13, 2018 19:48
Sort an array of strings and numbers, but keeping the position of where strings or numbers appear in the original array
const arr = [
'tree', 'zebra', 40, 'y', 5000, 8, 14, 'zzzzz', 1, 'a', 'bbbbb'
];
let numbers_pos = [];
let words_pos = [];
let words_slots = [], numbers_slots = [];
arr.forEach((val, i) => {
if (typeof val == 'string') {
  • A remote, full-time position as an Open Source/JavaScript front-end or full-stack developer. I have 10+ years in web application development, and 3 years doing full-stack JavaScript
  • A stack such as backbone.js, webpack, React, mongodb, ES6/7, and node.js would be great! Also have production dev experience in PHP. Very open to learning new things, open to new tools, not "religious" about any one thing
  • Prefer industries that are doing “something positive” for society. I know: this is a wide range and very vague, so I won’t list here, but prefer to stay away from oil companies, cigarette companies — as a couple of examples of where I wouldn’t work. So basically, a place with at least an awareness of ethics and social responsibility
  • A workplace with knowledge/understanding of mental illness, especially depression and social anxiety; that it doesn't mean people like me can't be super productive, given a fairly stable environment
  • Reasonable hours, please
  • If there is any travel, that there be some op
@pixelsnob
pixelsnob / fix_photo_filenames
Created July 13, 2012 02:14
Script that recursively reads a directory, then copies the files to another (flat) directory and renames them to a unique filename
<?php
/**
* Script that recursively reads a directory, then copies the files to another
* directory. Filenames will be 20120525-1.jpg, 20120525-2.jpg, etc.
*
*/
ini_set('date.timezone', 'America/Los_Angeles');
$dir = '/Users/luis/Pictures/Nikon Transfer 2/';