Skip to content

Instantly share code, notes, and snippets.

View miguelff's full-sized avatar

Miguel Fernández miguelff

View GitHub Profile
@miguelff
miguelff / gist:919277
Created April 14, 2011 11:12
mergesort java collections framework impl.
private static void sort(int start, int end, long[] array) {
long temp;
int length = end - start;
if (length < 7) {
for (int i = start + 1; i < end; i++) {
for (int j = i; j > start && array[j - 1] > array[j]; j--) {
temp = array[j];
array[j] = array[j - 1];
array[j - 1] = temp;
}
%%
%% wait_for_stream/2
%%
wait_for_stream({xmlstreamstart, _Name, Attrs}, StateData) ->
?TRACE(undefined, "START: ~p", [Attrs]),
DefaultLang = case ?MYLANG of
undefined -> " xml:lang='en'";
DL -> " xml:lang='" ++ DL ++ "'"
end,
case xml:get_attr_s("xmlns:stream", Attrs) of
@miguelff
miguelff / gist:2634316
Created May 8, 2012 11:18
An script to grab some quick dirty stats of the aol query log
#!/usr/bin/env ruby
files = %w{aol015 aol026}.map{|f| f+".sessionized"}
sessions = {}
#load sessions hash
files.each do |f|
lines = File.open(f).each do |line|
if line.length > 10
sid, uid, q, *rest = line.split("\t")
if sessions.has_key? sid
@miguelff
miguelff / gist:2920479
Created June 12, 2012 22:20
Gente hablando en twitter desde Mieres, (Asturias) sobre los mineros.
require 'rubygems'
gem 'twitter'
gem 'geocoder'
class Hash
def to_url_params
elements = []
keys.size.times do |i|
elements << "#{keys[i]}=#{values[i]}"
@miguelff
miguelff / strike.md
Created November 14, 2012 10:45 — forked from cavalle/strike.md
My reasons to support the general strike in Spain

My reasons to support the general strike in Spain

I think the austerity measures imposed by Europe to Spain will eventually work. But the only possible outcome I personally expect is to get back to where we were before the crisis. An illusion of wealth just waiting for the next crisis to happen.

Politicians seem to have decided that this crisis won't change anything. Probably because the first thing that needs to change are the politicians themselves.

After this crisis, Spain will be as inefficient and as brittle as it was before. Spain economy will keep depending on the state, on the banks and on a few very big companies to survive. We will keep depending on our King closing big deals with Arab Sheiks while hunting elephants in Africa.

The banks and the big companies, knowing that the consequences of their errors will be assumed by the tax-payers, as they cannot afford to let them down, will keep becoming increasingly more inefficient and incompetent.

My job, explained so my mom can understand it

"I am a freelance Ruby and Rails developer". When I talk with my geek friends, everyone understands what I do and they have a reasonable understanding of how I spend my day. But sometimes, less technical people ask me what I do for a living and then I tend to dumb down the answer: "I am a programmer, I usually build websites.". Oh -they say- my nephew also make websites, he even built me a blog in Blogger.

Err... yes, but that hardly has anything to do with what I do for a living.

There are many different kinds of websites, built with different technologies, and depending on the site and the technology used to build it, they are made by one kind of professional or another. The craft of building a website comprises many different disciplines, and professionals usually specialize in just one part of the process. Although I do many different things, my specialization is mainly programming dynamic websites using Ruby and Rails.

In this article I want to

#!/usr/bin/env ruby
require 'net/telnet'
cache_dump_limit = 100
localhost = Net::Telnet::new("Host" => "localhost", "Port" => 11211, "Timeout" => 3)
slab_ids = []
localhost.cmd("String" => "stats items", "Match" => /^END/) do |c|
matches = c.scan(/STAT items:(\d+):/)
slab_ids = matches.flatten.uniq
end

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application:

## Prepare ###################################################################
# Remove RVM
rvm implode
# Ensure your homebrew is working properly and up to date
brew doctor
brew update
## Install ###################################################################
@miguelff
miguelff / romans.py
Created October 6, 2013 00:39
Roman numerals in python
#!/usr/bin/env python
# encoding: utf-8
"""
romans.py
Convert integer to roman numerals back and forth
Created by Miguel Fernández on 2013-10-06.
"""
class Romans: