Skip to content

Instantly share code, notes, and snippets.

@vendethiel
vendethiel / gist:02b7fc9684c67b786ed8
Created May 23, 2015 10:09
debugger::ui::commandline
Unhandled exception: ctxlexpad needs an MVMContext
at src/gen/m-CORE.setting:13040 (./perl6/rakudo/install/share/perl6/runtime/CORE.setting.moarvm::33)
from src/gen/m-CORE.setting:13151 (./perl6/rakudo/install/share/perl6/runtime/CORE.setting.moarvm:AT-KEY:95)
from src/gen/m-CORE.setting:3756 (./perl6/rakudo/install/share/perl6/runtime/CORE.setting.moarvm:postcircumfix:<{ }>:30)
from lib/Debugger/UI/CommandLine.pm:735 (./perl6/rakudo/install/share/perl6/site/lib/Debugger/UI/CommandLine.pm.moarvm::82)
from src/gen/m-CORE.setting:10092 (./perl6/rakudo/install/share/perl6/runtime/CORE.setting.moarvm::558)
from src/gen/m-CORE.setting:10015 (./perl6/rakudo/install/share/perl6/runtime/CORE.setting.moarvm:reify:58)
from src/gen/m-CORE.setting:9931 (./perl6/rakudo/install/share/perl6/runtime/CORE.setting.moarvm::95)
from src/gen/m-CORE.setting:9927 (./perl6/rakudo/install/share/perl6/runtime/CORE.setting.moarvm::229)
from src/gen/m-CORE.setting:9901 (./perl6/rakudo/install/share/perl6/runtime/CORE
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);
})