Skip to content

Instantly share code, notes, and snippets.

@dhh
dhh / Gemfile
Created June 24, 2020 22:23
HEY's Gemfile
ruby '2.7.1'
gem 'rails', github: 'rails/rails'
gem 'tzinfo-data', '>= 1.2016.7' # Don't rely on OSX/Linux timezone data
# Action Text
gem 'actiontext', github: 'basecamp/actiontext', ref: 'okra'
gem 'okra', github: 'basecamp/okra'
# Drivers
@archy-bold
archy-bold / set-access-point.sh
Last active February 10, 2023 08:44
Script to find the access points for the given network SSID and set the BSSID for that network to the MAC of the access point with the highest strength
#!/bin/bash
# Usage: ./set-access-points.sh [network SSID] [network interface id = wlan0]
# Read in the arguements
ssid=$1;
interface=$2;
# SSID is required
if [ -z "$ssid" ]; then
@VvanGemert
VvanGemert / bulk_reindexer.rb
Created July 2, 2017 12:23
Asynchronous bulk reindexing module for Searchkick with Sidekiq
require 'sidekiq/api'
# BulkReindexer
module BulkReindexer
def self.reindex_model(model, promote_and_clean = true)
puts "Reindexing #{model.name}..."
index = model.reindex(async: true, refresh_interval: '30s')
puts "All jobs are in queue. Index name: #{index[:index_name]}"
loop do
# Check the size of queue
@KamilLelonek
KamilLelonek / curry.rb
Last active November 20, 2019 23:14
Currying functions in Ruby
[1] (pry) main: 0> add = -> (a, b) { a + b }
=> #<Proc:0x007ffde11d72c0@(pry):1 (lambda)>
# Call proc with two arguments
[2] (pry) main: 0> add.(1, 2)
=> 3
# Call proc with one argument
[3] (pry) main: 0> add.(1)
ArgumentError: wrong number of arguments (1 for 2)
@sqrtsanta
sqrtsanta / activity_finder.rb
Created April 22, 2015 11:33
Preload associations of polymorphic objects
class ActivityFinder
attr_reader :activities, :user
def initialize(user)
@user = user
@activities = Activity.all.where(:user_id => user_ids).
with_subject.with_user.desc
activities.group_by(&:subject_type).each do |name, group|
@bendilley
bendilley / trace.rb
Created February 10, 2015 17:41
Get a trace from a 'stack too deep' error in Rails
$enable_tracing = false
#$trace_out = File.open(Rails.root + 'trace.txt', 'w')
set_trace_func proc { |event, file, line, id, binding, classname|
if $enable_tracing && event == 'call'
#$trace_out.puts "#{file}:#{line} #{classname}##{id}"
raise "crash me" if caller_locations.length > 500
end
}
@ginjo
ginjo / gist:aaa4a4395fcdbbad3d29
Last active December 1, 2019 08:32 — forked from bkimble/gist:1365005
Get structured array of hashes of memcached keys on multiple servers
#!/usr/bin/env ruby
# List all keys stored in memcache.
# Forked from bkimble's gist https://gist.github.com/bkimble/1365005
# Credit to Graham King at http://www.darkcoding.net/software/memcached-list-all-keys/ for the original article on how to get the data from memcache in the first place.
# Currently resides at https://gist.github.com/ginjo/aaa4a4395fcdbbad3d29
#
# This fork separates the server query code from results presentation.
# The primary function of this script is to return an array of hashes of
# key items from any number of provided memcached servers.
@skanev
skanev / rubocop.rb
Last active March 13, 2024 08:24
A Rubocop wrapper that checks only added/modified code
#!/usr/bin/env ruby
# A sneaky wrapper around Rubocop that allows you to run it only against
# the recent changes, as opposed to the whole project. It lets you
# enforce the style guide for new/modified code only, as opposed to
# having to restyle everything or adding cops incrementally. It relies
# on git to figure out which files to check.
#
# Here are some options you can pass in addition to the ones in rubocop:
#
@mmintel
mmintel / gist:045ffce76b00b327bfc0
Last active October 12, 2020 10:34
BEM mixins in Sass 3.4
$elementSeparator: '__';
$modifierSeparator: '--';
@function containsModifier($selector) {
$selector: selectorToString($selector);
@if str-index($selector, $modifierSeparator) {
@return true;
} @else {
@return false;
}
@adrianorsouza
adrianorsouza / mkselfssl.sh
Last active September 1, 2023 10:34
Script to create a new self-signed SSL Certificate for Nginx
#!/bin/bash
# @author Adriano Rosa (http://adrianorosa.com)
# @date: 2014-05-13 09:43
#
# Bash Script to create a new self-signed SSL Certificate
# At the end of creating a new Certificate this script will output a few lines
# to be copied and placed into NGINX site conf
#
# USAGE: this command will ask for the certificate name and number in days it will expire