Skip to content

Instantly share code, notes, and snippets.

View danieldietrich's full-sized avatar
💭
📡 working from space

Daniel Dietrich danieldietrich

💭
📡 working from space
View GitHub Profile
@cowboy
cowboy / HEY-YOU.md
Last active April 9, 2024 15:54
jQuery Tiny Pub/Sub: A really, really, REALLY tiny pub/sub implementation for jQuery.
/*!
* jQuery Tiny Pub/Sub - v0.X - 11/18/2010
* http://benalman.com/
*
* Original Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*
* Made awesome by Rick Waldron
*
@penguinboy
penguinboy / Object Flatten
Created January 2, 2011 01:55
Flatten javascript objects into a single-depth object
var flattenObject = function(ob) {
var toReturn = {};
for (var i in ob) {
if (!ob.hasOwnProperty(i)) continue;
if ((typeof ob[i]) == 'object') {
var flatObject = flattenObject(ob[i]);
for (var x in flatObject) {
if (!flatObject.hasOwnProperty(x)) continue;
@nickfloyd
nickfloyd / create_branch_from_tag
Created January 27, 2011 05:38
To create a branch from a tag
-Go to the starting point of the project
>> git checkout origin master
-fetch all objects
>> git fetch origin
-Make the branch from the tag
>> git branch new_branch tag_name
-Checkout the branch
>> git checkout new_branch
-Push the branch up
>> git push origin new_branch
@JamieMason
JamieMason / average.js
Created July 28, 2011 09:29
Using underscore.js, return the average value from an array of Numbers.
function average (arr)
{
return _.reduce(arr, function(memo, num)
{
return memo + num;
}, 0) / arr.length;
}
@viktorklang
viktorklang / na.scala
Created December 21, 2011 13:13
Fast, faster, Scala
object Scala extends App {
import scala.collection.mutable.ArrayBuffer
import scala.annotation.tailrec
val items = List("foo", 23, true)
val before = System.currentTimeMillis()
@tailrec def adds(n: Int, absoluteResult: ArrayBuffer[Any] = ArrayBuffer()): ArrayBuffer[Any] = {
def foo(obj : Any) = obj match {
case _:String => "String"
case _:Boolean => "Boolean"
case _:Integer => "Integer"
@gre
gre / easing.js
Last active April 23, 2024 04:20
Simple Easing Functions in Javascript - see https://github.com/gre/bezier-easing
/*
* This work is free. You can redistribute it and/or modify it under the
* terms of the Do What The Fuck You Want To Public License, Version 2,
* as published by Sam Hocevar. See the COPYING file for more details.
*/
/*
* Easing Functions - inspired from http://gizma.com/easing/
* only considering the t value for the range [0, 1] => [0, 1]
*/
EasingFunctions = {
@leon
leon / play.conf
Created March 26, 2012 12:27
Upstart script for Play Framework 2.0
# Upstart script for a play application that binds to an unprivileged user.
# put this into a file like /etc/init/play.conf
#
# This could be the foundation for pushing play apps to the server using something like git-deploy
# By calling service play stop in the restart command and play-start in the restart command.
#
# Usage:
# start play
# stop play
# restart play
@tonymorris
tonymorris / ReaderWriterStateT.scala
Created April 11, 2012 16:59
Reader/Writer/State transformer in Scala
case class ReaderWriterStateT[R, W, S, F[_], A](
run: (R, S) => F[(W, A, S)]
) {
def map[B](f: A => B)(implicit F: Functor[F])
: ReaderWriterStateT[R, W, S, F, B] =
ReaderWriterStateT {
case (r, s) => F.map(run(r, s)) {
case (w, a, s) => (w, f(a), s)
}
}
@sadache
sadache / gist:2939230
Created June 15, 2012 23:37
Parsing progressively a csv like file with Play2 and Iteratees

If your csv doesn't contain escaped newlines then it is pretty easy to do a progressive parsing without putting the whole file into memory. The iteratee library comes with a method search inside play.api.libs.iteratee.Parsing :

def search (needle: Array[Byte]): Enumeratee[Array[Byte], MatchInfo[Array[Byte]]]

which will partition your stream into Matched[Array[Byte]] and Unmatched[Array[Byte]]

Then you can combine a first iteratee that takes a header and another that will fold into the umatched results. This should look like the following code:

// break at each match and concat unmatches and drop the last received element (the match)