Skip to content

Instantly share code, notes, and snippets.

subset File of Str of *.IO.e;
enum Color «:BUG(37) :TODO(36) :FIXME(33) :XXX(31)»;
sub color(Color $c, Str $msg) {
"\033[$cm$msg\033[0m";
}
sub process(File $file) {
gather for $file.lines.kv -> $i, $l {
take " $i: {Color::{$0}, $_)};" when /<|b>(BUG|TODO|FIXME|XXX)<|b>/;
import @ from "contracts.js";
macro fun {
rule {
$name:ident ($contract ...) { $body ... }
} => {
@ $contract ...
function $name () {
return (function {
$body ...
@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
@vendethiel
vendethiel / ruby.rb
Last active February 21, 2024 11:11
class RecordAddress
FIELDS = [:number, :country, :city_zip, :city_name, :street_name,
:latitude, :longitude, :geocoding_failed, :place_id]
BOOLEANS = [:geocoding_failed]
ASSOCIATIONS = [:place]
# @param [Object] object
# @param [Array] ary
def initialize(object, col)
@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)
macro $do {
rule {($($x = $y) (,) ...) $body} => {
(function ($x (,) ...) $body)($y (,) ...)
}
rule {$name ($($x = $y) (,) ...) $body} => {
(function $name ($x (,) ...) $body)($y (,) ...)
}
}
macro $var {
macro null_helper {
rule {($processed ...) ($rest)} => {
$processed (.) ... . $rest
}
rule {($processed ...) ($rest_head $rest ...)} => {
$processed (.) ... . $rest_head
&& null_helper ($processed ... $rest_head) ($rest ...)
}
}
// y-combinator
macro $y {
rule {( $var )} => {
function(){
return function (f){
return f(f)
}(function(f){
return $var(function(x){
return f(f)(x);
})
macro to_string {
case $x => { (JSON.stringify({ $x: 0 }).slice(2, -4)) }
}
macro enum {
case [ $val:ident (,) ... ] => {
(function () {
var e = {
$( $val : (to_string $val) ) (,) ...
};