Skip to content

Instantly share code, notes, and snippets.

@propensive
propensive / proxies.scala
Created January 25, 2015 10:51
"Proxies" with implicits and singleton types
package proxy
import language.dynamics
abstract class Param[T] { type Type }
object Param {
def apply[T](name: String) = new Param[name.type] { type Type = T }
}
class Proxy(underlying: Map[String, Any]) extends Dynamic {
@paf31
paf31 / 24days.md
Last active August 8, 2023 05:53
24 Days of PureScript

This blog post series has moved here.

You might also be interested in the 2016 version.

@pfultz2
pfultz2 / state_monad.cpp
Created November 11, 2014 01:29
State monad implemented in C++14
#include <utility>
#include <iostream>
struct void_
{
template<typename Stream>
friend Stream &operator<<(Stream &s, void_)
{
return s << "()";
}
@chrisdone
chrisdone / AnIntro.md
Last active October 29, 2024 15:34
Statically Typed Lisp

Basic unit type:

λ> replTy "()"
() :: ()

Basic functions:

@nkpart
nkpart / Yolo.hs
Last active September 5, 2018 13:50
{-# LANGUAGE GADTs #-}
module Yolo where
import System.IO.Unsafe
class Yolo f where
yolo :: f a -> a
instance Yolo Maybe where
yolo (Just x) = x
@vendethiel
vendethiel / initializer_QueryTrace.rb
Created July 28, 2014 13:20
QueryTrace. Credit @ somebody on SO!
module QueryTrace
def self.enable!
::ActiveRecord::LogSubscriber.send(:include, self)
end
def self.append_features(klass)
super
klass.class_eval do
unless method_defined?(:log_info_without_trace)
alias_method :log_info_without_trace, :sql
@masak
masak / groups.p6
Last active August 29, 2015 14:04
Some fun with cyclic groups, direct products, and isomorphism
role Group {
method elements { ... }
method id { ... }
method op($l, $r) { ... }
}
macro assert($fact) {
quasi {
die "FAILED: ", $fact.Str
unless {{{$fact}}};
@vendethiel
vendethiel / Any.cpp
Last active August 29, 2015 14:03
Any.cpp
#include <utility>
#include <vector>
#include <iostream>
#define ANY_OP(T, OP) bool operator OP(T el) { \
for (const auto& elem : _elems) { \
if (elem OP el) return true; \
} \
return false; \
}
@vendethiel
vendethiel / ability_test.rb
Last active August 29, 2015 14:01
Ruby's metaprogramming. I love it.
require 'test_helper'
class AbilityTest < ActiveSupport::TestCase
def setup
super
@ability_t = Ability.new(users(:translator_my))
@ability_m = Ability.new(users(:manager_my))
@ability_a = Ability.new(users(:admin_my))
@proj1 = projects(:proj1)
@moritz
moritz / call-positional-by-name.pl
Created May 18, 2014 13:57
Fill positional arguments by name (Perl 6)
use v6;
sub t ($x, $y, :$label = 'sum') {
say "$label: ", $x + $y;
}
sub namecall(&c, *@pos, *%named is rw) {
my %name-to-idx;
for &c.signature.params.kv -> $idx, $p {
next if $p.named;