Skip to content

Instantly share code, notes, and snippets.

@lotsofcode
lotsofcode / gist:24592ed8614c50403c62
Created January 13, 2015 14:35
name-that-color.js
/*
+-----------------------------------------------------------------+
| Created by Chirag Mehta - http://chir.ag/projects/ntc |
|-----------------------------------------------------------------|
| ntc js (Name that Color JavaScript) |
+-----------------------------------------------------------------+
All the functions, code, lists etc. have been written specifically
for the Name that Color JavaScript by Chirag Mehta unless otherwise
@lotsofcode
lotsofcode / gist:4b39e61d851410e36b06
Created November 20, 2014 11:02
virtualbox-ns_error_failure-fix
#----------------------------------------------------------------------
# virtualbox error
#----------------------------------------------------------------------
There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.
Command: ["hostonlyif", "create"]
Stderr: 0%...
@lotsofcode
lotsofcode / gist:92f90fbb5423d6317c8c
Created July 31, 2014 15:23
JSON format with stringify
JSON.stringify(jsObj, null, "\t"); // stringify with tabs inserted at each level
JSON.stringify(jsObj, null, 4); // stringify with 4 spaces at each level
@lotsofcode
lotsofcode / gist:90dfd4e4a8738c4d571b
Created July 31, 2014 15:22
JSON stringify replacer
// @ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Parameters
function censor(key, value) {
if (typeof value === "string") {
return undefined;
}
return value;
}
var foo = {
@lotsofcode
lotsofcode / prepend-child.js
Created July 31, 2014 14:30
JavaScript implementation of "prependChild"
Element.prototype.prependChild = function(newElement) {
return this.insertBefore(newElement, this.firstChild);
};
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<h1>Angular CORS configuration</h1>
(function() {
var CSSCriticalPath = function(w, d, opts) {
var opt = opts || {};
var css = {};
var pushCSS = function(r) {
if(!!css[r.selectorText] === false) css[r.selectorText] = {};
var styles = r.style.cssText.split(/;(?![A-Za-z0-9])/);
for(var i = 0; i < styles.length; i++) {
if(!!styles[i] === false) continue;
var pair = styles[i].split(": ");
(function () {
var scriptName = "embed.js"; //name of this script, used to get reference to own tag
var jQuery; //noconflict reference to jquery
var jqueryPath = "http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js";
var jqueryVersion = "1.8.3";
var scriptTag; //reference to the html script tag
/******** Get reference to self (scriptTag) *********/
var allScripts = document.getElementsByTagName('script');
/*global angular: true, google: true, _ : true */
'use strict';
angular.module('geocoder', ['ngStorage']).factory('Geocoder', function ($localStorage, $q, $timeout) {
var locations = $localStorage.locations ? JSON.parse($localStorage.locations) : {};
var queue = [];
// Amount of time (in milliseconds) to pause between each trip to the
require 'sinatra'
require 'premailer'
require 'json'
configure :production do
set :port, 80
end
get '/premailer' do
<<-eos