Skip to content

Instantly share code, notes, and snippets.

View westonganger's full-sized avatar

Weston Ganger westonganger

View GitHub Profile
config.ignore_if do |exception, options|
# use beginning to prevent non unique keys (they include object ids and such)
key = exception.message.split("for").first[0..30]
ExpirableKey.new(key).exist_with_renew
end
@samrocketman
samrocketman / libimobiledevice_ifuse_Ubuntu.md
Last active January 11, 2024 22:47
On Ubuntu 16.04, since iOS 10 update, libimobiledevice can't connect to my iPhone. This is my attempt to document a fix.

Why this document?

I upgraded my iPhone 5s to iOS 10 and could no longer retrieve photos from it. This was unacceptable for me so I worked at achieving retrieving my photos. This document is my story (on Ubuntu 16.04).

The solution is to compile libimobiledevice and ifuse from source.

Audience

Who is this guide intended for?

@arteezy
arteezy / puma.service
Last active May 9, 2024 22:22
Manage Puma with systemd and rbenv
[Unit]
Description=Puma Rails Server
After=network.target
[Service]
Type=simple
User=deploy
WorkingDirectory=/home/deploy/app/current
ExecStart=/home/deploy/.rbenv/bin/rbenv exec bundle exec puma -C /home/deploy/app/shared/config/puma.rb
ExecStop=/home/deploy/.rbenv/bin/rbenv exec bundle exec pumactl -S /home/deploy/app/shared/tmp/pids/puma.state stop
@westonganger
westonganger / or_scopes.rb
Created May 27, 2016 01:19 — forked from craigweston/or_scopes.rb
OR'ing scopes
module ActiveRecord
module Querying
delegate :or, :to => :all
end
end
module ActiveRecord
module QueryMethods
# OrChain objects act as placeholder for queries in which #or does not have any parameter.
# In this case, #or must be chained with any other relation method to return a new relation.
@westonganger
westonganger / Get Previous Route in Rails
Last active March 30, 2023 05:06
Get Previous Route in Rails 3/4+ App
ApplicationController < ActionController::Base
after_filter :set_route_info
def set_route_info
session[:return_to] = request.url
prev_route = Rails.application.routes.recognize_path(URI(session[:return_to]).path)
session[:previous_controller] = prev_route[:action]
npm_global_path = File.join(system("npm config get prefix"), "lib/node_modules")
file_name = File.join(npm_global_path, "ionic/lib/tasks/cliTasks.js")
File.open(file_name, 'r+') do |f|
orig_str = "'--splash|-s': {"
str = "'--ignore-cache|-c': { title: 'Ignoring cached resources', boolean: true },#{orig_str}"
f.write File.read(file_name).gsub(orig_str, str)
end
file_name = File.join(npm_global_path, "ionic/node_modules/ionic-app-lib/lib/resources.js")
@hopsoft
hopsoft / benchmarks.rb
Last active June 11, 2020 14:27
Ruby 2.3 safe navigation `&.` vs Active Support's try
require "benchmark"
require "active_support/all"
Benchmark.bm do |x|
count = 1_000_000
label_size = 20
x.report "check for nil:".rjust(label_size) do
count.times { nil && nil.length }
end
@xrstf
xrstf / letsencrypt.md
Last active April 18, 2023 05:01
Let's Encrypt on Ubuntu 14.04, nginx with webroot auth

Let's Encrypt on Ubuntu 14.04, nginx with webroot auth

This document details how I setup LE on my server. Firstly, install the client as described on http://letsencrypt.readthedocs.org/en/latest/using.html and make sure you can execute it. I put it in /root/letsencrypt.

As it is not possible to change the ports used for the standalone authenticator and I already have a nginx running on port 80/443, I opted to use the webroot method for each of my domains (note that LE does not issue wildcard certificates by design, so you probably want to get a cert for www.example.com and example.com).

Configuration

For this, I placed config files into etc/letsencrypt/configs, named after <domain>.conf. The files are simple:

@rob-murray
rob-murray / find_dups.rb
Created October 27, 2015 09:59
Rails find duplicate records
columns_that_make_record_distinct = [:some_id, :another_name]
distinct_ids = Model.select("MIN(id) as id").group(columns_that_make_record_distinct).map(&:id)
duplicate_records = Model.where.not(id: distinct_ids)
@nassredean
nassredean / lookahead.rb
Created October 23, 2015 15:54
Prawn Lookahead Height
require "prawn"
@pdf = Prawn::Document.new(margin: 0)
@text = "Oh hai text rect. " * 10
@options = { :document => @pdf }
text_box = Prawn::Text::Box.new(@text, @options)
p "cursor before dry run: #{@pdf.cursor}"
p "whats the height before dry run?"
p "....who knows????" if text_box.height == 0