Skip to content

Instantly share code, notes, and snippets.

View axelarge's full-sized avatar

Miķelis Vindavs axelarge

View GitHub Profile
@jonsterling
jonsterling / .gitignore
Created May 14, 2011 22:57
The Type Class Idiom in Haskell, Scala, C++, and Objective-C
*.class
*.swp
@andkerosine
andkerosine / raskell.rb
Created August 15, 2012 05:56
Haskell-like list comprehensions in Ruby
$stack, $draws = [], {}
def method_missing *args
return if args[0][/^to_/]
$stack << args.map { |a| a or $stack.pop }
$draws[$stack.pop(2)[0][0]] = args[1] if args[0] == :<
end
class Array
def +@
@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active July 22, 2024 23:19
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@paulp
paulp / The Signs of Soundness
Last active June 17, 2021 06:48
The Signs of Soundness
Hello scala, my old friend
I've come to take you home again
Because a feature slowly creeping
left me plagued with doubts and weeping
and the version that was tagged in the repo
just has to go
it lacks the signs of soundness
On sleepless nights I hacked alone
applying ant and other tools of stone
@alandipert
alandipert / maptemplate.md
Created January 30, 2013 00:28
ClojureScript macros: kinda, sorta, not really.

ClojureScript macros: kinda, sorta, not really.

ClojureScript does not have a standalone macro system. To write ClojureScript macros, one must write them in Clojure and then refer to them in ClojureScript code. This situation is workable, but at a minimum it forces one to keep ClojureScript code and the macros it invokes in separate files. I miss the locality of regular Clojure macros, so I wrote something called maptemplate that gives me back some of what I miss. The technique may be useful in other scenarios.

Problem

Suppose you're wrapping functionality in another namespace or package so that you can have your own namespace of identically named but otherwise decorated functions:

ClojureScript:

@viktorklang
viktorklang / NonblockingCache.scala
Last active December 11, 2015 23:38
Nonblocking cache
/*©2013 Viktor Klang*/
package akka.util
import java.util.concurrent.atomic.AtomicReference
import scala.concurrent.{ Future, ExecutionContext }
import scala.annotation.tailrec
class Cache[K, V](__ec: ExecutionContext, throughput: Int) extends AtomicReference[Map[K, V]] {
implicit val executor = SerializedSuspendableExecutionContext(throughput)(__ec)
@tailrec final def update(f: Map[K, V] ⇒ Map[K, V]): Map[K, V] = {
val v = get
val nv = f(v)
/**
* Several macros simplifying use of weak references to self inside blocks
* which goal is to reduce risk of retain cycles.
*
* Example:
* @code
@interface Example : NSObject{
int _i;
}
@NZKoz
NZKoz / apologies.text
Last active February 22, 2022 16:01
Template password compromise documentation
Dear [First Name],
We're really sorry but our systems were compromised and the attackers managed to take a copy
of your passwords.
The passwords were stored as:
[ ] Bcrypt hashes with a cost factor of X
[ ] PBKDF2 hashes with an iteration count of X
[ ] scrypt because I am Colin Percival
@debasishg
debasishg / gist:5567328
Created May 13, 2013 10:08
regex interpolation fails ..
Apples-MacBook-Pro:~ debasishg$ scala
Welcome to Scala version 2.10.0 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_45).
Type in expressions to have them evaluated.
Type :help for more information.
scala> :paste
// Entering paste mode (ctrl-D to finish)
implicit class RContext(sc: StringContext) {
def r =
@mergeconflict
mergeconflict / Inject.scala
Created May 28, 2013 18:16
"dependency injection" monad (for the lulz)
case class Inject[-E, +A](inject: E => A) {
// covariant functor and monad
def map[B](f: A => B): Inject[E, B] =
Inject { e => f(inject(e)) }
def flatMap[ε <: E, B](f: A => Inject[ε, B]): Inject[ε, B] =
Inject { e => f(inject(e)).inject(e) }
// to satisfy for-comprehension desugaring in scala < 2.10
def filter(f: A => Boolean): Inject[E, A] =