Skip to content

Instantly share code, notes, and snippets.

Basics:
-ctrl a c -> create new window
-ctrl a A -> set window name
-ctrl a w -> show all window
-ctrl a 1|2|3|… -> switch to window n
-ctrl a " -> choose window
-ctrl a ctrl a -> switch between window
-ctrl a d -> detach window
-ctrl a ? -> help
@simonmichael
simonmichael / gist:1185421
Created September 1, 2011 03:59
ghc-pkg-clean, ghc-pkg-reset
# unregister broken GHC packages. Run this a few times to resolve dependency rot in installed packages.
# ghc-pkg-clean -f cabal/dev/packages*.conf also works.
function ghc-pkg-clean() {
for p in `ghc-pkg check $* 2>&1 | grep problems | awk '{print $6}' | sed -e 's/:$//'`
do
echo unregistering $p; ghc-pkg $* unregister $p
done
}
# remove all installed GHC/cabal packages, leaving ~/.cabal binaries and docs in place.
@etorreborre
etorreborre / gist:2231981
Created March 29, 2012 00:55
Using Scalaz to get the applicative syntax for ScalaCheck generators
import scalaz.Apply
import org.scalacheck.Gen
import org.scalacheck.Arbitrary._
/**
* Use this trait to get applicative syntax when building generators. This
* is especially useful when building generators for case classes.
*
*/
trait Data {
@jboner
jboner / latency.txt
Last active July 21, 2024 15:49
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
@earthgecko
earthgecko / bash.generate.random.alphanumeric.string.sh
Last active July 4, 2024 17:31
shell/bash generate random alphanumeric string
#!/bin/bash
# bash generate random alphanumeric string
#
# bash generate random 32 character alphanumeric string (upper and lowercase) and
NEW_UUID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
# bash generate random 32 character alphanumeric string (lowercase only)
cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 32 | head -n 1
@jgoosey
jgoosey / quine.hs
Last active August 12, 2020 17:22
Quine in Haskell, two implementations
--Haskell Quine
--Implementation 1
import Control.Monad
import Control.Monad.Instances
main = (putStr . ap (++) show)
"--Haskell Quine\n--Implementation 1\nimport Control.Monad\nimport Control.Monad.Instances\nmain = (putStr . ap (++) show) "
--Implementation 2
--main = putStrLn (s ++ show s) where s =
-- "--Haskell Quine\n--Implementation 2\nmain = putStrLn (s ++ show s) where s ="
@cheecheeo
cheecheeo / MonoidFun.hs
Created November 26, 2013 03:37
Somebody said that lists are the "free monoid" in Haskell
module MonoidFun where
-----------------------------------------------------------------------------
-- |
-- Inspirition from: http://stackoverflow.com/a/13357359/1019205 lists are
-- the "free monoid" and http://hackage.haskell.org/package/newtype
import Data.Monoid
import Data.Foldable
import Control.Newtype
@jwreagor
jwreagor / EmacsKeyBinding.dict
Created March 20, 2014 18:41
Global Emacs Key Bindings for OS X
{
/* Keybindings for emacs emulation. Compiled by Jacob Rus.
*
* This is a pretty good set, especially considering that many emacs bindings
* such as C-o, C-a, C-e, C-k, C-y, C-v, C-f, C-b, C-p, C-n, C-t, and
* perhaps a few more, are already built into the system.
*
* BEWARE:
* This file uses the Option key as a meta key. This has the side-effect
* of overriding Mac OS keybindings for the option key, which generally
@goldobin
goldobin / ByteStringConverters.scala
Last active November 6, 2017 08:06
Converters for UUID and String to ByteString for Scala
object ByteStringConverters {
implicit val DefaultByteOrder = ByteOrder.BIG_ENDIAN
implicit class UUIDWithToByteString(uuid: UUID) {
def toByteString = ByteString(
ByteBuffer
.allocate(16)
.putLong(uuid.getMostSignificantBits)
.putLong(8, uuid.getLeastSignificantBits)
)
@jkpl
jkpl / Main.scala
Last active February 5, 2024 08:29
Ways to pattern match generic types in Scala
object Main extends App {
AvoidLosingGenericType.run()
AvoidMatchingOnGenericTypeParams.run()
TypeableExample.run()
TypeTagExample.run()
}
class Funky[A, B](val foo: A, val bar: B) {
override def toString: String = s"Funky($foo, $bar)"
}