Skip to content

Instantly share code, notes, and snippets.

View lopopolo's full-sized avatar

Ryan Lopopolo lopopolo

View GitHub Profile
@todgru
todgru / ssh-tunnel.md
Last active May 6, 2023 15:32
How to set-up a SSH tunnel for AWS RDS

SSH Tunnel

Our db is hosted on Amazon. Our web server can connect to the db. Connections to the db are not allowed outside of the web server.

Run ssh tunnel locally:

This creates a tunnel from my local machine to the web server:

ssh -N -L 3307:my-rds-db.us-east-1.rds.amazonaws.com:3306 ec2-my-web-server.compute-1.amazonaws.com
@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)
@hubgit
hubgit / README.md
Last active May 27, 2024 03:48
Remove metadata from a PDF file, using exiftool and qpdf. Note that embedded objects may still contain metadata.

Anonymising PDFs

PDF metadata

Metadata in PDF files can be stored in at least two places:

  • the Info Dictionary, a limited set of key/value pairs
  • XMP packets, which contain RDF statements expressed as XML

PDF files

@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"
@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
@cespare
cespare / log.go
Created October 31, 2012 06:51
Golang apache logging
type ApacheLogRecord struct {
http.ResponseWriter
ip string
time time.Time
method, uri, protocol string
status int
responseBytes int64
elapsedTime time.Duration
}
@unak
unak / history.txt
Last active November 29, 2021 01:40
The History of Ruby
* Only the releases of the stable versions are listed in principle. The releases of the unstable versions especially considered to be important are indicated as "not stable."
* The branches used as the source of each releases are specified, and the branching timing of them are also shown. BTW, before subversionizing of the repository, the term called "trunk" was not used, but this list uses it in order to avoid confusion.
* In order to show a historical backdrop, big conferences (RubyKaigi, RubyConf and Euruko) are also listed. About the venues of such conferences, general English notations are adopted, in my hope.
* ruby_1_8_7 branch was recut from v1_8_7 tag after the 1.8.7 release because of an accident.
* 1.2.1 release was canceled once, and the 2nd release called "repack" was performed. Although there were other examples similar to this, since the re-releases were performed during the same day, it does not write clearly in particular.
* Since 1.0 was released with the date in large quantities, the mi
@jboner
jboner / latency.txt
Last active June 7, 2024 11:40
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
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>"
@Abizern
Abizern / NSData+Base64.h
Created January 19, 2012 22:52
A category on NSData for coding and encoding Base64
//
// NSData+Base64.h
// base64
//
// Created by Matt Gallagher on 2009/06/03.
// Copyright 2009 Matt Gallagher. All rights reserved.
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software. Permission is granted to anyone to