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 / PropertyBuilder.scala
Created May 1, 2015
Scala map to Java properties
View PropertyBuilder.scala
import java.util.Properties
object PropertyBuilder {
* Build a java Properties instance from a Scala Map
* @param properties An immutable map of properties
def buildFromMap(properties: Map[String, String]) =
View lambda.sml
(**** ML Programs from Chapter 9 of
ML for the Working Programmer, 2nd edition
by Lawrence C. Paulson, Computer Laboratory, University of Cambridge.
(Cambridge University Press, 1996)
Copyright (C) 1996 by Cambridge University Press.
Permission to copy without fee is granted provided that this copyright
notice and the DISCLAIMER OF WARRANTY are included in any copy.
owainlewis / .gitignore
Created Jun 27, 2014
Scala gitignore
View .gitignore
# sbt specific
View Gzip.scala
import{ByteArrayOutputStream, ByteArrayInputStream}
import{GZIPOutputStream, GZIPInputStream}
import scala.util.Try
object Gzip {
def compress(input: Array[Byte]): Array[Byte] = {
val bos = new ByteArrayOutputStream(input.length)
val gzip = new GZIPOutputStream(bos)
View binaryTrees.hs
module BinaryTree
-- Haskell Binary Tree Examples
-- A binary tree can either be empty or a node with a left and right branch
data Tree a = EmptyTree | Node a (Tree a) (Tree a)
deriving ( Show, Read, Eq )
#!/usr/bin/env bash
sudo yum install -y git-core zlib zlib-devel gcc-c++ patch readline readline-devel libyaml-devel libffi-devel openssl-devel make bzip2 autoconf automake libtool bison curl sqlite-devel
git clone git:// .rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
git clone git:// ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bash_profile
owainlewis / Either.scala
Last active Jul 7, 2019
Validation examples
View Either.scala
object EitherValidationExamples {
type ValidationError = String
def validateEmail(user: User): Either[ValidationError, User] =
if ( contains "@") Right(user) else Left("Must supply a valid email")
def validateAge(user: User): Either[ValidationError, User] =
if (user.age > 18) Right(user) else Left("Must be over 18")
owainlewis /
Created Mar 24, 2017
Set docker proxy on Ubuntu 16.04

How to setup docker behing a HTTP proxy

mkdir /etc/systemd/system/docker.service.d

sudo touch /etc/systemd/system/docker.service.d/http-proxy.conf

Add proxy info

View ss.yaml
apiVersion: apps/v1
kind: StatefulSet
name: web
serviceName: "nginx"
replicas: 2
app: nginx
owainlewis / model_to_csv.rb
Created Jul 2, 2012
Export Rails model to CSV
View model_to_csv.rb
# Export Active Record model as a CSV file
def self.render_csv active_record_model
CSV.generate do |csv|
csv << active_record_model.column_names
active_record_model.all.each do |m|
values ={ |f| m.send f.to_sym }
csv << values
You can’t perform that action at this time.