Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jimtla
jimtla / underscoreR.coffee
Created May 6, 2012 21:51
Add CoffeeScript friendly argument order to Underscore.js
# Five lines of code that will make your underscore + CoffeeScript use cleaner.
# Creates an underscore function for each function in to_reverse with R (short for Reversed) appended to the name.
# The R version moves the function argument (first argument in normal underscore) to the end,
# so you can write:
$(window).scroll _.throttleR 500, ->
console.log "This print's at most every 500ms"
# Instead of:
$(window).scroll _.throttle ->
console.log "This prints at most every 500ms too"
@jimtla
jimtla / cheater.coffee
Created March 12, 2013 15:31
A perfect solution to AlexeyMK/guessing-game, although I can't help but feel it violates the spirit of the game.
cheater =
start_game: ->
@count = 0
global.Math = {random: => @count++}
guess_index: (cur_num) ->
return cur_num
name: "Cheater"
import skein
from random import choice
target = '5b4da95f5fa08280fc9879df44f418c8f9f12ba424b7757de02bbdfbae0d4c4fdf9317c80cc5fe04c6429073466cf29706b8c25999ddd2f6540d4475cc977b87f4757be023f19b8f4035d7722886b78869826de916a79cf9c94cc79cd4347d24b567aa3e2390a573a373a48a5e676640c79cc70197e1c5e7f902fb53ca1858b6'
def bitcount(v):
if v > 0:
return (v & 1) + bitcount(v>>1)
else:
return 0
### Keybase proof
I hereby claim:
* I am jimtla on github.
* I am jimtla (https://keybase.io/jimtla) on keybase.
* I have a public key whose fingerprint is 9997 4223 B138 49BF 6F43 C80F AA4A 7117 AC09 F449
To claim this, I am signing this object:
@jimtla
jimtla / main.go
Created August 21, 2014 22:51
Test Program for Golang's heap profiler
package main
import (
"log"
"net/http"
_ "net/http/pprof"
)
func wasteMemory() {
s := "ABCDEFGHIJKLMNOPQRSTUVWXYZ00123456789"
@jimtla
jimtla / resizeAndWrite.go
Last active August 29, 2015 14:05
Code Sample for Go Leaks blog post
func resizeAndWrite(img image.Image, width int, path string, c chan error) {
newImg := resize.Resize(uint(width), 0, img, resize.Bicubic)
err := writeJpegToS3(s, newImg, path)
// Write back to the channel with the status of the S3 write operation.
c <- err
}
@jimtla
jimtla / gist:32dab1bb0ea0424710f8
Last active August 29, 2015 14:05
Code Sample for Go Leaks blog post
func createAlternateSizes(photoPath string, img image.Image, block bool) error {
// Put a white background on all the resized images.
whiteImg := imageWithWhiteBg(img)
c := make(chan error, 0)
go resizeAndWrite(whiteImg, 640, photoPath + "_f", c)
go resizeAndWrite(whiteImg, 290, photoPath + "_s", c)
go resizeAndWrite(whiteImg, 200, photoPath + "_d", c)
if block {
@jimtla
jimtla / gist:6693f7614ecfcd5fa7e9
Created August 21, 2014 23:54
Code Sample for Go Leaks blog post
func createAlternateSizes(photoPath string, img image.Image, block bool) error {
// Put a white background on all the resized images.
whiteImg := imageWithWhiteBg(img)
numberOfResizes := 3
c := make(chan error, numberOfResizes)
go resizeAndWrite(whiteImg, 640, photoPath + "_f", c)
go resizeAndWrite(whiteImg, 290, photoPath + "_s", c)
go resizeAndWrite(whiteImg, 200, photoPath + "_d", c)
@jimtla
jimtla / gist:6c5191760729d0ec2502
Created August 22, 2014 00:04
Code Sample for Go Leaks blog post
21 @ 0x26be6 0x12f4d 0x135bc 0x69d24 0x26db0
# 0x69d24 jello/models.resizeAndWrite+0x6145
~/go/src/jello/models/photo.go:149
#![feature(collections)]
#![feature(box_patterns)]
#[cfg(feature = "simple")]
pub fn matches(regex : &str, target : &str) -> bool {
match (regex.slice_shift_char(), target.slice_shift_char()) {
// Both strings are emtpy, so we've got a match.
(None, None) => true,
// We're looking at _*, match the kleene star.