Skip to content

Instantly share code, notes, and snippets.

View buren's full-sized avatar

Jacob Burenstam Linder buren

View GitHub Profile
@buren
buren / gem_irb_session.rb
Created June 23, 2016 07:37
Start a IRB session with a gem loaded
# From http://erniemiller.org/2014/02/05/7-lines-every-gems-rakefile-should-have/
task :console do
require 'irb'
require 'irb/completion'
require 'my_gem'
ARGV.clear
IRB.start
end
@buren
buren / gem_inline_install.rb
Created August 7, 2016 22:53
Install gems on demand, in scripts, using Bundler inline.
require 'bundler/inline'
gemfile(true) do # `true` means install on demand
source 'https://rubygems.org'
gem 'sinatra'
end
@buren
buren / response_follow_redirect.rb
Last active August 8, 2016 15:14
Get response given an URL and follow redirects
require 'uri'
require 'net/http'
require 'openssl'
MAX_ATTEMPTS = 2
# Get response given an URL and follow redirects
def self.url_response(uri)
found = false
url = URI.parse(uri)
@buren
buren / skills-sql-foo.sql
Created February 7, 2017 13:56
Map user skills to rule the world
SELECT "users"."id", "users"."email",
"user_skills1"."skill_id", "user_skills1"."proficiency", "user_skills1"."proficiency_by_admin",
"user_skills2"."skill_id", "user_skills2"."proficiency", "user_skills2"."proficiency_by_admin"
FROM "users"
INNER JOIN "user_skills" as user_skills1 ON "user_skills1"."user_id" = "users"."id" AND (user_skills1.skill_id = 1 AND (user_skills1.proficiency >= 3 OR user_skills1.proficiency_by_admin >= 3))
INNER JOIN "user_skills" as user_skills2 ON "user_skills2"."user_id" = "users"."id" AND (user_skills2.skill_id = 26 AND user_skills2.proficiency_by_admin >= 1)
@buren
buren / first_time_job_performers.sql
Created March 7, 2017 23:04
Total first time job performers between dates
-- First time job performers between dates
SELECT user_performed_in_range.user_id FROM (
SELECT
users.id as user_id,
COUNT(users.id) as user_performed_jobs_count
FROM "jobs"
INNER JOIN job_users on job_users.job_id = jobs.id AND job_users.will_perform = true
INNER JOIN users on job_users.user_id = users.id
WHERE (job_end_date >= {start_time} AND job_end_date <= {end_time})
AND cancelled = false
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@buren
buren / just-arrived-dev-machine-setup.md
Created May 12, 2017 12:05
Just Arrived - Dev machine setup

Just Arrived - Dev machine setup

  1. Install Homebrew

    First of all install Homebrew a.k.a brew (OSX package manager, like apt-get).

    Goto https://brew.sh/ and follow the instructions.

  2. Install Command Line Tools

@buren
buren / gist:6961940
Last active June 1, 2017 07:48
Custom database for rails branch

Custom database for Rails branch

(Below is an example with MySQL)

Customize config/database.yml to handle multiple databases.

<%
  # How to setup a custom database for a branch
  branch = `git symbolic-ref HEAD 2>/dev/null`.chomp.sub('refs/heads/', '')
  suffix = `git config --bool branch.#{branch}.database`.chomp == 'true' ? "_#{branch}" : "_development"
@buren
buren / parse_documents.rb
Last active June 25, 2017 21:12
Parse documents with the yomu gem.
require 'yomu'
filename_or_stream = ARGV[0] # This could also be a tempfile or any object that responds to #read
parsed_document = Yomu.new(filename_or_stream)
metadata = parsed_document.metadata
result = {
title: metadata['title'],
created_at: metadata['meta:creation-date'],
sv_lang = Language.find_by(lang_code: :sv)
en_lang = Language.find_by(lang_code: :en)
ar_lang = Language.find_by(lang_code: :ar)
root_industry = nil
result = csv.map do |row|
sv, en, ar = row
is_root_industry = false
if sv.start_with?('__')