Skip to content

Instantly share code, notes, and snippets.

@john-kurkowski
john-kurkowski / StreamOuter.scala
Created August 15, 2011 17:41
Scala closures capture outer variables, which can lead to unhappy serialization when you don't expect a lazy data structure under the covers. The lesson is, for serialization, favor strict, concrete types.
class A
class B extends Serializable
val baos = new java.io.ByteArrayOutputStream(1024)
val oos = new java.io.ObjectOutputStream(baos)
val streamSurprise: Seq[A] = Stream.fill(3)(new A) // say you don't know it's a Stream under the covers
val transformation = streamSurprise map (a => new B)
oos.writeObject(transformation) // fails due to NotSerializableException: A
@milessabin
milessabin / gist:1705644
Created January 30, 2012 17:47
Access to companion object of Foo via implicit resolution
trait Companion[T] {
type C
def apply() : C
}
object Companion {
implicit def companion[T](implicit comp : Companion[T]) = comp()
}
object TestCompanion {
@rampion
rampion / RedBlackTree.hs
Created May 11, 2012 13:55
red-black trees in haskell, using GADTs and Zippers
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE StandaloneDeriving #-}
module RedBlackTree where
data Zero
data Succ n
type One = Succ Zero
data Black
@ryin
ryin / tmux_local_install.sh
Last active May 27, 2025 08:36
bash script for installing tmux without root access
#!/bin/bash
# Script for installing tmux on systems where you don't have root access.
# tmux will be installed in $HOME/local/bin.
# It's assumed that wget and a C/C++ compiler are installed.
# exit on error
set -e
TMUX_VERSION=1.8
@loicdescotte
loicdescotte / Forcomptran.md
Last active November 12, 2025 15:54
Scala for comprehension translation helper

Scala for comprehension translation helper

"For comprehension" is a another syntaxe to use map, flatMap and withFilter (or filter) methods.

yield keyword is used to aggregate values in the resulting structure.

This composition can be used on any type implementing this methods, like List, Option, Try, Future...

@claudiosanches
claudiosanches / django-runserver-ssl.md
Last active August 10, 2024 06:42
Django - SSL with runserver

Instalation

[sudo] apt-get install stunnel

Configuration

cd path/to/django/project
@vaskoz
vaskoz / builder.go
Last active January 22, 2024 10:54
Golang Builder pattern
package main
import "strconv"
import "fmt"
type Color string
type Make string
type Model string
const (
@takeshixx
takeshixx / hb-test.py
Last active September 8, 2025 01:16
OpenSSL heartbeat PoC with STARTTLS support.
#!/usr/bin/env python2
"""
Author: takeshix <[email protected]>
PoC code for CVE-2014-0160. Original PoC by Jared Stafford ([email protected]).
Supportes all versions of TLS and has STARTTLS support for SMTP,POP3,IMAP,FTP and XMPP.
"""
import sys,struct,socket
from argparse import ArgumentParser
@zenoamaro
zenoamaro / hst.py
Last active May 16, 2017 13:14 — forked from takeshixx/hb-test.py
Testing tool for analysis of Heartbleed vulnerability (CVE-2014-0160).
#!/usr/bin/env python2
# Heart-shaped tool
# =================
# Testing tool in demonstration of CVE-2014-0160.
# Heavily derived from code by Jared Stafford ([email protected]).
# This version by: @zenoamaro, <zenoamaro at gmail dot com>
# Hits the Heartbleed vulnerability on a hostname.
@staltz
staltz / introrx.md
Last active December 1, 2025 11:31
The introduction to Reactive Programming you've been missing