Skip to content

Instantly share code, notes, and snippets.

View danielgracia's full-sized avatar

Daniel Gracia danielgracia

View GitHub Profile
@danielgracia
danielgracia / pluck_bug.rb
Created June 11, 2014 18:59
Unexpected behavior in pluck
gem 'activerecord', '4.1.0'
require 'active_record'
require 'minitest/autorun'
require 'logger'
# Ensure backward compatibility with Minitest 4
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
@danielgracia
danielgracia / Cripto.java
Created September 11, 2014 02:33
Everybody did that once
package persistence.utility;
public class Cripto {
public static String encodeString(String s){
//TODO: encode password here
return s;
}
}
@danielgracia
danielgracia / dilbert.rb
Last active January 4, 2016 19:17
Fooling with JRuby and pretty much any gem with a cool name that I feel like using.
require 'date'
require 'rubygems'
require 'mechanize'
require 'concurrent'
require 'daybreak'
require 'thread'
require 'pry'
Promise = Concurrent::Promise
@danielgracia
danielgracia / cgi-server.rb
Last active March 13, 2017 23:34
CGI Server in Ruby
#!/usr/bin/env ruby
# Script depends on whatever WEBrick has in Ruby 2.2.3
# Includes for convenience
require 'webrick'
include WEBrick
# Initialize plain server, no indexing, else CGI handling will be broken
s = HTTPServer.new(
@danielgracia
danielgracia / main.c
Created January 29, 2016 19:29
shortpath (nerdsniped)
#include <stdbool.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <libgen.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <pwd.h>
@danielgracia
danielgracia / coalesce.ex
Last active December 7, 2017 17:13
Coalesce macro
defmodule Coalesce do
@moduledoc """
Provides a "coalesce" macro.
This macro is partly inspired by the COALESCE function in the SQL-92 standard.
The original COALESCE function is a function that returns the first non-null
computed expression passed as one of its argument, or NULL itself if no such
expression is found.