Skip to content

Instantly share code, notes, and snippets.

View mgomes's full-sized avatar

Mauricio Gomes mgomes

View GitHub Profile
# Install Ruby 1.9.2 on OS 10.6
# Uses RVM and homebrew
# Install RVM (if you haven't already)
bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )
# Install homebrew (if you haven't already)
ruby -e "$(curl -fsS http://gist.github.com/raw/323731/install_homebrew.rb)"
# If you already had rvm installed (older versions only)
# Run these commands
# Uses Homebrew install of libxml2 with Snow Leopard version of libxslt
brew install libxml2
gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.7.7/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.7.7/lib --with-xslt-lib=/usr/lib/libxslt.1.dylib
@mgomes
mgomes / raw_couchdb_find.rb
Created February 8, 2011 21:29
Uses Curl
def raw_find(view, key)
url = URI::parse(CouchPotato::Config.database_name)
if key.is_a?(String)
http_client = Curl::Easy.new("#{url}/_design/advocacy_polygon/_view/#{EscapeUtils.escape_url(view)}?key=%22#{EscapeUtils.escape_url(key.to_s)}%22&reduce=false&include_docs=true")
elsif key.is_a?(Integer)
http_client = Curl::Easy.new("#{url}/_design/advocacy_polygon/_view/#{EscapeUtils.escape_url(view)}?key=#{EscapeUtils.escape_url(key.to_s)}&reduce=false&include_docs=true")
elsif key.is_a?(Range)
http_client = Curl::Easy.new("#{url}/_design/advocacy_polygon/_view/#{EscapeUtils.escape_url(view)}?startkey=#{EscapeUtils.escape_url(key.begin)}&endkey=#{EscapeUtils.escape_url(key.end)}&reduce=false&include_docs=true")
else
raise SyntaxError
@mgomes
mgomes / gist:964911
Created May 10, 2011 17:10
Ruby Array XOR
class Array
def ^(ary)
return (ary | self) - (ary & self)
end
end
desc "Heroku Cron Task"
task :cron => :environment do
begin
Rake::Task["accounts:bill"].invoke
rescue
HoptoadNotifier.notify($!)
end
begin
Rake::Task["accounts:expire"].invoke
desc "Heroku Cron Task"
task :cron => :environment do
Rake::Task["accounts:bill"].invoke
Rake::Task["accounts:expire"].invoke
end
<a href='http://youtube.com'>
<img src='http://mauriciogomes.com/share/kx_video.png'>
</a>
@mgomes
mgomes / web_url_regex.rb
Created March 14, 2016 18:19
Detect URL within text. Adapted from Android.
# URL Matching
# Taken from Android: http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/5.1.1_r1/android/util/Patterns.java#145
GOOD_IRI_CHAR = /a-zA-Z0-9\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF/
GOOD_GTLD_CHAR = /a-zA-Z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF/
GTLD = /[#{GOOD_GTLD_CHAR}]{2,63}/
IRI = /[#{GOOD_IRI_CHAR}]([#{GOOD_IRI_CHAR}\-]{0,61}[#{GOOD_IRI_CHAR}]){0,1}/
HOST_NAME = /(#{IRI}\.)+#{GTLD}/
IP_ADDRESS = /((25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[1-9][0-9]|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[1-9][0-9]|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[1-9][0-9]|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[1-9][0-9]|[0-9]))/
DOMAIN_NAME = /(#{HOST_NAME}|#{IP_ADDRESS})/
WEB_URL_REGEX = /((?:(http|https|Http|Https|rtsp|Rtsp):\/\/(?:(?:[a-zA-Z0-9\$\-\_\.\+\!\*\'\(\)\,\;\?\&\=]|(?:\%[a-fA-F0-9]{2})){1,64}(?:\:(?:[a-zA-Z0-9\$\-\_\.\+\!\*\'\(\)\,\;\?\&\=]|(?:\%[a-fA-F0-9]{2})){1,25})?\@)?)?(?:#{DOMAIN_NAME})(?:\:\d{1,5})?)(\/(?:(?:[#{GOOD_IRI_CHAR}\;\/\?\:\@\&\=\#\~\-\.\+\
@mgomes
mgomes / dnn.py
Last active March 19, 2019 03:33
Deep Neural Net
import tensorflow as tf
print(tf.__version__)
class myCallback(tf.keras.callbacks.Callback):
def on_epoch_end(self, epoch, logs={}):
if(logs.get('loss')<0.4):
print("\nReached 60% accuracy so cancelling training!")
self.model.stop_training = True
callbacks = myCallback()
@mgomes
mgomes / cnn.py
Created March 19, 2019 03:05
CNN With MNIST
import tensorflow as tf
print(tf.__version__)
mnist = tf.keras.datasets.mnist
(training_images, training_labels), (test_images, test_labels) = mnist.load_data()
training_images=training_images.reshape(60000, 28, 28, 1)
training_images=training_images / 255.0
test_images = test_images.reshape(10000, 28, 28, 1)
test_images=test_images/255.0
model = tf.keras.models.Sequential([
tf.keras.layers.Conv2D(32, (3,3), activation='relu', input_shape=(28, 28, 1)),