Skip to content

Instantly share code, notes, and snippets.

View jescalan's full-sized avatar

Jeff Escalante jescalan

View GitHub Profile
@jescalan
jescalan / main.go
Last active August 29, 2015 14:03
Is there any reason to ever use the new keyword in go?
package main
import "fmt"
type Vertex struct {
X, Y int
}
func main() {
v := new(Vertex)
@jescalan
jescalan / index.md
Last active August 29, 2015 14:13
Named Functions

Using Named Functions

In javascript, there are two methods of declaring functions that are seen frequently. They are similar in many ways, but there are a few ways in which they are different. The first one is called a named function. This is how it looks:

function test(){
  console.log('hello world!');
}
@jescalan
jescalan / app.coffee
Last active August 29, 2015 14:18 — forked from andyshora/app.coffee
axis = require 'axis'
js_pipeline = require 'js-pipeline'
css_pipeline = require 'css-pipeline'
roots_config = require 'roots-config'
W = require 'when'
readdirp = require 'readdirp'
siteFiles = []
# generate files for sitemap
@jescalan
jescalan / loop.js
Created November 16, 2011 19:16 — forked from wycats/loop.js
Handlebars No Name Loop
// The JSON (get back from api as javascript objects contained in an array)
// when logged to console, [▶Object,▶Object] etc.
// can be manipulated before being passed to handlebars
[
{
id: 1,
link: "http://abcnews.go.com/Business/video/job-search-social-media-ditch-resume-hunt-nontraditional-ways-internet-professional-contacts-business-13581468",
title: "ABC News: Job Search Through Social Media",
updated_at: "2011-10-19T16:22:30Z"
@jescalan
jescalan / loop.js
Created November 16, 2011 18:08
Handlebars No Name Loop
// The JSON
[
{
created_at: "2011-10-19T16:22:30Z",
id: 1,
link: "http://abcnews.go.com/Business/video/job-search-social-media-ditch-resume-hunt-nontraditional-ways-internet-professional-contacts-business-13581468",
title: "ABC News: Job Search Through Social Media",
updated_at: "2011-10-19T16:22:30Z"
},
@jescalan
jescalan / mgr.sh
Created January 11, 2012 15:25
bash file management
# This script is a great shorcut for managing a large number of files.
# It runs through all the files in the present working directory, compares them
# against a regex, and then you can do what you want with the matches
for f in *
do if [[ "$f" =~ some_regex ]]
# do something to the files that match
# this is just an random example that zips them
then zip "$f.zip" $f
fi
@jescalan
jescalan / d3-css.js
Created January 21, 2012 18:33
jQuery-style css selector for d3 library
// D3: a data visualization library for javascript --http://mbostock.github.com/d3/
// Allows you to set multiple css properties at once
// Add this into the d3 source. Use like this d3.select('p').css({ color: 'red', 'font-size': '24px' });
d3_selectionPrototype.css = function(args) {
for (var key in args) {
var val = args[key]
this.style(key, val)
}
}
@jescalan
jescalan / challenge.rb
Created January 24, 2012 16:44
numbas
str = "iirytroyppytpeppowuiyoiuypipiyuyotyoiwiytorouqyiepyirueuiprpptwyiroqwtuyipourrrourorwipowiorutpwtwruuioquteorioriyutwqyyprptuqqquuituyywyuoewtrppqwrtiiruirpwyptpuoyyoeyerpqiotuieripurouwuwyuwrworowitoepoypeipeypiireeorrwripuuteoitpuutturruwiyryeetyrioweytueqrrrtotrpiqetoyepoipiwrwpppiritupwipruooiepoweypiuwrqywuuwyiroqpqpruioopuiuerputpwwuuiqwpiroewrtwiqerteoyeqtutwoeoipioiuqiiiouuoqtuuwtuwiiqwppqitywuqpuutrqiyoeuuutwrwtoqrqyoeyoiporuuioiwryoeruypreprqroiyuqwtuyoytoerwqryeeripryieypiwqirtriurueypiuyuypriuiwptywppupoioyrewooytreteeriiwroietuwypieeeeeqpiiiwrirtppoeyiwpooyyporpruwuoriiyowuytiwpwpryeywotoyirqypyypoeptiuwwoyprquoetepptorwiewprpiywwtuieeiweytrrwiqtwotioryoiptyyyuriiqiyroeeiqepwteuwptpruuypipieuoiiuuweeuryuuowporrooyywyyrryriqyirooitirueruptotpryoqtipippyptiurwyiryooywtryyuurtrutwqiqiiiqwouyeooueoturuowiuwrtruwwiupwopwweoo"
key_map = %w[q w e r t y u i o p]
number_map, result = [], []
# map to keyboard character
str.split('').each do |letter|
key_map.each_with_index do |key,index|
numb
@jescalan
jescalan / extension.sh
Created January 26, 2012 17:12
Bash, change file extensions
for f in *.jpeg; do mv "$f" "`basename "$f" .jpeg`.jpg"; done;
@jescalan
jescalan / split.sass
Created February 13, 2012 17:51
Split Mixin
=split($margin: 10px)
$left: $margin
$right: $margin
@if type-of($margin) == list
$left: nth($margin, 1)
$right: nth($margin, 2)
overflow: hidden
& > *
overflow: hidden