Skip to content

Instantly share code, notes, and snippets.

# encoding: utf-8
module Iceleres
class PhoneNumber
include EnumerateIt
include ActiveModel::Validations
ATTRIBUTES = [:area_code, :number, :type, :validation]
PHONE_FORMAT = /^[1-9]\d{3}[-\s]?\d{4}/
attr_accessor *ATTRIBUTES
# encoding: utf-8
module Iceleres
module HasPhoneNumber
def has_phone_number(name, options={})
options.assert_valid_keys [:validate]
define_method "#{name}_phone_number=" do |phone_number|
self.send("#{name}_phone=", phone_number.number)
self.send("#{name}_phone_areacode=", phone_number.area_code)
end
def give_specific_permissions_to_user(user, permission)
profile = if user.profiles.empty?
user_profile = Iceleres::UserProfile.create :user_id => user.id, :profile => Factory(:profile)
user_profile.profile
else
user.profiles.first
end
profile.permissions << Factory(permission)
end
@marcosinger
marcosinger / config.ru
Created February 29, 2012 23:49
Rails Lightweight Stack. Most of this is detailed on Crafting Rails Applications - http://pragprog.com/book/jvrails/crafting-rails-applications
# Run this file with `RAILS_ENV=production rackup -p 3000 -s thin`
# Be sure to have rails and thin installed.
require "rubygems"
require "rails"
# Let's load only action controller. If you want
# to use active record, just require it as well.
require "action_controller/railtie"
class MyApp < Rails::Application
@marcosinger
marcosinger / gist:2722199
Created May 17, 2012 23:12
Cloning all listed projects, creating a gemset and runs Bundle install
#!/bin/bash
current_path=`pwd`
projects=(webdesk/webdesk webdesk/webdesk-provisioner webdesk/webdesk-product-api
webchat/webchat webchat/webchat-provisioner webchat/webchat-product-api
pabx-virtual/pabx-virtual-2011 pabx-virtual/pabx-provisioner
pabx-virtual/pabx-product-api pabx-virtual/ruby_pabx_core
saas_plan_config/saas_plan_config
locaweb-utilities/x9 package_pipeline/package_pipeline
product-apify/product-apify feed_consumer/feed_consumer
@marcosinger
marcosinger / gist:2781490
Last active October 5, 2015 08:48
Append jQuery on the fly
javascript:(
function(){
a=document.createElement('SCRIPT');
a.type='text/javascript';
a.src='http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js';
document.getElementsByTagName('head')[0].appendChild(a);
}
)();
@marcosinger
marcosinger / 0_reuse_code.js
Created December 21, 2013 03:04
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@marcosinger
marcosinger / count_tech
Created February 6, 2015 22:16
A shell script to count how many lines of code in each language each author added/removed in a repo
#!/bin/bash
git status &>-
if [ "$?" -ne 0 ]; then
printf "%0s$(echo -en "\033[1;31m")Error :$(echo -en "\033[0m") Run this command in a git repo"
exit 1
fi
declare -A techs=( ["Ruby"]="rb" ["Javascript"]="js" ["Html"]="html" ["Css"]="css")
authors=$(git shortlog -s | awk '{print $2}')
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
)
func main() {
@marcosinger
marcosinger / sample.rb
Created January 3, 2019 19:32
Classe de exemplo para determinar se um estabelecimento está aberto no momento
class Sample
HOURS = {
'mon' => [],
'tue' => [
['09:00', '19:00'],
],
'wed' => [
['09:00', '19:00'],
],
'thu' => [