Skip to content

Instantly share code, notes, and snippets.

@lipowen
lipowen / gist:e1943e1f3f63ef89fa8f8dc8caff829e
Created April 16, 2020 02:46 — forked from jfriedlaender/gist:1273614
Lighten or darken a hexadecimal color (string)
# Amount should be a decimal between 0 and 1. Lower means darker
def darken_color(hex_color, amount=0.4)
hex_color = hex_color.gsub('#','')
rgb = hex_color.scan(/../).map {|color| color.hex}
rgb[0] = (rgb[0].to_i * amount).round
rgb[1] = (rgb[1].to_i * amount).round
rgb[2] = (rgb[2].to_i * amount).round
"#%02x%02x%02x" % rgb
end
@lipowen
lipowen / exporter.rb
Created October 3, 2019 02:55 — forked from chad/exporter.rb
Export ActiveRecord Tables to CSV
require 'csv'
module Exporter
DEFAULT_EXPORT_TABLES = [ Invoice, InvoiceItem, Item, Merchant, Transaction, User ]
DESTINATION_FOLDER = "tmp/"
def self.included(klass)
klass.extend ClassLevelMethods
end
@lipowen
lipowen / ruby.json
Last active August 18, 2018 04:56
Debug with pry in VSCODE
{
// Place your snippets for Ruby here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
"Debug with pry": {
"prefix": "pry",
"body": [
@lipowen
lipowen / benchmark.rb
Created May 3, 2017 11:15 — forked from timurvafin/benchmark.rb
Faraday adapters benchmark
#!/usr/bin/env ruby
require 'bundler/setup'
require 'byebug'
require 'faraday'
require 'faraday-request-timer'
require 'faraday_middleware'
require 'excon'
@lipowen
lipowen / excon benchmark
Created May 3, 2017 08:25 — forked from phiggins/excon benchmark
excon benchmark vs google
$ ruby benchmarks/excon_vs_google.rb
[em-http-request, HTTParty, Net::HTTP, Net::HTTP (persistent), open-uri, RestClient, StreamlyFFI (persistent), Typhoeus, Excon, Excon (persistent)]
+--------------------------+-----------+
| tach | total |
+--------------------------+-----------+
| Excon | 7.614298 |
+--------------------------+-----------+
| Typhoeus | 7.723362 |
@lipowen
lipowen / .tmux.conf
Last active April 17, 2017 09:25
tmux config
unbind C-b
set -g prefix C-s
bind-key -r C-s send-prefix
# improve colors
set -g default-terminal 'screen-256color'
# reload tmux.conf
bind-key r source-file ~/.tmux.conf \; display-message "~/.tmux.conf reloaded"
@lipowen
lipowen / pr.md
Created March 24, 2017 08:51 — forked from piscisaureus/pr.md
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@lipowen
lipowen / rspec_rails_cheetsheet.rb
Created April 1, 2016 03:48 — forked from them0nk/rspec_rails_cheetsheet.rb
Rspec Rails cheatsheet (include capybara matchers)
#Model
@user.should have(1).error_on(:username) # Checks whether there is an error in username
@user.errors[:username].should include("can't be blank") # check for the error message
#Rendering
response.should render_template(:index)
#Redirecting
response.should redirect_to(movies_path)
@lipowen
lipowen / capybara cheat sheet
Created March 25, 2016 06:27 — forked from zhengjia/capybara cheat sheet
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')