Skip to content

Instantly share code, notes, and snippets.

Avatar
🍊
workin' goodly

Gianni Chiappetta gf3

🍊
workin' goodly
View GitHub Profile
@gf3
gf3 / uuid.js
Created Dec 19, 2016
UUIDs ES6
View uuid.js
/**
* Convert a number or array of integers to a string of padded hex octets.
*/
function asHex(value: Array<number> | Uint8Array): string {
return Array.from(value).map(i => ('00' + i.toString(16)).slice(-2)).join('');
}
/**
* Attempt to securely generate random bytes/
*/
@gf3
gf3 / Rakefile
Created Sep 28, 2011 — forked from alexaivars/Rakefile
sass, haml & coffescript watcher
View Rakefile
require 'rake/clean'
BIN = "public_html"
HAML = FileList['**/*.haml']
LESS = FileList['**/*.less']
COFFEE = FileList['**/*.coffee']
SASS = FileList['**/*.scss']
HTML = HAML.ext('html')
View NaturalMotion.swift
//
// NaturalMotion.swift
//
// Created by Maciej Swic on 2014-06-06.
// Released under the MIT license.
//
import UIKit
extension UIView {
View Has weird right-to-left characters.txt
ּ_בּ
בּ_בּ
טּ_טּ
כּ‗כּ
לּ_לּ
מּ_מּ
סּ_סּ
תּ_תּ
٩(×̯×)۶
٩(̾●̮̮̃̾•̃̾)۶
View foo.rb
class Foo
autoload :Bar, 'foo/bar'
autoload :Baz, 'foo/baz'
end
@gf3
gf3 / model.js.coffee
Created Oct 24, 2012
Backbone Model Instance Sharing
View model.js.coffee
@instance_store = {}
class App.Model extends Backbone.Model
cache_enabled: false
cache_key: "id"
constructor: (attr) ->
@on "destroy", @_removeFromStore
View point.coffee
# ### Point.angleForCircle( origin, point ) -> Number
#
# * **origin** ( `Point` ): Origin of circle.
# * **point** ( `Point` ): Point to find angle of.
#
# Get the angle (in degrees) of a point for a given origin of a circle.
Point.angleForCircle = (origin, point) ->
x = origin.x - point.x
y = origin.y - point.y
r = Math.sqrt Math.pow(x, 2) + Math.pow(y, 2)
View radar.coffee
# Find closest point to a set of points.
findClosestPoint = (needle, haystack) ->
(init = new Point).diff = Number.MAX_VALUE
comparator = (memo, point) ->
point.diff = Math.abs(needle.x - point.x) + Math.abs(needle.y - point.y)
if point.diff < memo.diff then point else memo
_.foldl haystack, comparator, init
# Find closest point to a set of points based on angles.
findClosestPointByAngle = (needle, haystack, origin) ->
View radar.coffee
# Find closest point to a set of points.
findClosestPoint = (needle, haystack) ->
(init = new Point).diff = Number.MAX_VALUE
comparator = (memo, point) ->
point.diff = Math.abs(needle.x - point.x) + Math.abs(needle.y - point.y)
if point.diff < memo.diff then point else memo
_.foldl haystack, comparator, init
@gf3
gf3 / git-feature
Created May 3, 2011
Git Feature Command – Feature Branches
View git-feature
#!/usr/bin/env zsh
# git-feature
# Written by: Gianni Chiappetta <gianni@runlevel6.org>
# Requires: git 1.7.5+, zsh 4.3.11+
# Screenshot: http://cloud.gf3.ca/6TPb
function c_list { echo " \033[1;32m✔\033[0m $1"; }
function e_list { echo " \033[1;31m✖\033[0m $1"; }