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 / 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
owainlewis / .gitignore
Created Jun 27, 2014
Scala gitignore
View .gitignore
*.class
*.log
# sbt specific
.cache/
.history/
.lib/
dist/*
target/
lib_managed/
View Gzip.scala
import java.io.{ByteArrayOutputStream, ByteArrayInputStream}
import java.util.zip.{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
where
-- 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 )
View setup.sh
#!/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
cd
git clone git://github.com/sstephenson/rbenv.git .rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bash_profile
@owainlewis
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 (user.email 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
owainlewis / docker-proxy.md
Created Mar 24, 2017
Set docker proxy on Ubuntu 16.04
View docker-proxy.md

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
metadata:
name: web
spec:
serviceName: "nginx"
replicas: 2
selector:
matchLabels:
app: nginx
@owainlewis
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 = active_record_model.column_names.map{ |f| m.send f.to_sym }
csv << values
end
end
You can’t perform that action at this time.