Skip to content

Instantly share code, notes, and snippets.

@hugopeixoto
hugopeixoto / enumerable_collate.gemspec
Created May 29, 2012 10:18
Allows for iteration of multiple enumerables
Gem::Specification.new do |s|
s.name = 'enumerable_collate'
s.version = '0.1.0'
s.platform = Gem::Platform::RUBY
s.author = 'Hugo Peixoto'
s.email = 'hugo.peixoto@gmail.com'
s.summary = 'Enumerable Collate'
s.description = 'Allows for iteration of multiple enumerables'
s.files = ['enumerable_collate.rb']
#include "post.h"
using app::models::Post;
template<>
const char Post::super::model_name_[] = "post";
template<>
const Post::super::ColumnList Post::super::columns_ = {
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
</head>
<body>
<% Post::Set& posts = params.get("posts"); %>
<h1>It works!</h1>
<ul>
## List herp derp file
sub is_herpderp
{
my ($match) = "@_\n";
my($file) = Irssi::get_irssi_dir."/herp";
open my $fh, "<", $file;
return grep {uc($_) eq uc($match)} <$fh>;
}
@hugopeixoto
hugopeixoto / test.cc
Created August 26, 2012 19:10
Overriding static_cast to provide bounds checking
#include <limits>
extern "C" int printf (const char*, ...);
template<typename T, typename U>
T checked_static_cast(const U& a_value)
{
if (a_value < std::numeric_limits<T>::min() ||
a_value > std::numeric_limits<T>::max()) {
printf("Out of bounds value!\n");
int x = *(int*)0;
@hugopeixoto
hugopeixoto / enumeration_support.rb
Created August 29, 2012 13:22
Enumeration support
module EnumerationSupport
def self.included (base)
base.extend ClassMethods
end
module ClassMethods
def add_enumeration name, *keys
keys = keys.map { |key| key.to_s.tr(' ', '_').upcase }
const_set(name.to_s.upcase, Class.new do
keys.each do |key|
@hugopeixoto
hugopeixoto / x.rb
Created November 21, 2012 21:47
pokemon
class CategoriesTest < ActiveSupport::TestCase
def setup
@catalog = mock()
@interactor = StoreAPI::CategoriesInteractor.new(@catalog)
end
test "Should return the root categories" do
expected_categories = [mock(), mock(), mock()]
Category.stubs(:main_categories).returns(expected_categories)
require 'store_api/categories'
class StoreAPI
def categories
StoreAPI::Categories.new # defined in store_api/categories.rb
end
end
@hugopeixoto
hugopeixoto / edit.ecc
Created November 26, 2012 02:06
kiwi revised
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
</head>
<body>
<h1>Editing post <%= post["name"] %></h1>
<%= form_for(post, [&](FormBuilder& f) { %>
<p><%= f.input("name") %></p>
@hugopeixoto
hugopeixoto / test.rb
Created November 27, 2012 14:25
Single assert?
test "Should allow multiple locales" do
x = X.new
x.set_name("Herp", "en_US")
x.set_name("Erpo", "pt_PT")
assert_equal "Herp", x.get_name("en_US")
assert_equal "Erpo", x.get_name("pt_PT")
end