Skip to content

Instantly share code, notes, and snippets.

View guilhermesimoes's full-sized avatar
😎

Guilherme Simoes guilhermesimoes

😎
View GitHub Profile
# Google Calendar access w/ Data API
# OAuth authentication.
require "sinatra"
require "excon"
require "cgi"
require "base64"
require "openssl"
require "digest/hmac"
require "json/pure"
anonymous
anonymous / gist:3267597
Created August 5, 2012 22:41
Removedeadtracks.js
var ITTrackKindFile = 1;
var iTunesApp = WScript.CreateObject("iTunes.Application");
var deletedTracks = 0;
var mainLibrary = iTunesApp.LibraryPlaylist;
var tracks = mainLibrary.Tracks;
var numTracks = tracks.Count;
var i;
@spalenza
spalenza / define_method.rb
Created February 7, 2013 00:42
Ruby create methods with define_method
# normal
class Library
attr_accessor :games
def each(&block)
games.each(&block)
end
def map(&block)
games.map(&block)
@jonvuri
jonvuri / htmlencode.js
Last active December 15, 2015 04:50
A function to HTML encode a string
function htmlEncode(str) {
return String(str)
.replace(/&/g, '&')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#39;')
.replace(/\//g, '&#47;');
}
import java.util.Map;
import java.util.Comparator;
import java.util.Collections;
int index = 0;
PImage pokemon, current;
PGraphics pie;
HashMap<Integer,Integer> colorMap;
ArrayList<Integer> colorByCount;
@eweitnauer
eweitnauer / README.md
Last active January 15, 2019 23:20
Dominant Baseline Style

Demonstrates the effect of dominant baseline for each of its possible values on text positioning in an SVG.

Each browser/ mobile browser seems to handle these a bit differently. Here are some issues:

  • Retrieving bounding boxes only works correctly after the font is loaded (and there is no easy way to find out when this happens)
  • The bounding box width does not reflect the actual extent of a text, but how far it advances the cursor. That means that in an italic letter 'f' in many fonts, part of the f will actually lie outside of the bounding box
  • The baseline-shift style does not work in FF
  • dominant-baseline values are interpreted different among browsers

All in all its best just use 'alphabetical' (which is consistent across browsers) and do any further vertical positioning by manually by using the x,y or dx,dy or the transform attributes. Also, if one needs to find out about the actual bounds of a text, one cannot rely on the getBBox() or the getBoundingClientRect() DOM methods, but has to use

@lexmag
lexmag / application.js
Created August 4, 2012 19:28
Rails streaming
//= require jquery
//= require jquery_ujs
$(function() {
var source = new EventSource('/stream');
source.addEventListener('counter', function(e) {
$('body').after(e.data + '<br />');
});
});
@cpetschnig
cpetschnig / i18n_lookup.rb
Created January 11, 2012 13:32
Log failed I18n lookups in Rails
class I18n::Backend::Simple
module Implementation
protected
def lookup(locale, key, scope = [], options = {})
init_translations unless initialized?
keys = I18n.normalize_keys(locale, key, scope, options[:separator])
keys.inject(translations) do |result, _key|
@caged
caged / scale.rb
Created November 22, 2012 04:04
Linear scale interpolation in Ruby based on d3.js's implementation
# Returns a lambda used to determine what number is at t in the range of a and b
#
# interpolate_number(0, 500).call(0.5) # 250
# interpolate_number(0, 500).call(1) # 500
#
def interpolate_number(a, b)
a = a.to_f
b = b.to_f
b -= a
lambda { |t| a + b * t }
@justinko
justinko / Plea.markdown
Created May 30, 2012 19:40
Am I doing it wrong?

Dear Rubyists,

I just lost a contract because of my code in a Rails project.

The specific code in question is related to a "posting a comment" feature. Here are the details:

In this project, "posting a comment" does not simply entail inserting a row into the database. It involves a procedure to yes, insert a row, but also detect its language, check for spam, send emails, and "share" it to Twitter and Facebook. I believe this algorithm should be encapsulated. I do not believe it belongs in a controller or a model. I do not believe Active Record callbacks should be used.

The "senior developer", whom is the stake holder's right hand man, said this: