Skip to content

Instantly share code, notes, and snippets.

@geoffyoungs
geoffyoungs / add_gem_path.rb
Created November 9, 2022 15:05
Side load a gem that's not in Gemfile
module GemSideLoad
class << self
attr_accessor :last
end
module Gem
VERSION = '1.0.0'
Requirement = Struct.new(:wat)
Version = Struct.new(:version)
class Version
def >=(other)
@geoffyoungs
geoffyoungs / compile_webp_with_mini_portile2.patch
Created October 25, 2022 19:51
Patch webp-ffi to install libwebp using mini_portile2
diff --git a/Rakefile b/Rakefile
index 67b32ec..e5d2660 100644
--- a/Rakefile
+++ b/Rakefile
@@ -5,13 +5,27 @@ require 'rake/clean'
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require 'ffi-compiler/compile_task'
+require 'mini_portile2'
+
@geoffyoungs
geoffyoungs / http_to_curl_command.rb
Created March 25, 2021 15:54
convert ruby Net::HTTP::Get to curl command line
require 'shellwords'
def curl_command(uri, http_get)
curl = ['curl', '--http1.1']
http_get.each_capitalized do |h,v|
case h
when 'User-Agent'
curl << '--user-agent' << v
else
curl << '-H' << "#{h}: #{v}"
@geoffyoungs
geoffyoungs / find-box.rb
Created July 24, 2015 09:27
Find the maximum active box from a selection of images and crop them all to a square that attempts to centre the active area
#!/usr/bin/env ruby
require 'gdk_pixbuf2'
require 'fileutils'
# arg : String : filename
# sensitivity : Integer : greyscale distance between pixels for this to be considered an edge
# scale_to : Integer : max dimension (images are scaled down for performance reasons)
#
# Scales image down and then runs a simple edge detection algorithm in order to detect the active area
@geoffyoungs
geoffyoungs / no-files-changed-by-version.sh
Created November 29, 2011 11:10
Compare no of files changed in each version in git
#!/bin/bash
git tag | ruby -e 'a=b=nil;loop { a, b=ARGF.gets, a; a and b and (STDOUT << "#{a.strip} : ") and system("git diff --name-status #{b.strip} #{a.strip}| wc -l"); a.nil? and b.nil? and break }'
@geoffyoungs
geoffyoungs / animate.css
Created October 28, 2011 20:15
Animated graduated background
@-webkit-keyframes pulsate {
0% {
background-position: 0 0;
}
100% {
background-position: 300px 0;
}
}
div.animated {
@geoffyoungs
geoffyoungs / pack-cell-renderers.rb
Created September 21, 2011 08:06
Include multiple CellRenderers in a single TreeView column
#!/usr/bin/env ruby
# See http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3ATreeViewColumn
# for more details on Gtk::TreeViewColumn
require 'gtk2'
require 'base64'
win = Gtk::Window.new("Multiple cells in a column")
win.signal_connect('delete-event') { Gtk.main_quit }
def grad_vl(y1,y2,col1=nil,col2=nil,&block)
pattern= Cairo::LinearPattern.new(0, y1, 0, y2)
{0=>col1,1=>col2}.each do |offset, col|
next unless col
case col.size
when 3
pattern.add_color_stop_rgb(offset, *col)
when 4
pattern.add_color_stop_rgba(offset, *col)
end
@geoffyoungs
geoffyoungs / cairo-pango-fancy-text.rb
Created March 11, 2011 13:45
Simple text effects for cairo/pango rendered text
require 'cairo'
require 'pango'
width, height = 600, 600
surface = Cairo::ImageSurface.new(:argb32, width, height)
cr = Cairo::Context.new(surface)
cr.save do
@geoffyoungs
geoffyoungs / stuts-car.rb
Created January 4, 2011 17:53
Dream Cheeky Mini RC Control from linux
require 'usb'
require 'pp'
class StutsCar
attr_reader :handle
def initialize(handle)
@handle = handle
@handle.public_methods(false)
@handle.usb_detach_kernel_driver_np(0, 0) rescue nil
@handle.usb_claim_interface(0) rescue nil