Skip to content

Instantly share code, notes, and snippets.

@wfaler
wfaler / rsync-exactcopy.sh
Last active December 11, 2015 20:28
rsync exact copy from source to copy
rsync -vaz --delete source/* 'copy 1'/
@wfaler
wfaler / cabal-source.cabal
Created December 7, 2012 23:50
cabal-source.cabal
library
build-depends: base, HUnit
exposed-modules: Module.Name
Hs-Source-Dirs: src
@wfaler
wfaler / mac-switching-java.sh
Created November 23, 2012 13:27
mac-switching-java.sh
cd /System/Library/Frameworks/JavaVM.framework/Versions/
sudo rm Current
sudo ln -s [Java version folder] Current
@wfaler
wfaler / java-interdependency-null-bug.java
Created November 15, 2012 21:39
java-interdependency-null-bug.java
public class Basket{
private List<LineItem> lineItems = ...
public List<Product> getProductsOfType(String type){
List<Product> products = new ArrayList<Product>();
for(LineItem item : lineItems){
if(item.getProductType().equals(type)
products.add(item.getProduct());
}
return products;
@wfaler
wfaler / cake-pattern-example.scala
Created October 22, 2012 16:57
simple-cake-pattern-example.scala
// simple example of the cake pattern
// abstract DAO trait
trait Repository[A, B]{
// saves an entity, returns an ID
def save(entity: A): B
// more features..
}
trait RdbmsRepository extends Repository[MyUserCaseClass, Long]{
@wfaler
wfaler / ModelAndViewWTF.java
Created October 17, 2012 14:30
ModelAndViewWTF.java
// WTF's added by me, class cut down for brevity.
public class ModelAndView {
// WTF?!
/** View instance or view name String */
private Object view;
public ModelAndView(String viewName) {
this.view = viewName;
@wfaler
wfaler / gist:3778139
Created September 24, 2012 20:24 — forked from seanparsons/gist:3761731
Playing with lenses.
// Note this requires scalaz-core 7.0 added to the classpath.
import scalaz._
import Scalaz._
import Lens._
case class Address(street: String, country: String)
case class User(name: String, address: Address)
val address = Address("Monkey Street", "England")
val user = User("Sean", address)
@wfaler
wfaler / reassignment_to_new_val.scala
Created August 29, 2012 11:08
reassignment_to_new_val.scala
viewContent.map{content =>
val model = mergedModel.updated(template.contentPlaceHolder, content)
val content = render(template.name, model)
template.parent.map(layout => Scalate(layout, model, Some(content))).getOrElse(content)
}
@wfaler
wfaler / delegatingToTypeClassImplQuestion.scala
Created July 4, 2012 17:55
delegatingToTypeClassImplQuestion.scala
// Aim: Given a trait Client, I want to have one possible implementation that uses type classes to
//implement Clients abstract function, WITHOUT leaking through this fact to the Client traits API signature,
//as there are other, non- typeclass using impls.
trait Mapper[A]{
def map(s: String): A
}
object Mapper{
implicit object StringMapper extends Mapper[String]{
@wfaler
wfaler / option.clj
Created June 11, 2012 11:27
option in Clojure
(defn get-or-else [value default]
(if (nil? value)
(if (ifn? default)
(default)
default)
value))
(defn m-bind [value function]
(if (nil? value)
nil