Skip to content

Instantly share code, notes, and snippets.

@lauris
lauris / fix_django_timezones.sh
Created August 15, 2014 16:21
Fix Django timezones issue: "Database returned an invalid value in QuerySet.datetimes(). Are time zone definitions for your database and pytz installed?"
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
@lauris
lauris / ccToMap.scala
Created August 9, 2014 10:12
Convert case class to map in Scala
def ccToMap(cc: AnyRef) =
(Map[String, Any]() /: cc.getClass.getDeclaredFields) {
(a, f) =>
f.setAccessible(true)
a + (f.getName -> f.get(cc))
}
// Usage
case class Column(name: String,
val myRequest = "http://somehost.com" / "some" / "path" <<? Map("id" -> "12345")
@lauris
lauris / monoidal_fizzbuzz.scala
Created May 26, 2014 06:56
Monoidal FizzBuzz In Scala by Dominic Fox
import scalaz._
object Main {
case class FizzBuzz(elems: String*)
implicit object FizzBuzzMonoid extends Monoid[FizzBuzz] {
override def zero = FizzBuzz()
override def append(f1: FizzBuzz, f2: => FizzBuzz): FizzBuzz = FizzBuzz(f1.elems ++ f2.elems :_*)
}
implicit def flipImplicitlyCurried[A,B,C](f: A => B => C) = (b: B) => (a: A) => f(a)(b)
ace.require("ace/lib/net").loadScript("https://raw.github.com/ajaxorg/ace-builds/master/src-min-noconflict/keybinding-vim.js", function() {
e = $(".file-contents").codeEditor().editor;
e.setKeyboardHandler(ace.require("ace/keyboard/vim").handler);
})
/** Fix navigation bar width */
.global-nav .container { max-width: 910px; }
/** Hide Me & DM menu items */
.global-nav li.profile, .global-nav .dm-nav { display: none; }
/** Remove bottom border from active menu item and just set text color to black instead */
#global-actions > li > a { border-bottom: none; }
#global-actions > li:hover > a, #global-actions>li.active>a { color: black; }
alert((![]+[])[+[]]+(![]+[])[+!+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]);
@lauris
lauris / github-vim.js
Created December 13, 2013 11:44
Github Vim
ace.require("ace/lib/net").loadScript("https://raw.github.com/ajaxorg/ace-builds/master/src-min-noconflict/keybinding-vim.js", function() {
e = document.getElementById("ace-editor").env.editor;
e.setKeyboardHandler(ace.require("ace/keyboard/vim").handler);
})
@lauris
lauris / Balance.scala
Created September 18, 2013 07:31
A recursive function which verifies the balancing of parentheses in a string, which we represent as a List[Char]. Recfun 2013, Week 1.
package recfun
import common._
import scala.annotation.tailrec
object Balance {
def balance(chars: List[Char]): Boolean = {
@tailrec
def loop(chars: List[Char], open: Int): Boolean = {
chars match {
case Nil => open == 0