Skip to content

Instantly share code, notes, and snippets.

View roccogalluzzo's full-sized avatar
⛑️

Rocco Galluzzo roccogalluzzo

⛑️
View GitHub Profile
from routes import Mapper
class CustomMapper(Mapper):
def match(self, url= None, environ= None):
if not url and not environ:
raise RoutesException('URL or environ must be provided')
if not url:
def render(template_name, tmpl_vars={}, cache_key=None,
cache_type=None, cache_expire=None):
globs = pylons_globals()
tmpl_vars.update(globs)
@contextfunction
DELIMITER $$
CREATE PROCEDURE `geodist`(IN mylat float, IN mylon float, IN dist int)
BEGIN
declare lon1 float; declare lon2 float;
declare lat1 float; declare lat2 float;
set lon1 = mylon-dist/abs(cos(radians(mylat))*111.1);
set lon2 = mylon+dist/abs(cos(radians(mylat))*111.1);
set lat1 = mylat-(dist/111.1);
@roccogalluzzo
roccogalluzzo / gist:1977777
Created March 5, 2012 10:27 — forked from dhh/gist:1975644
Protect against Mass assigniments bugs
class PostsController < ActionController::Base
def create
Post.create(post_params)
end
def update
Post.find(params[:id]).update_attributes!(post_params)
end
private
/**
* Exercise 3
*/
def countChange(money: Int, coins: List[Int]): Int = {
if (money == 0) 1
else if (money < 0 || coins.isEmpty) 0
else countChange(money, coins.tail) + countChange(money - coins.head, coins)
}
'''
prefix_code.py
Copyright 2012-2013 Josiah Carlson
Released under the GNU LGPL v 2.1 license
This module offers the ability to encode/decode a sequence of integers into
strings that can then be used to compare sequences of integers (or paths on
trees) quickly. This module was originally intended to be used in a case-
preserving index in a relational database (where 'Z' comes before 'a', as is
body = {
grant_type: 'authorization_code',
client_id: Rails.application.secrets[provider]['client_id'],
client_secret: Rails.application.secrets[provider]['client_secret'],
redirect_uri: integration_callback_url(provider),
code: params[:code]
}.to_query
uri = URI.parse('https://api.createsend.com/oauth/token')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
@roccogalluzzo
roccogalluzzo / 0_reuse_code.js
Last active August 29, 2015 14:07
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
# JSON
mailup = MailUp::API.new(credentials)
lists = mailup.console.user.lists
lists['Items'].first['Name']
# => "Test List"
list_id = lists['Items'].first['idList'].to_i
# => 1
list = mailup.console.list(list_id)
groups = list.groups(pageNumber: 1, pageSize: 25)
# old
def get(path, opts={}, &block) # :nodoc:
request(:get, path, opts, &block)
end
def recipients(params = {})
@api.get("#{@api.path}/Message/#{@id}/List/Recipients", params: params)
end
def views(params = {})