Skip to content

Instantly share code, notes, and snippets.

View kidGodzilla's full-sized avatar
👋
Working from home forever

James Futhey kidGodzilla

👋
Working from home forever
View GitHub Profile
@kidGodzilla
kidGodzilla / letRubyInfluenceJavaScript.js
Last active August 29, 2015 14:12
let rubyInfluenceJavaScript
//let rubyInfluenceJavaScript
Number.prototype.times = function(f){for(a=-1;++a<this;){f(a)}return+this};
Number.prototype.upto = function(a,f){b=this;if(a<b){return+b}for(;b<=a;){f(b++)}return+b};
Number.prototype.downto = function(a,f){b=this;if(a>b){return+b}for(;b>=a;){f(b--)}return+b};
Number.prototype.to = function(a,f){a>this?this.upto(a, f):this.downto(a, f)};
Number.prototype.toS = function(){return ""+this};
String.prototype.toI = function(){return parseInt(this)};
String.prototype.toF = function(){return parseFloat(this)};
// ruby-inspired looping
@kidGodzilla
kidGodzilla / this-method-will-self-destruct.js
Created January 5, 2015 05:11
Prototype an object with secret methods which self-destruct
function SecretMethods () {} (function () {
var add = function (a,b) {
return a + b;
}
var mul = function (a,b) {
return a * b;
}
@kidGodzilla
kidGodzilla / cachebuster.js
Created May 5, 2015 19:49
JavaScript Cache Buster Example
/**
* Generates a random hex string
*/
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
/**
@kidGodzilla
kidGodzilla / concise-dll.js
Created May 13, 2015 07:18
Doubly-Linked List
/**
* **************************************************************************************
* dll: A Concise Doubly-Linked List Object
*
* Author: James Futhey <futhey@gmail.com>, 2015
* 277 characters
*
* Each node contains a value and up to two objects, representing the previous (p) and
* next (n) object in the list, if applicable.
*
@kidGodzilla
kidGodzilla / LICENSE.txt
Last active August 29, 2015 14:26 — forked from LeverOne/LICENSE.txt
generate random v4 UUIDs (107 bytes)
DO WTF YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Alexey Silin <pinkoblomingo@gmail.com>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WTF YOU WANT TO PUBLIC LICENSE
@kidGodzilla
kidGodzilla / flattenArrays.js
Created August 10, 2015 09:03
A couple of functions to flatten arrays, with tests. See http://jsbin.com/zoqorudoka/edit?js,console
/**
* Test Inputs
*/
a = [[1,2,[3.23,4,"dfger",[5]]],4];
a2 = [[[[[0]], [1]], [[[2,5,6], [3]]], [[4], [5]]]];
/**
* Recursively flatten an array
*/
function flatten (array) {
@kidGodzilla
kidGodzilla / responsive-text.css
Last active August 29, 2015 14:27
Simple, declarative responsive text classes
/* Responsive text */
.text-left { text-align: left; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-justify { text-align: justify; }
@media (max-width: 768px) {
.text-left-xs { text-align: left; }
.text-right-xs { text-align: right; }
.text-center-xs { text-align: center; }
@kidGodzilla
kidGodzilla / deduce-type.php
Last active August 29, 2015 14:27
Deduce a value's type from a stringified version of that value
// Deduce Type
// James Futhey, 2015
//
// Useful for parsing a $_GET or $_POST value and knowing it's MySQL-compatible type
function deduceType ($value) {
if (strlen(strval($value)) === 0) {
return "null";
}
if ($value === "true" || $value === "false") {
@kidGodzilla
kidGodzilla / bootstrap-grid.css
Created September 4, 2015 19:54
Bootstrap - Just the grid
@-ms-viewport {
width: device-width;
}
.visible-xs,
.visible-sm,
.visible-md,
.visible-lg {
display: none !important;
}
.visible-xs-block,
@kidGodzilla
kidGodzilla / style.css
Last active October 10, 2015 16:38
Example CSS Styles for the Ember 2 blog example application
@import url(//fonts.googleapis.com/css?family=Lato:300,400,300italic,400italic);
@import url(//fonts.googleapis.com/css?family=Merriweather:300italic,300,700,700italic);
@import url(//fonts.googleapis.com/css?family=Montserrat:400,700);
body {
width: 60%;
margin-left: 20%;
font-family: 'Merriweather', serif;
font-weight: 300;
font-size: 18px;