Skip to content

Instantly share code, notes, and snippets.

View carlesso's full-sized avatar

Enrico Carlesso carlesso

View GitHub Profile
if object.asin.present?
"http://www.amazon.it/gp/product/#{object.asin}/ref=as_li_qf_br_asin_il_tl?ie=UTF8&camp=3370&creative=23322&creativeASIN=#{object.asin}&linkCode=as2&tag=swdaniele-21"
else
"http://www.amazon.it/s/ref=nb_sb_noss_1?__mk_it_IT=%C3%85M%C3%85%C5%BD%C3%95%C3%91&url=search-alias%3Ddvd&field-keywords=#{CGI::escape title}&tag=swdaniele-21"
end
@carlesso
carlesso / Twitter Languages - 2015-06-25
Created June 24, 2015 22:26
Twitter Languages - 2015-06-25
[
{
"code": "fr",
"name": "French",
"status": "production"
},
{
"code": "en",
"name": "English",
"status": "production"
require 'rubygems'
require 'bundler/setup'
require 'faye/websocket'
require 'eventmachine'
require 'json'
require 'pry'
EM.run {
url = ARGV[0]
headers = {'Origin' => 'http://faye.jcoglan.com'}
class WelcomeController < ApplicationController
def index
@xhr = request.xhr?
render :index, change: 'variable'
end
end
0 info it worked if it ends with ok
1 verbose cli [ 'node', '/usr/bin/npm', 'start' ]
2 info using npm@2.12.1
3 info using node@v0.12.6
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info prestart learning-react@1.0.0
6 info start learning-react@1.0.0
7 verbose unsafe-perm in lifecycle true
8 info learning-react@1.0.0 Failed to exec start script
9 verbose stack Error: learning-react@1.0.0 start: `node --harmony server`
# :nocov:
if defined?(Rails)
module MyGem
module Rails
class Engine < ::Rails::Engine
end
end
end
end
# :nocov:
class Post
include Mongoid::Document
include Mongoid::Paranoia
include Mongoid::Timestamps
field :title, :type => String
attr_accessor :tags_string
accepts_nested_attributes_for :answers
@carlesso
carlesso / gist:1143274
Created August 12, 2011 23:47
Rails 3.1.0.rc5 clean Gemfile.lock
GEM
remote: http://rubygems.org/
specs:
actionmailer (3.1.0.rc5)
actionpack (= 3.1.0.rc5)
mail (~> 2.3.0)
actionpack (3.1.0.rc5)
activemodel (= 3.1.0.rc5)
activesupport (= 3.1.0.rc5)
builder (~> 3.0.0)
@carlesso
carlesso / gist:1178149
Created August 29, 2011 10:26
Mod Rewrite
RewriteEngine On
Options Indexes FollowSymlinks Multiviews
RewriteBase /
RewriteCond %{HTTP_HOST} www.sito.com
RewriteCond %{REQUEST_URI} !drupal/
RewriteRule ^(.*)$ http://www.sito.com/drupal/$1 [L]
def hc_votes_per_ages
# 0-18 19-24 25-34 35-49 50-64 65-inf
now_s = Time.now.to_formatted_s(:db)
age_votes = {"0" => [], "1" => [], "2" => [], "3" => [], "4" => [], "5" => [], "6" => []}
age_labels = {"0" => "< 18", "1" => "18 - 25", "2" => "25 - 35", "3" => "35 - 50", "4" => "50 - 65", "5" => "> 65", "6" => "unknown"}
model.answers.each do |a|
query = "COUNT(users.id) as vote_count, CASE
WHEN users.birthday>(NOW() - INTERVAL '18 year') THEN 0
WHEN users.birthday<=(NOW() - INTERVAL '18 year') AND users.birthday>(NOW() - INTERVAL '25 year') THEN 1
WHEN users.birthday<=(NOW() - INTERVAL '25 year') AND users.birthday>(NOW() - INTERVAL '35 year') THEN 2