Skip to content

Instantly share code, notes, and snippets.

Avatar

Man Vuong kidlab

  • Toptal (@toptal)
  • Ho Chi Minh City, Vietnam
View GitHub Profile
@kidlab
kidlab / gist:4c40fababb3944385f55
Last active Aug 29, 2015 — forked from masonforest/gist:4048732
Installing a Gem on Heroku from a Private GitHub Repo
View gist:4c40fababb3944385f55

Installing a Gem on Heroku from a Private GitHub Repo

Sometimes you want to use a gem on Heroku that is in a private repository on GitHub.

Using git over http you can authenticate to GitHub using basic authentication. However, we don't want to embed usernames and passwords in Gemfiles. Instead, we can use authentication tokens.

  1. Get an OAuth Token from GitHub

First you will need to get an OAuth Token from GitHub using your own username and "note"

View goldiloader_issue_29.rb
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
gem 'activerecord', '4.2.4'
@kidlab
kidlab / Debugging Ruby Notes.html
Created Dec 6, 2015 — forked from wallace/Debugging Ruby Notes.html
My notes from Aman Gupta's Debugging Ruby webinar by Engine Yard
View Debugging Ruby Notes.html
<a href="http://en.wikipedia.org/wiki/Lsof">lsof</a>
----
show open files
lsof -nPp <pid>
<a href="http://linux.die.net/man/1/strace">strace</a>
------
@kidlab
kidlab / README.md
Created Nov 6, 2016 — forked from joakimk/README.md
CircleCI elixir build example
View README.md

This runs a build for a small elixir (phoenix) project in about 40 seconds by caching as much of the compiled files as possible.

We've been using this for months in multiple projects without any issues. Please ping be if there is any issues with this script and I'll update it.

It should be generic enough to work on any elixir app using mix.

If you have a elixir_buildpack.config, then enable that section in the build script to keep versions in sync!

2016-08-09: Updated to newer Erlang and Elixir and fixed curl command.

@kidlab
kidlab / another_example.rb
Last active Apr 18, 2017 — forked from shawndrost/application.rb
Single file Rails application
View another_example.rb
# Activate the gem you are reporting the issue against.
gem 'activerecord'
require 'active_record'
require 'minitest/autorun'
require 'logger'
# Ensure backward compatibility with Minitest 4
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
# This connection will do for database-independent bug reports.
@kidlab
kidlab / Rakefile.rb
Created Apr 18, 2017 — forked from drogus/Rakefile.rb
This is the example contents of the Rakefile, which you would use to run active record tasks without using Rails. It assumes using the same directories as rails uses: `db/migrate`, `config/database.yml`.
View Rakefile.rb
require 'bundler/setup'
require 'active_record'
include ActiveRecord::Tasks
db_dir = File.expand_path('../db', __FILE__)
config_dir = File.expand_path('../config', __FILE__)
DatabaseTasks.env = ENV['ENV'] || 'development'
@kidlab
kidlab / GIF-Screencast-OSX.md
Created May 12, 2017 — forked from dergachev/GIF-Screencast-OSX.md
OS X Screencast to animated GIF
View GIF-Screencast-OSX.md

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application:

@kidlab
kidlab / .rvmrc
Created Nov 3, 2017 — forked from eirc/.rvmrc
Ruby-based Benchmark of MessagePack vs. JSON vs. Yajl vs. Protobuffers vs. MultiJson vs. Marshal vs. YAML vs. BSON
View .rvmrc
rvm --create ree@benchmarks
@kidlab
kidlab / README.md
Last active Nov 3, 2017
Ruby memory conscious
View README.md

MEASURING MEMORY USAGE

There are several gems that help with determining where a program allocates memory. The two that I most often use are allocation_tracer and memory_profiler.

Both tools can measure a whole program or they can be turned on and off to only measure certain parts of a program. Either method allows you to determine hotspots in your program and then act on the information. For example, while developing kramdown several years ago I found that the HTML converter class allocated huge amounts of throw-away strings. By changing this hotspot to a better alternative kramdown got faster and used less memory.

To get you started on using these two gems, here are two files that are intended to get pre-loaded using the -r switch of the ruby binary (i.e. ruby -I. -ralloc_tracer myscript.rb).

Credit: https://gettalong.org/blog/2017/memory-conscious-programming-in-ruby.html

@kidlab
kidlab / manual_preloading.rb
Created May 2, 2018 — forked from sobstel/manual_preloading.rb
Rails manual association preloading
View manual_preloading.rb
# taken from https://mrbrdo.wordpress.com/2013/09/25/manually-preloading-associations-in-rails-using-custom-scopessql/
# collection association e.g. has_many
owners = People.all
association_name = :photos
owners.each do |owner|
records = Array(whatever_you_want)