Skip to content

Instantly share code, notes, and snippets.

View owainlewis's full-sized avatar

Owain Lewis owainlewis

View GitHub Profile
@owainlewis
owainlewis / Either.md
Last active August 27, 2015 14:45
Scala Either

Working with Either

There are two ways to work with Either in Scala.

If you want to update only one side use a projection and map

response.right.map(_.parseJson.convertTo[Seq[String]])
@owainlewis
owainlewis / Golang.md
Created January 31, 2014 13:59
Installing golang
mkdir $HOME/gopath
export GOPATH="$HOME/gopath"
export PATH="$GOPATH/bin:$PATH"
require 'sinatra'
require 'mongo'
require 'json/ext'
include Mongo
def connect!
begin
MongoClient.new("localhost", 27017)
rescue
@owainlewis
owainlewis / result.clj
Last active August 29, 2015 13:56
Sitecore job parser
//
var ChannelView = Backbone.View.extend({
initialize: function() {
this.channel = new Channel({id: this.id});
this.channel.events.fetch().done(_.bind(function(){
this.render();
}, this));
},
render: function() {
this.channel.events.forEach(function(e) {
App.prototype = {
poll: function(endpoint){
$.ajax({ url: endpoint, success: function(data){
console.log(data);
}, dataType: "json", complete: _.bind(function() {
setTimeout(_.bind(function() {
this.poll(endpoint)
}, this), this.pollingFrequency);
}, this), timeout: 3000 });
}
module Data.Set.Unboxed (
-- * Set type
USet -- instance Eq,Ord,Show,Read,Data,Typeable
, US
, Boxed(Boxed)
-- * Operators
, (\\)
-- * Query
(* ========================================================================= *)
(* Misc library functions to set up a nice environment. *)
(* ========================================================================= *)
let identity x = x;;
let ( ** ) = fun f g x -> f(g x);;
(* ------------------------------------------------------------------------- *)
(* GCD and LCM on arbitrary-precision numbers. *)
@owainlewis
owainlewis / fisher-yates.js
Created March 13, 2014 16:11
Fisher Yates shuffle for randomising javascript results on Fshionable
function fisherYates(array) {
for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = array[i];
array[i] = array[j];
array[j] = temp;
}
return array;
}
# Setup our folder structure
cd /var
sudo mkdir -p fshionable
sudo mkdir -p fshionable/site.git
cd /var/fshionable/site.git
# Create a bare git repo to receive our push
git init --bare