Skip to content

Instantly share code, notes, and snippets.

View fxn's full-sized avatar

Xavier Noria fxn

View GitHub Profile
@fxn
fxn / gist:274219
Created January 11, 2010 13:05
seach for STI grandchildren who are leaves
# Computes STI models who are grandchildren or more.
#
# In a STI the root class and its subclasses work normally, but if there are
# grandchildren we need to preload them. Reason is, given A < B < C, if you
# for example compute B.count without loading A, only B records are taken into
# account in the query (where a clause about the type column intervenes). This
# is not a bug, Active Record is simply not aware of A. Once it is, the clause
# becomes an OR with all relevant types.
#
# I used this script to compute them.
A backup from http://sites.google.com/site/redcodenl/creating-shazam-in-java-1 just in case
----
Creating Shazam in Java
A couple of days ago I encountered this article: How Shazam Works
This got me interested in how a program like Shazam works… And more importantly, how hard is it to program something similar in Java?
@fxn
fxn / authors of electronic music
Created July 19, 2010 19:32
Recommendations of authors/groups of electronic music
Moby
Enigma - Enigma 3
Hooverphonic
Koop
Au Revoir Simone
The XX
Gotan Project
Air
The Virgin Suicides
Goldfrapp
#!/usr/bin/env ruby
# A simple script to gzip content recursively. I use it for the Nginx gzip_static module.
require 'find'
EXTENSIONS = %w(.js .html .css)
def gzname(file)
"#{file}.gz"
defmodule Hello.HelloController do
use Hello.Web, :controller
plug :action
def world(conn, %{"name" => name}) do
render conn, "world.html", name: name
end
end
@fxn
fxn / gsoc.md
Created September 10, 2015 07:33 — forked from febuiles/gsoc.md

Google Summer of Code Wrap up: Ruby on Rails

Rails is a Ruby framework that includes everything needed to create web applications. This was our fourth Summer of Code participation, and in this post we'd like to tell you a bit about this year's projects.

Asset Source Maps (Andrei Istratii)

Andrei has added support for several types of Source Maps to Sprockets 4. With Source Maps users can see a readable version of their code inside Developer Tools (Javascript, CSS, etc.) after it's been minified or compiled. Check out Andrei's

@fxn
fxn / user.ex
Created September 12, 2015 07:55
defp put_pass_hash(changeset) do
case changeset do
%Ecto.Changeset{valid?: true, changes: %{password: pass}} = chset ->
put_change(chset, :password_hash, Comeonin.Bcrypt.hashpwsalt(pass))
chset -> chset
end
end
require 'set'
require 'digest/md5'
# Let original be a collection with the names of the files in the
# original directory. Let target be the ones in the target directory.
#
# We want to find which files in original are equal to some in target
# except perhaps for the filename.
osizes, tsizes = classify_by_size(original, target)
#!/usr/bin/env ruby
#
# Joins paragraphs so that they span one long line.
# Quoted or indented text are left untouched.
# Useful for Gmail.
#
open('| pbcopy', 'w') do |pbcopy|
pbcopy.write(`pbpaste`.gsub(/([^>\n])\n(\w)/, '\\1 \\2'))
end
@fxn
fxn / config.ru
Created April 1, 2011 21:48
demonstrates early fetch of an asset in the HEAD, and the 1K threshold
class Html
def initialize(env)
@server_port = env['SERVER_PORT']
end
def first_chunk_prefix
<<EOS
<!DOCTYPE html>
<html>
<head>