Skip to content

Instantly share code, notes, and snippets.

@dcolish
dcolish / migration.sh
Created June 8, 2011 23:10
Migrations done in bash
#!/bin/bash
RUN_SQL?="$(which psql) i3"
function _info(){
echo "At migration version: $(cat .migration-version)"
}
function _init() {
echo 0 > .migration-version
@zbskii
zbskii / yc.py
Created April 10, 2012 03:38
Y-Combinator
# -*- coding: utf-8 -*-
# a functional is a function that takes a function for its input
def fact(factorial):
def fn(n):
if n == 0: return 1
else:
return n * factorial(n - 1)
return fn
@dbackeus
dbackeus / utf8_json_spec.rb
Created December 13, 2012 17:11
Spec to confirm monkey patch still necessary for: https://github.com/rails/rails/issues/3727
# Encoding: UTF-8
require 'spec_helper'
# Specs for initializers/patches.rb
describe ActiveSupport::JSON::Encoding do
it "should not break high bitrate utf-8 characters" do
hash = { string: "𐒑" }
json = ActiveSupport::JSON.encode(hash)
object TypeClassExample {
trait UnicodeOrdered[T] {
def ≤(i:T,j:T): Boolean
}
object UnicodeOrdered {
implicit object UnicodeOrderedInt extends UnicodeOrdered[Int] {
def ≤(i:Int,j:Int): Boolean = i <= j
}
@larsrh
larsrh / build.sbt
Created November 17, 2013 21:49
Code examples from scala.io 2013 (see comments). Note that until shapeless 2.0.0 is out, this is still in a state of flux.
scalaVersion := "2.10.2"
resolvers += Resolver.sonatypeRepo("snapshots")
libraryDependencies += "org.typelevel" %% "shapeless-scalaz" % "0.2-SNAPSHOT"
libraryDependencies += "org.typelevel" %% "shapeless-scalacheck" % "0.2-SNAPSHOT"
initialCommands in console := """
import scalaz._
@ramn
ramn / XmlSchemaValidator.scala
Created December 2, 2010 11:02
XML Schema validator in Scala
import javax.xml.transform.stream.StreamSource
import javax.xml.validation.Schema
import javax.xml.validation.SchemaFactory
import javax.xml.validation.{Validator=>JValidator}
import org.xml.sax.SAXException
object Validator {
def main(args: Array[String]) {
require(args.size >= 2, "Params: xmlFile, xsdFile")
val result =
<?php
/**
* PDO SINGLETON CLASS, ADODB ENABLED
*
* @author Tony Landis
* @link http://www.tonylandis.com
* @license Use how you like it, just please don't remove or alter this PHPDoc
*/
class sdb {
/**
@tony-landis
tony-landis / pdo-adodb-singleton-refactor.class.php
Created December 3, 2008 07:44
PHP PDO Singleton w/AdoDB backwards compatable
<?php
/**
* PDO SINGLETON CLASS, ADODB ENABLED
*
* @author Tony Landis
* @link http://www.tonylandis.com
* @license Use how you like it, just please don't remove or alter this PHPDoc
*/
class sdb
{
@legumbre
legumbre / foo.md
Created June 29, 2012 00:14
resolving merge conflicts with magit-ediff

Use magit-ediff to resolve merge conflicts

Use magit-ediff or 'e' on an unmerged item to resolve merge conflicts with ediff. Magit will set up an ediff with three buffers A, B and C. A and B are the original (conflicting) files, and C is the conflicted merge.

Use 'n'/'p' to move to the next/previous conflict, use 'a'/'b' to choose which changes (those in a A or B) should be the ones to keep in the merged file.

You can always just switch to buffer C and edit what the merged version should look like.

@hpbuniat
hpbuniat / namespaceRefactor.php
Last active April 3, 2021 22:33
Super-simple script to convert a existing project to use namespaces
<?php
/**
* Super-simple script to convert a existing project to use namespaces
*
* @author Hans-Peter Buniat <hpbuniat@googlemail.com>
* @copyright 2012 Hans-Peter Buniat <hpbuniat@googlemail.com>
* @license http://opensource.org/licenses/BSD-3-Clause
*/
class namespaceRefactor {