Skip to content

Instantly share code, notes, and snippets.

View crohr's full-sized avatar
➡️
Cheaper, faster GitHub Actions with runs-on.com

Cyril Rohr crohr

➡️
Cheaper, faster GitHub Actions with runs-on.com
View GitHub Profile
me@redacted:~$ python
Python 2.7.3 (default, Mar 14 2014, 11:57:14)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
>>>
[1]+ Stopped python
me@redacted:~$ ps
PID TTY TIME CMD
24815 pts/1 00:00:00 bash
class Ticket < ActiveRecord::Base
belongs_to :grouper
belongs_to :user
validate :user_cant_be_blacklisted, on: :confirmation
validate :user_cant_double_book, on: :confirmation
validate :grouper_cant_be_full, on: :confirmation
validate :grouper_cant_have_occurred, on: :confirmation
@thbar
thbar / maintenance.rake
Created November 28, 2013 10:10
Quick, slow, dirty way to verify how aged your gems are.
task :outdated => :environment do
include ActionView::Helpers::DateHelper
regexp = /\* ([^ ]+) \((\S+) > ([^)]+)\)/
outdated = `bundle outdated`.scan(regexp)
outdated.each do |gem_name, available, current|
data = JSON.parse(`curl --silent https://rubygems.org/api/v1/versions/#{gem_name}.json`)
version = data.find { |e| e['number'] == current }
age = distance_of_time_in_words_to_now(Time.parse(version['built_at']))
puts " * #{gem_name}: (#{available} > #{current}, built #{age} ago)"
end
@bf4
bf4 / hl
Last active December 28, 2015 16:49
highlight files
#!/usr/bin/env ruby
# Bonus: place in PATH and use from the command line.
# Usage:
# find path -type f | xargs ruby highlight.rb
# gem contents metric_fu | grep lib | xargs ruby highlight.rb
# The highlighted code will be output to 'output.html' in the working directory
require 'coderay'
class Highlighter
def initialize
@flomotlik
flomotlik / gist:6212725
Last active November 13, 2017 18:46
Wget Curl comparison and our Approach

We have changed our check_url implementation from curl to wget for three reasons

  1. It gives us the ability to retry on connection refused. Compare the command we used previously with curl:
curl -sSfL --retry 3 URL

to the current one:

# A program that works jobs in newly created UNIX
# process by calling fork. The number of processes
# running at any given time is bounded by our use
# of a sized queue.
require 'thread'
# Run at most 4 UNIX processes for any given time.
@limiter = SizedQueue.new(4)
@roidrage
roidrage / wrap.rb
Last active May 3, 2018 04:46
A simple wrapper that forks off a child and prints out a progress dot every X seconds
#!/usr/bin/env ruby
pid = Kernel.fork do
`#{ARGV.join(" ")}`
exit
end
trap(:CHLD) do
print "\n"
exit
require 'connection_pool'
require 'redis'
require 'metriks'
class RedisClientWrapper
def initialize(options)
@options = options.delete(:pool)
@pool = ConnectionPool.new(@options) do
::Redis.new(options)
end
@dergachev
dergachev / GIF-Screencast-OSX.md
Last active April 20, 2025 21:14
OS X Screencast to animated GIF

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:

anonymous
anonymous / concerning.rb
Created December 18, 2012 18:00
class Module
# We often find ourselves with a medium-sized chunk of behavior that we'd
# like to extract, but only mix in to a single class.
#
# We typically choose to leave the implementation directly in the class,
# perhaps with a comment, because the mental and visual overhead of defining
# a module, making it a Concern, and including it is just too great.
#
#
# Using comments as lightweight modularity: