Skip to content

Instantly share code, notes, and snippets.

View dgilperez's full-sized avatar
🌊
Build that!

David Gil dgilperez

🌊
Build that!
View GitHub Profile
@dgilperez
dgilperez / README_Genealogy.textile
Last active December 17, 2015 12:49
Resources towards an online genealogical tree visualizing app
@dgilperez
dgilperez / user.rb
Last active December 21, 2015 02:09 — forked from harlow/user.rb
# app/models/user.rb
class User < ActiveRecord::Base
validates :zipcode, presence: true, zipcode: true
end
on appIsRunning(appName)
tell application "System Events" to (name of processes) contains appName
end appIsRunning
on execInItermTab(_terminal, _session, _command)
tell application "iTerm"
activate
set current terminal to _terminal
tell _session
select _session
require 'delegate'
class Base
def foo
"foo"
end
def bar
"bar"
end
end
@dgilperez
dgilperez / gist:8921033
Last active November 4, 2016 22:08
Setting up a spinner for every AJAX call, globally
// One solution might be to have an AJAX spinner in a standard location that gets shown when AJAX requests start and hidden when AJAX requests complete. To do this globally in jQuery:
// http://robots.thoughtbot.com/automatically-wait-for-ajax-with-capybara
jQuery.ajaxSetup({
beforeSend: function(xhr) {
$('#spinner').show();
},
// runs after AJAX requests complete, successfully or not
complete: function(xhr, status){
$('#spinner').hide();
// Slick little method to create a bitmask from an array of boolean values. (for Javascript)
function bitMask(a, b) {
var m = 0, i;
if (b !== undefined) { a = Array.prototype.slice.apply(arguments); }
for (i = 0; i < a.length; i += 1) {
if (a[i] !== false) { m += Math.pow(2, i) };
}
return m;
module Abilities
def self.ability_for(user)
if user.admin?
AdminAbility.new(user)
else user
MemberAbility.new(user)
else
GuestAbility.new
end
end
# Parses YouTube URLs directly or from iframe code. Handles:
# * Address bar on YouTube url (ex: http://www.youtube.com/watch?v=ZFqlHhCNBOI)
# * Direct http://youtu.be/ url (ex: http://youtu.be/ZFqlHhCNBOI)
# * Full iframe embed code (ex: <iframe src="http://www.youtube.com/embed/ZFqlHhCNBOI">)
# * Old <object> tag embed code (ex: <object><param name="movie" value="http://www.youtube.com/v/ZFqlHhCNBOI">...)
/(youtu\.be\/|youtube\.com\/(watch\?(.*&)?v=|(embed|v)\/))([^\?&"'>]+)/
$5 #=> the video ID
# test it on Rubular: http://rubular.com/r/eaJeSMkJvo
namespace :spec do
# largely lifted from http://www.pervasivecode.com/blog/2007/06/28/hacking-rakestats-to-get-gross-loc/
task :stats_setup do
require 'code_statistics'
class CodeStatistics
alias calculate_statistics_orig calculate_statistics
def calculate_statistics
@pairs.inject({}) do |stats, pair|
if 3 == pair.size