Skip to content

Instantly share code, notes, and snippets.

View aserrallerios's full-sized avatar
🐦
Working or IDK

Albert Serrallé Ríos aserrallerios

🐦
Working or IDK
View GitHub Profile
@viktorklang
viktorklang / ScalaEnum.scala
Created June 30, 2011 23:12
DIY Scala Enums (with optional exhaustiveness checking)
trait Enum { //DIY enum type
import java.util.concurrent.atomic.AtomicReference //Concurrency paranoia
type EnumVal <: Value //This is a type that needs to be found in the implementing class
private val _values = new AtomicReference(Vector[EnumVal]()) //Stores our enum values
//Adds an EnumVal to our storage, uses CCAS to make sure it's thread safe, returns the ordinal
private final def addEnumVal(newVal: EnumVal): Int = { import _values.{get, compareAndSet => CAS}
val oldVec = get
@pchiusano
pchiusano / GADTs.scala
Created November 16, 2011 04:30
GADT support in Scala
/** GADTs in Scala and their limitations */
/** Background: what is an algebraic data type (ADT) ?
* ADT: (possibly) recursive datatype with sums and products
* In scala - a trait with case classes (case class is product, subtyping is sum)
*/
/** Motivation: untyped embedded DSL doesn't prevent nonsensical expressions */
sealed trait Expr {
def apply(other: Expr) = Ap(this, other)
@jboner
jboner / latency.txt
Last active May 13, 2024 12:48
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
@MohamedAlaa
MohamedAlaa / tmux-cheatsheet.markdown
Last active May 11, 2024 07:10
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@earthgecko
earthgecko / bash.generate.random.alphanumeric.string.sh
Last active April 2, 2024 15:59
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
@copumpkin
copumpkin / Primes.agda
Last active May 6, 2020 23:08
Primes
module Primes where
open import Level using (_⊔_)
open import Coinduction
open import Function
open import Data.Empty
open import Data.Unit
open import Data.Nat
open import Data.Nat.Properties
open import Data.Nat.Divisibility
anonymous
anonymous / Haskell
Created October 7, 2013 19:22
Comparison of the straightforward embedding of a basic tenet of category theory in Scala vs Haskell.
yonedaLemma = Iso (flip fmap) ($ id)
@ssedano
ssedano / omshell_example
Created October 25, 2013 14:39
omshell example
new host
set name = "b"
set hardware-address = f0:4d:a2:fd:2d:74
set ip-address = 20:02:ca:fe:00:00:00:00:00:00:00:00:00:00:00:07,20:02:ca:fe:00:00:00:00:00:00:00:00:00:00:00:08
set hardware-type = 1
set statements = "option dhcp6.vendor-opts 6f:70:74:69:6f:6e;"
create
@thomasdarimont
thomasdarimont / AnnotationMixin.java
Created October 29, 2013 17:11
Prototype of @AnnotationMixing Feature for ProjectLombok
package lombok.experimental;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.ANNOTATION_TYPE)
@Retention(RetentionPolicy.SOURCE)
public @interface AnnotationMixin {
@thomasdarimont
thomasdarimont / LambdaPi.java
Last active December 27, 2015 15:59
Approximate PI in almost one line with Lambdas in Java 8 :) - Theory here: http://www.stealthcopter.com/blog/2009/09/python-calculating-pi-using-random-numbers/
package de.tutorials.training.java8.lambda;
import java.util.stream.IntStream;
import static java.lang.Math.*;
import static java.util.concurrent.ThreadLocalRandom.*;
/**
* Author: Thomas Darimont
*/