Skip to content

Instantly share code, notes, and snippets.

View brutuscat's full-sized avatar

Mauro Asprea brutuscat

View GitHub Profile
@brutuscat
brutuscat / ExceptionThrower.php
Created February 17, 2011 09:38
Utility for catching PHP errors, warnings and notices, then converting them (throwing) to an exception that can be caught at runtime @author Jason Hinkle - http://verysimple.com/2010/11/02/catching-php-errors-warnings-and-notices/ @copyright 1997-20
<?php
/**
* Utility for catching PHP errors and converting them to an exception
* that can be caught at runtime
* @author Jason Hinkle
* @copyright 1997-2011 VerySimple, Inc.
* @license http://www.gnu.org/licenses/lgpl.html LGPL
* @version 1.0
*/
class ExceptionThrower
@brutuscat
brutuscat / application.rb
Created September 22, 2011 17:39
Fix issue with Ruby1.9.2, Rails and Psych (new YAML parser)
# Downgrade to use old YAML parser
YAML::ENGINE.yamler = "syck"
# Lots of other stuff .....
@brutuscat
brutuscat / wget.limited.scapper
Created October 4, 2011 09:09
wget command to scrap just a portion of a website's HTML
# This way you can test your scripts in your localhost. It's like using the
# --mirror option without downloading all the needed resources, just the HTML.
# Add "-e robots=off" to be evil
# Add --continue so wget won't download already downloaded files
wget -r -N -E --convert-links --random-wait -l 3 --wait=2 --user-agent=" Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:6.0.1) Gecko/20100101 Firefox/6.0.12011-09-09 13:03:08" "URL-WEBSITE?and=1&params=2"
@brutuscat
brutuscat / bsas_neighborhoods.rb
Created October 7, 2011 13:40
Buenos Aires's neighborhoods (Barrios de Buenos Aires y Localidades de la Provincia)
# Neighborhoods from the Autonomous Capital City official ones and some not so.
TOWNS_CABA = Set.new ["Agronomía","Almagro","Balvanera","Barracas","Belgrano",
"Boedo","Caballito","Chacarita","Coghlan","Colegiales","Constitución","Flores",
"Floresta","La Boca","La Paternal","Liniers","Mataderos","Monserrat",
"Monte Castro","Nueva Pompeya","Núñez","Palermo,","Parque Avellaneda",
"Parque Chacabuco","Parque Chas","Parque Patricios","Puerto Madero","Recoleta",
"Retiro","Saavedra","San Cristóbal","San Nicolás","San Telmo","Vélez Sársfield",
"Versalles","Villa Crespo","Villa del Parque","Villa Devoto","Villa Gral. Mitre",
"Villa Lugano","Villa Luro","Villa Ortúzar","Villa Pueyrredón","Villa Real",
"Villa Riachuelo","Villa Santa Rita","Villa Soldati","Villa Urquiza","Abasto",
@brutuscat
brutuscat / gist:1270928
Created October 7, 2011 17:55
A bash for loop to rename all files with an extension, recursively.
# Replace the first ".less" with your extension and ".css.less" with the desired one
for i in `find . -type f`; do mv "$i" `basename -s .less "$i"`.css.less ; done
@brutuscat
brutuscat / index.json.haml
Created February 14, 2012 09:59
Rails HAML Json render
:plain
[
- @movies.each do |movie|
:plain
{
"name":"#{movie.name}",
"description":"#{j(movie.description)}"
},
]
@brutuscat
brutuscat / deploy.rb
Created February 21, 2012 15:36
Simple Sunspot Solr Capistrano Tasks
# Simple Start and Stop tasks for your Solr server.
# 1 - Download your Solr from http://www.apache.org/dyn/closer.cgi/lucene/solr/ and extract it somewhere
# 2 - Set the :solr_path with the full path to the Solr "example" dir
#
# NOTES:
# - sunspot_solr gem must be in your Gemfile
# - It will run the "example" Jetty-embed Solr server (start.jar)
# - It will automatically pick your project Solr config from your "project_path/solr" with the Sunspot schema and files.
@brutuscat
brutuscat / monit
Created April 25, 2012 15:31
Chksrvd @cpanel /etc/chkserv.d/monit for monitoring monit
service[monit]=x,x,x,/etc/init.d/monit restart,/usr/bin/monit,root
@brutuscat
brutuscat / README
Last active October 26, 2022 06:22
Anonymous Rotating Proxies with Monit, Tor, Haproxy and Delegated. Idea by http://blog.databigbang.com/running-your-own-anonymous-rotating-proxies/
0 - Read http://blog.databigbang.com/running-your-own-anonymous-rotating-proxies/
1 - Install monit, haproxy, tor and delegated.
2 - Setup your environment in the setup.rb file
3 - Just run > ruby setup.rb
4 - ...........
5 - PROFIT! > http://www.southparkstudios.com/clips/151040/the-underpants-business
@brutuscat
brutuscat / weak_assign_attributes.rb
Created May 8, 2012 15:42
A Weak Attributes-Assignment Method for ActiveRecords, that merges in the values only when the attribute is blank?
def weak_assign_attributes(new_attributes)
new_attributes = new_attributes.stringify_keys
new_attributes = self.attributes.merge(new_attributes){|key, old_val, new_val| old_val.present? ? old_val : new_val}.
diff(self.attributes)
self.attributes = new_attributes
end