Skip to content

Instantly share code, notes, and snippets.

Owain Lewis owainlewis

Block or report user

Report or block owainlewis

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@owainlewis
owainlewis / Either.md
Last active Aug 27, 2015
Scala Either
View Either.md

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 Jan 31, 2014
Installing golang
View Golang.md
mkdir $HOME/gopath
export GOPATH="$HOME/gopath"
export PATH="$GOPATH/bin:$PATH"
View api_prototype.rb
require 'sinatra'
require 'mongo'
require 'json/ext'
include Mongo
def connect!
begin
MongoClient.new("localhost", 27017)
rescue
View backbone.js
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) {
View polling.js
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 });
}
View unboxed.hs
module Data.Set.Unboxed (
-- * Set type
USet -- instance Eq,Ord,Show,Read,Data,Typeable
, US
, Boxed(Boxed)
-- * Operators
, (\\)
-- * Query
View friday.ml
(* ========================================================================= *)
(* 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 Mar 13, 2014
Fisher Yates shuffle for randomising javascript results on Fshionable
View fisher-yates.js
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;
}
View gist:9549117
# 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
You can’t perform that action at this time.