Skip to content

Instantly share code, notes, and snippets.

View sahidursuman's full-sized avatar

Sahidur Rahman Suman sahidursuman

View GitHub Profile
@sahidursuman
sahidursuman / gist:1ef3bc549f5df8177f4362df8b454967
Created June 21, 2018 15:24 — forked from jrochkind/gist:59b6330e3f52710cc49e
Monkey patch to ActiveRecord to forbid
######################
#
# Monkey patch to ActiveRecord to prevent 'implicit' checkouts. Currently tested with Rails 4.0.8, prob
# should work fine in Rails 4.1 too.
#
# If you create a thread yourself, if it uses ActiveRecord objects without
# explicitly checking out a connection, one will still be checked out implicitly.
# If it is never checked back in with `ActiveRecord::Base.clear_active_connections!`,
# then it will be leaked.
#
@sahidursuman
sahidursuman / actionview_helpers_texthelper_autolink_patch.rb
Created June 21, 2018 14:22 — forked from pmarreck/actionview_helpers_texthelper_autolink_patch.rb
A monkeypatch to Rails' ActionView::Helpers::TextHelper (or that class provided by the rails_autolink gem) which causes it to chop up input data in case it's too long to handle

Background

I believe Ubuntu 16.04 comes with PostgreSQL 9.5. Thats good for a start, but it is a matter of time before you have the need of a PostgreSQL 9.6 cluster. For me it was to import a PG backup from Heroku.

The procedure couldn't have been any easier and is described below. If you are interested in upgrading your old cluster to 9.6 afterwards, you may be interested in this.

Instructions

@sahidursuman
sahidursuman / .gitignore
Created June 5, 2018 22:22 — forked from parasew/.gitignore
.gitignore file about what to ignore in a new rails app
Capfile
config/deploy.rb
config/database.yml
log/*.log
**/*.spec.log
db/*.sqlite3
db/schema.rb
tmp/cache/*
tmp/pids/*
tmp/sessions/*
@sahidursuman
sahidursuman / imagemagick-install-steps
Created June 4, 2018 15:36 — forked from rodleviton/imagemagick-install-steps
Installing Image Magick on Ubuntu 14.04
sudo -i
cd
apt-get install build-essential checkinstall && apt-get build-dep imagemagick -y
wget http://www.imagemagick.org/download/ImageMagick-6.8.7-7.tar.gz
tar xzvf ImageMagick-6.8.9-1.tar.gz
cd ImageMagick-6.8.9-1/
./configure --prefix=/opt/imagemagick-6.8 && make
checkinstall
@sahidursuman
sahidursuman / load.sh
Created May 31, 2018 09:01 — forked from derwiki/load.sh
Bulk loading 500m rows into MySQL
for month_table in action*.txt; do
echo "$(date) splitting $month_table..."
split -l 1000000 $month_table curmonth_
for segment in curmonth_*; do
echo "On segment $segment"
time mysql -hlocalhost action_credit_silo <<-SQL
SET FOREIGN_KEY_CHECKS = 0;
SET UNIQUE_CHECKS = 0;
SET SESSION tx_iso
class Item < ActiveRecord::Base
attr_accessible :description, :owner_id, :title, :image_url, :weekly, :daily,
:amazon_url, :image, :brand, :component
belongs_to :owner, class_name: 'User'
COMPONENTS = [:lens, :body, :accessory].each do |component|
scope component.to_sym, where(component: component)
end
BRANDS = [:canon, :nikon, :sony, :olympus, :other].each do |brand|
scope brand.to_sym, where(brand: brand)
var ITERATIONS = 100000,
av = navigator.appVersion;
console.time('indexOf')
for (var i = 0; i < ITERATIONS; i++) {
navigator.appVersion.indexOf("Mobile") > -1
}
console.timeEnd('indexOf')
console.time('regex')
@sahidursuman
sahidursuman / maybe_login_from_token.rb
Created May 31, 2018 08:59 — forked from derwiki/maybe_login_from_token.rb
before_filter that checks for a login token and logs the user in if it's valid
def maybe_login_from_token
Rails.logger.info "maybe_login_from_token: '#{ params[:token] }'"
return if (token = params[:token]).blank?
if (user = User.find_by_token(token))
Rails.logger.info "One time login token used for user #{ user.id }"
sign_in(user)
else
Rails.logger.info "No user found from token: '#{ token }'"
end
@sahidursuman
sahidursuman / pixelpeeper_basic.rb
Created May 31, 2018 08:59 — forked from derwiki/pixelpeeper_basic.rb
Example thin JSON API client in Ruby
require 'httparty'
class PixelPeeper
include HTTParty
base_uri 'www.pixel-peeper.com'
def api_key
ENV['PIXELPEEPER_API_KEY']
end