Skip to content

Instantly share code, notes, and snippets.

@pfn
pfn / AndroidConversions.scala
Created February 7, 2012 23:41
AndroidConversions.scala
package com.hanhuy.android.irc
import android.app.Activity
import android.app.ActionBar
import android.content.Intent
import android.content.Context
import android.content.BroadcastReceiver
import android.content.res.Configuration
import android.os.AsyncTask
import android.os.Build
@pfn
pfn / build.scala
Created February 24, 2012 05:13
multi-project build.scala
import sbt._
import sbt.Keys._
import AndroidKeys._
/*
* this represents a multi-project structure like:
* - root-project (wrapper/meta project)
* `- lite (android project)
* `- common (android library-project)
@guillaumebort
guillaumebort / 1.sql
Created May 25, 2012 15:17
Play 2.0/Anorm
# --- !Ups
CREATE TABLE users(
email VARCHAR(255) NOT NULL PRIMARY KEY,
name VARCHAR(255)
);
CREATE TABLE subjects(
id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
title LONGTEXT NOT NULL,
@alvinj
alvinj / sbtmkdirs.sh
Last active June 22, 2024 15:13
A shell script to create an SBT project directory structure
#!/bin/bash
#------------------------------------------------------------------------------
# Name: sbtmkdirs
# Version: 1.5
# Purpose: Create an SBT project directory structure with a few simple options.
# Author: Alvin Alexander, http://alvinalexander.com
# License: Creative Commons Attribution-ShareAlike 2.5 Generic
# http://creativecommons.org/licenses/by-sa/2.5/
#------------------------------------------------------------------------------
@ayosec
ayosec / CORSDirectives.scala
Created December 18, 2012 03:28
CORS with Spray
package foo.bar
import spray.routing._
import spray.http._
import spray.http.StatusCodes.Forbidden
// See https://developer.mozilla.org/en-US/docs/HTTP/Access_control_CORS
case class Origin(origin: String) extends HttpHeader {
@noelmarkham
noelmarkham / gist:5771197
Last active December 18, 2015 10:49
My attempt at Tony Morris's refactoring puzzle - see http://tmorris.net/posts/refactoring-puzzle/index.html
object RefactorPuzzle {
case class IntRdr[+A](read: Int => A) {
def map[B](f: A => B): IntRdr[B] =
IntRdr(f compose read)
def flatMap[B](f: A => IntRdr[B]): IntRdr[B] =
IntRdr(n => f(read(n)).read(n))
}
object IntRdr {
@textarcana
textarcana / install-jenkins-centos-6-3.sh
Last active June 3, 2020 15:27
How to install Jenkins on CentOS 6.3
sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo
sudo rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key
sudo yum -y install jenkins
sudo yum -y install java-1.7.0-openjdk.x86_64
# Login as the jenkins user and specify shell explicity,
# since the default shell is /bin/false for most
# jenkins installations.
sudo su jenkins -s /bin/bash
object Predicates {
type Pred[-T] = (T => Boolean)
implicitly[Seq[Int] >:> List[Int]]
implicitly[Pred[Seq[Int]] <:< Pred[List[Int]]] // predicate of seq is a subtype of predicate of list
val hasLength3: Pred[Seq[Int]] = _.size == 3
hasLength3(Vector(1,2,3)) // we can pass any seq to hasLength3
hasLength3(List(1,2,3))
anonymous
anonymous / Dependencies.scala
Created June 23, 2013 03:53
Here's an SBT build file I work on that I think is pretty clean.
package com.rackspace.dcx.dcorch.build
import sbt._
trait Dependencies {
private object v {
val akka = "2.1.4"
@shajra
shajra / Task.scala
Created August 23, 2013 03:34
integration code between Scalaz and Scala standard concurrency libraries.
import concurrent.{ExecutionContext, Future => SFuture, Promise}
import util.Try
import _root_.scalaz.\/
import _root_.scalaz.concurrent.{Task => ZTask}
object Task {
def fromScala[A]