Skip to content

Instantly share code, notes, and snippets.

View lopopolo's full-sized avatar

Ryan Lopopolo lopopolo

View GitHub Profile
@nzakas
nzakas / simplemap.js
Created April 3, 2014 17:38
A simple map implementation for JavaScript (not intended to be an ES6 polyfill)
function SimpleMap() {
this._data = {};
}
SimpleMap.prototype = {
get: function(key) {
return this.has(key) ? this._data[key] : null;
},
function! SuperTab()
if (strpart(getline('.'),col('.')-2,1)=~'^\W\?$')
return "\<Tab>"
else
return "\<C-n>"
endif
endfunction
function! SuperShiftTab()
if (strpart(getline('.'),col('.')-2,1)=~'^\W\?$')
return "\<S-Tab>"
@mrrooijen
mrrooijen / Vagrantfile.rb
Created November 25, 2012 18:57
Example of running multiple VM's using a single Vagrantfile.
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant::Config.run do |config|
config.vm.box = "base"
config.vm.customize ["modifyvm", :id, "--memory", 1024]
config.vm.define :haproxy do |haproxy|
haproxy.vm.forward_port 80, 8000
haproxy.vm.network :hostonly, "192.168.1.10"
@vmarquez
vmarquez / Polymorphism.scala
Last active December 23, 2015 09:49
Two implementations of a Design by Contract Cache interface. Parametric Polymorphism is more flexible than subtype polymorphism.
case class GenericCache[A[_,_], B, C](instance: A[B,C], getf: B=>C, putf: (B,C)=>Unit) {
def retrieve(b: B) = getf(b)
def insert(b: B, c: C) = putf(b,c)
}
//Notice how neither cache implementations have to even be aware of the existnace of the typeclass. much more flexible than inheritance
class FastCache[A,B] {
private var m = Map[A,B]() //excuse mutability for illustration purposes
def add(a: A, b: B): Unit = {
m = m + (a->b)
@hynek
hynek / Example Usage
Last active November 26, 2016 19:10
PoC of using attrs’s upcoming metadata feature for using declarative application configuration from env variables including envconsul’s HashiCorp Vault support.
$ env APP_ENV=dev APP_PROMETHEUS_PORT=7000 SECRET_WHOIS_DEV_APP_PROMETHEUS_CONSUL_TOKEN=abc python app.py
WhoisConfig(env='dev', prometheus=Prometheus(address='127.0.0.1', port='7000', consul_token='abc'))
@stew
stew / fizzbuzz.scala
Created November 14, 2012 20:55
fizzbuzz in the scala type system
package fizzbuzz
// This is church encoding of natural numbers
sealed trait Num {
def toInt : Int
override def toString = toInt.toString
}
final case object Z extends Num {
def toInt : Int = 0
@bcantrill
bcantrill / ub.c
Created January 11, 2019 18:41
Punishment doesn't fit the crime?
#define NULL ((void *)0)
static char *arr[2] = { "nasal", "demons" };
long
func()
{
int i;
for (i = 0; i <= 2; i++) {
@fnichol
fnichol / README.md
Last active August 17, 2020 14:41
A Windows/Linux/macOS PowerShell Rustup Install Script

A Windows/Linux/macOS PowerShell Rustup Install Script

On Windows, run

& ([scriptblock]::Create((New-Object System.Net.WebClient).DownloadString('https://gist.github.com/fnichol/699d3c2930649a9932f71bab8a315b31/raw/rustup-init.ps1')))

in a PowerShell session. This downloads and runs rustup-init.ps1, which in turn downloads and runs the correct version of the rustup-init executable on

@zargony
zargony / config.yml
Last active December 16, 2020 16:47
CircleCI 2.0 configuration for Rust library crate project
version: 2
jobs:
test:
docker:
- image: rust:1
steps:
- checkout
- run:
name: Version information
@detunized
detunized / globals.rb
Created January 16, 2012 12:24
List global Ruby variables and their values
global_variables.sort.each do |name|
puts "#{name}: #{eval "#{name}.inspect"}"
end