Skip to content

Instantly share code, notes, and snippets.

View lcaballero's full-sized avatar

Lucas Caballero lcaballero

View GitHub Profile
@lcaballero
lcaballero / uuid
Created September 30, 2014 04:56
A uuid mixin for Lodash.
_.mixin
# Better than random number, this should not allow for collisions.
# Code was minimally modified from
# [stackoverflow](http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript),
# demonstrated at [jsfiddle](http://jsfiddle.net/briguy37/2MVFd/)
uuid : ->
now = Date.now()
'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace /[xy]/g, (c) ->
r = (now + Math.random() * 16) % 16 | 0
now = Math.floor now / 16
@lcaballero
lcaballero / console.json
Created September 12, 2014 17:09
Coffee script to add json serialization to a var args call on console.
console.json = (args...) ->
console.log.apply(console, _.map(args, (a) -> JSON.stringify(a, null, ' ')))
@lcaballero
lcaballero / Bat Shit Obnoxious CoffeeScript whitespace issues
Created August 25, 2014 21:42
Bat Shit Obnoxious CoffeeScript whitespace issues
key = "some key"
key.substring(0, key.length -1) # <= Produces length is not a function Hahaha
@lcaballero
lcaballero / gist:c36f1da0206cf81b1caf
Created August 24, 2014 17:45
A bit of jquery code to pull rgb colors from Kuler themes.
$("div.content").on("click", function(ev) {
var s = []
var e = $(this)
if (e.is(".content")) {
e.find(".frame > div")
.each(function(i,e) {
var rgb = $(e).css("background-color")
.match(/([0-9]+)/g, ',')
@lcaballero
lcaballero / cli-color.java
Created May 5, 2014 17:31
Quick snippet about how to add color to the console from Java
public void start() {
started = true;
System.out.print("\u001b[31m");
System.out.print(Joiner.on(", ").join("Hello", "World"));
System.out.print("\u001b[39m");
System.out.println();
}
@lcaballero
lcaballero / Tmux conf dot file stuff
Created December 19, 2013 08:37
Tmux conf dot file stuff.
# .tmux.conf
bind | split-window -h
bind - split-window -v
bind r source-file ~/.tmux.conf
set -g default-terminal "screen-256color"
setw -g mode-mouse on
set -g mouse-select-pane on
@lcaballero
lcaballero / Coffee Quick Examples
Created December 10, 2013 18:22
Coffee Quick Examples (mostly just a text file with coffee, js, and notes thrown together).
# Coffee Script
# Overview
# variable that is closed, var(ed) and not exposed to the global, or window
# object which reduces leaking variables
variable = "value"
# Thin Arrow
# Function one-liners
@lcaballero
lcaballero / Alias for Make dir, cd into dir
Created October 25, 2013 03:59
Alias for Make dir, cd into dir
createAndMove() { mkdir $1; cd $1; }
alias md="createAndMove"
@lcaballero
lcaballero / Event loop halting
Created October 22, 2013 05:28
Example showing the event loop halting because of a `while` loop.
setTimeout(function() {
console.log("after 2sec")
}, 2000)
d = new Date()
while (new Date().getTime() - d.getTime() < 3000);
console.log("after 3sec")
@lcaballero
lcaballero / Recursion + Async + Promise + Node
Created October 14, 2013 22:28
Recursive + async traversal of a directory using Promises and Node
Q = require('q')
fs = require('fs')
_ = require("lodash")
isFile = (name) ->
fs.statSync(name).isFile()
isDirectory = (name) ->
fs.statSync(name).isDirectory()