Skip to content

Instantly share code, notes, and snippets.

View lukelex's full-sized avatar

Lukas Alexandre lukelex

  • Gami Studio
  • Copenhagen, Denmark
  • 19:32 (UTC +02:00)
  • Instagram _lukelex
View GitHub Profile
@lukelex
lukelex / week.rb
Created June 2, 2012 17:29
WeekDays Metaprogrammed example
class Week
WEEKDAYS = %w( :segunda_feira, :terca_feira, :quarta_feira, :quinta_feira, :sexta_feira )
def custom_attr_accessor(attr)
self.class_eval("def #{attr};@#{attr};end")
self.class_eval("def #{attr}=(val);@#{attr}=val;end")
end
WEEKDAYS.each do |day|
@lukelex
lukelex / money2float
Created August 17, 2012 14:57
Converts brazilian money to american money
function money2float (money) {
money = money.replace(/[\.\s]/g, "")
money = money.replace(",",".");
return parseFloat(money);
}
@lukelex
lukelex / gist:3417664
Created August 21, 2012 17:37
Getting the relational hierarchy of a mongo embedded document
module EmbeddedSearch
def self.included(base) # :nodoc:
base.extend ClassMethods
end
module ClassMethods
def hierarchy
value = ""
klass = self
while klass.embedded?
@lukelex
lukelex / gist:3489501
Created August 27, 2012 15:27
Json Post with curl
curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST -d ' {"email":"email@email.com"}' http://0.0.0.0:3000/
@lukelex
lukelex / gist:3489878
Created August 27, 2012 16:06
Simple api token authentication
class ApplicationController < ActionController::Base
protect_from_forgery
respond_to :json
before_filter :authorize_user!
helper_method :current_user
def current_user
@current_user
@lukelex
lukelex / .bash_login
Created August 30, 2012 17:58
My git shorcuts
alias g='git'
alias gs='git status'
alias ga='git add'
alias gal='git add .'
alias gcm='git commit -m'
alias gcam='git commit -am'
alias gc='git checkout'
alias gcl='git clone'
alias gm='git merge'
alias gps='git push'
config.model Phase do
# Found associations:
configure :_type, :text # Hidden
configure :_id, :bson_object_id
configure :created_at, :datetime
configure :updated_at, :datetime
list do
field :name
field :number
field :active
@lukelex
lukelex / star_rating.js
Created October 4, 2012 03:28
Simple start rating script
$('#user_stats_resume #top_stats .stars .star').click(function(){
rate = $(this).data('rate');
stars = $('#user_stats_resume #top_stats .stars .star');
stars.removeClass('selected');
stars.each(function() {
$(this).addClass('selected');
if ($(this).data('rate') === rate) return false;
});
});
@lukelex
lukelex / ZipCode.js
Created October 28, 2012 00:15
Get the zip code state from Google Api
var geocoder = new google.maps.Geocoder();
function getState(zipcode) {
geocoder.geocode( { 'address': zipcode}, function (result, status) {
var state = "N/A";
for (var component in result[0]['address_components']) {
for (var i in result[0]['address_components'][component]['types']) {
if (result[0]['address_components'][component]['types'][i] == "administrative_area_level_1") {
state = result[0]['address_components'][component]['short_name'];
// do stuff with the state here!
@lukelex
lukelex / sorter.coffee
Created December 8, 2012 21:58
Generic table item sorter in coffeescript & jquery
$ ->
$('dt .iconFilter').click (e) ->
e.preventDefault()
objTable = $(@).closest('dl')
order = $(@).attr('class').match(/(a|de)sc/)[0]
sortTable {
clicked: $(@),
table: objTable,
order: order,
elemType: 'dd',