Skip to content

Instantly share code, notes, and snippets.

@ernie
ernie / delegate.rb
Last active May 31, 2016 10:39
An alternate take on the delegation class macro provided by ActiveSupport. Updated with Ruby 2.0's caller_locations.
#!/usr/bin/env ruby
class Module
private
def delegate(*args)
dest, prefix = _extract_valid_delegation_options(args.pop)
_define_delegators(caller_locations.first, prefix, dest, args)
end
@robotlolita
robotlolita / gist:7216015
Created October 29, 2013 14:46
Basically, every time the subject "correctness" comes up. Every. Single. Time. Damn, no wonder we have bugs everywhere.
<dmanderson> Oh Domo :)
<dmanderson> Nice templater
<Sorella> Oh.
<dmanderson> I've been using an underscore to JST compiler as of late, but
this looks really nice.
<Sorella> I don't quite like Domo, but sure.
<Sorella> Oh Lord, don't use Underscore's templating. Like,
really. Don't. Just. Don't.
<dmanderson> No I'm using JST
<dmanderson> writing the templates in underscore
@robotlolita
robotlolita / list.md
Last active December 26, 2015 08:59
PLT reading list yo~

Meta-Programming

  • Towards a fully-reflective meta-programming language (G. Neverov, P. Roe)
  • D-Expressions: Lisp Power, Dylan Style (J. Bachrach, K. Playford)
  • The Java Syntactic Extender (J. Bachrach, K. Playford)
  • Template Meta-Programming for Haskell (T. Sheard, S.P. Jones)
  • First-class macros have types (A. Bawden)
  • Macros that work (W. Clinger, J. Rees)
  • Macros as multi-stage computations: type-safe, generative, binding macros in MacroML (S.E. Ganz, A. Sabry, W. Taha)
  • Hygienic macro expansion (E. Kohlbecker, D. Friedman, M. felleisen, B. Duba)
require 'addressable/uri'
# Source: http://gist.github.com/bf4/5320847
# Accepts options[:message] and options[:allowed_protocols]
# spec/validators/uri_validator_spec.rb
class UriValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
uri = parse_uri(value)
if !uri
defmodule ApplicationRouter do
use Dynamo.Router
prepare do
# Pick which parts of the request you want to fetch
# You can comment the line below if you don't need
# any of them or move them to a forwarded router
conn.fetch([:cookies, :params])
end
#!/usr/bin/env ruby
gem "parser", "~> 1.4"
require "parser"
require "parser/ruby19"
require "set"
class ConstantDeclarationAndUseProcessor < Parser::AST::Processor
attr_reader :declared, :used
def initialize
@thoughtpolice
thoughtpolice / CoYoneda.hs
Last active December 27, 2019 01:52
CoYoneda = Yoneda
{-# LANGUAGE ExistentialQuantification, RankNTypes #-}
{-# LANGUAGE InstanceSigs #-}
module CoYoneda where
import Data.IORef
import Data.Set (Set, map)
import Control.Monad (liftM)
--------------------------------------------------------------------------------
-- Yoneda
@nuttycom
nuttycom / Functorial
Last active December 18, 2015 08:09
A hypothesis as to what functors, monads, etc. might look like if the value type were not universally quantified, but instead could be restricted by requirement for other typeclass instances. Universal quantification could still be achieved, of course; hence this provides a more flexible generalization of our familiar typeclasses. This grew out …
trait Functorial[F[_], B] {
def map[A](m: F[A])(f: A => B): F[B]
}
trait Monadic[M[_], B] extends Functorial[F, B] {
def point(b: B): M[B]
def flatMap[A](m: M[A])(f: A => M[B]): M[B]
}
trait Traversial[F[_], B] {
@tenderlove
tenderlove / terrible.rb
Last active May 16, 2020 13:13
I am a terrible person
require 'fiddle'
module IAmAHorriblePerson
def unset flag
value = _wrap self
flags = 8.times.map { |i| value[i] }.pack('C8').unpack('Q').first
[flags & ~flag].pack('Q').unpack('C8').each_with_index { |n,i|value[i] = n }
end
def class= k