Skip to content

Instantly share code, notes, and snippets.

View bcardiff's full-sized avatar
🏝️
I should be slow to respond.

Brian J. Cardiff bcardiff

🏝️
I should be slow to respond.
View GitHub Profile
@bcardiff
bcardiff / tests.cpp
Created September 19, 2012 19:44
tp0 test
#include "anillo.h"
#include "aed2_tests.h"
template<typename T>
string to_s(const Anillo<T>* a) {
ostringstream os;
os << *a;
return os.str();
}
@bcardiff
bcardiff / aed2_tests.h
Created November 28, 2012 19:07
tp3 test
#ifndef AED2_TESTS_
#define AED2_TESTS_
#include <iostream>
#include <sstream>
using namespace std;
string mt_bool_to_s(bool b) { return b ? "true" : "false"; }
#define MT_MAKE_ERROR(lhs, rhs, line) { ostringstream os;os << "error en linea " << (line) << endl;os << " se esperaba: " << (rhs) << endl;os << " se obtuvo: " << (lhs);throw os.str(); }
void mt_assert(bool lhs, bool rhs, int line) { if (lhs != rhs) { MT_MAKE_ERROR(mt_bool_to_s(lhs), mt_bool_to_s(rhs), line) } }
@bcardiff
bcardiff / svg.rb
Created January 11, 2013 17:17
SVG Generator spike with same RVG API from RMagick. (output svg xml only)
require 'rexml/document'
class SVG
def initialize(width, height)
@doc = REXML::Document.new
@doc << REXML::XMLDecl.new
@svg = @doc.add_element 'svg'
@svg.add_attribute 'xmlns', 'http://www.w3.org/2000/svg'
@svg.add_attribute 'width', width
@bcardiff
bcardiff / scoped_cache.rb
Created March 7, 2013 16:07
Rails Scoped Cache allows seamless usage of cache island that can be deleted at once. Also default expiration could be achieved by cache options. Further reference: http://quickleft.com/blog/faking-regex-based-cache-keys-in-rails
class ScopedCache
attr_reader :name
def initialize(cache, name, options = nil)
@cache = cache
@name = name
@options = options
end
def read(key)
@bcardiff
bcardiff / mini_test.cpp
Created March 18, 2013 01:38
mini test header framework for C++
#ifndef MINI_TEST
#define MINI_TEST
/*
Mini Test for C++
author: Brian J. Cardiff
1. Create simple test cases.
@bcardiff
bcardiff / README.rdoc
Created July 17, 2013 15:09
Render views as angular text/ng-template in rails

Usage

1) Drop views and partials anywhere in app/views

|-- app
|   `-- views
|       `-- shared
|           `-- angular_views
|               |-- foo
|               |   `-- view3.html.haml
@bcardiff
bcardiff / base.cr
Created June 18, 2014 20:36
file system abstraction for crystal
macro collect_alias_method(method, type)
def {{method}}
res = [] of {{type}}
{{method}} do |e|
res << e
end
res
end
end
@bcardiff
bcardiff / todos.rb
Last active August 29, 2015 14:14
List of TODOs in ./app/ decorated with blame sorted by time git grep blame
require 'date'
target = ARGV[1] || "."
files = %x(git grep -n 'TODO*' #{target})
lines = []
length_author = 0
length_file = 0
@bcardiff
bcardiff / README.md
Last active November 21, 2017 16:39
wkhtmltopdf binding for crystal

Experiment for wkhtmltopdf

brew install wkhtmltopdf
crystal wkhtmltopdf.cr

known issue: althout conversion succeeds the wkhtmltopdf process seems to hanging in the very end :-(

@bcardiff
bcardiff / README.md
Created June 19, 2015 08:24
Autocode metaprogramming POC in Crystal

Compiling

crystal build main.cr

will change Settings declaration in main.cr from

class Settings