Skip to content

Instantly share code, notes, and snippets.

View dcorking's full-sized avatar

David Corking dcorking

View GitHub Profile
@maoueh
maoueh / Gemfile
Last active May 30, 2022 08:50
Simple Ruby files to statically serve files
source "https://rubygems.org"
gem 'rack', '~> 1.5'
gem 'rack-cache', '~> 1.2'
gem 'puma', '~> 2.7'
@korczis
korczis / rubocop-cops.txt
Created April 24, 2014 18:15
List of RuboCop cops
# Available cops (167) + config for /Users/tomaskorcak/dev/gooddata-ruby:
# Type 'Lint' (32):
AmbiguousOperator:
Description: Checks for ambiguous operators in the first argument of a method invocation
without parentheses.
Enabled: true
AmbiguousRegexpLiteral:
Description: Checks for ambiguous regexp literals in the first argument of a method
invocation without parenthesis.
@johnnymo87
johnnymo87 / gist:711e1d38e2e5707fda06
Created May 17, 2014 17:38
Finding fixed points
import math.abs
object finding_fixed_points {
val tolerance = 0.0001 //> tolerance : Double = 1.0E-4
def isCloseEnough(x: Double, y: Double) =
abs((x - y) / x) / x < tolerance //> isCloseEnough: (x: Double, y: Double)Boolean
def fixedPoint(f: Double => Double)(firstGuess: Double) = {
def iterate(guess: Double): Double = {
val next = f(guess)
if (isCloseEnough(guess, next)) next
@dcorking
dcorking / disk-usage.sh
Created June 26, 2014 13:54
Explore the apt cache in Debian
# this looks interesting
du --max-depth=1 -b -k /var/cache/apt | sort -k1 -rn
@lengarvey
lengarvey / staging.rb
Created June 29, 2014 11:28
Enabling Rails 4.1 mail previews in staging (or any other env besides development)
# put this in your staging.rb file. Obviously you'll need more config than this it's just an example.
Rails.application.configure do
config.action_mailer.preview_path ||= defined?(Rails.root) ? "#{Rails.root}/test/mailers/previews" : nil
config.autoload_paths += [config.action_mailer.preview_path]
routes.append do
get '/rails/mailers' => "rails/mailers#index"
get '/rails/mailers/*path' => "rails/mailers#preview"
end
@dcorking
dcorking / find_abuse.sh
Last active May 17, 2017 08:01
Notes on findutils
# This is not the official way to prune directories, but I found it easier.
# It prints the contents of all the files in the tree - excluding .git and CachedPixmaps,
# but there is a potential bug in the second globbed file name
#
# Works with GNU findutils. Might not work with BSD find, such as Mac OS X.
find -not -wholename './.git*' -not -wholename '*CachedPixmaps*' -type f |xargs cat
@dcorking
dcorking / typecasting.c
Created August 2, 2014 20:40
Typecasting int to char in printf() in C
#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
/* implements http://stackoverflow.com/questions/25079788/typecasting-int-to-char-in-printf-in-c */
/* by discussedtree */
/* Output is */
/* Int size in bits is: 32 */
/* Without typecasting, the integer at byte #0 is set to: 53200 */
@caike
caike / Dockerfile
Created September 29, 2014 21:54
Fixed version of the Dockerfile for the tutorial at https://docs.docker.com/examples/nodejs_web_app/
# DOCKER-VERSION 1.2.0
FROM centos:centos6
# Enable EPEL for Node.js
RUN rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
# Install Node.js and npm
RUN yum install -y npm
# Creates a new folder on the container
VOLUME /src

The thing that students have the hardest time on when learning functional programming is how to process a recursive structure while maintaining some sort of "state", the result if you will. I'll attempt here to demystify the process.

Functional programming languages almost always use a lot of recursively defined structures. Depending on the language those can be implemented in various ways, but in any case the end result is the same. A structure of this type is either an "atom", i.e. an irreducible thing, or a "compound" consisting of substructures of the same form.

For example a "list" is either an Empty/Nil list (the "atom") or it is formed as a Cons of a value and another list (compound form). That other "sublist" can itself be empty or another cons and so on and so forth. A tree is similar. It is either empty, or it consists of a triple of a value and two sub-trees, left and right.

Almost every problem we encounter is a question about doing something with all entries in a structure. To solve these prob

@steve-jansen
steve-jansen / export-zone.sh
Created December 15, 2014 19:11
Export DNS records from Rackspace Cloud DNS to zone files on disk
#!/bin/bash
# exports DNS records from Rackspace Cloud DNS to text files
# Depends on https://github.com/wichert/clouddns/blob/master/src/clouddns.py
set -e
me=export-zone
base_domain=
rackspace_region=
rackspace_rate_limit_delay=3