Skip to content

Instantly share code, notes, and snippets.

@mikbe
mikbe / thread_safe.rb
Created June 17, 2011 13:30
Stops collisions but it's ugly
require 'thread'
module ThreadSafe
def self.included(base)
base.extend(ThreadSafeClassMethods)
base.threadsafe_class_mutex = Mutex.new
end
module ThreadSafeClassMethods
@mikbe
mikbe / nokogiri_sucks.txt
Last active July 10, 2016 04:07
How to install Nokogiri
## Do this before doing bundle install
# Make sure you have Xcode installed with command line utilities.
# Install Home Brew (if you already have it installed update it):
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew update --system
brew update
@mikbe
mikbe / FriendlyChgDir.sh
Created February 15, 2013 21:48
A friendlier change directory for Bash and OS X.
# Change to a directory given a full or partial name
# You don't have to wrap directory names in quotes either
function chd() {
friendlyChgDirOptions
if [ -n "$1" ]; then
if [ -n "`ls "$@"* 2>/dev/null`" ]; then
cd "$1"*
else
echo "-bash: chd: "$1": No directory found from partial name"
@mikbe
mikbe / CaseInsensitiveBash.sh
Created February 15, 2013 21:22
Make Bash case insensitive when globbing (using wildcards)
shopt -s nocaseglob
@mikbe
mikbe / gist:4945780
Created February 13, 2013 16:23
Download all Railscast Pro and regular episodes (if you have a subscription)
#!/usr/bin/env ruby
require 'rss'
require 'open-uri'
require 'net/http'
# Your subscription ID
sub_id = "xxx"
url = "http://railscasts.com/subscriptions/#{sub_id}/episodes.rss"
puts "Reading RSS"
@mikbe
mikbe / gist:2974686
Created June 22, 2012 19:42
Storyline index file example
<!-- index.html -->
<html>
<head>
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
<META HTTP-EQUIV="EXPIRES" CONTENT="0">
<META HTTP-EQUIV="REFRESH" CONTENT="0;https://mywebsite.com/ab.007/story.html">
<script type="text/javascript">
window.location = "https://mywebsite.com/ab.007/story.html"
</script>
@mikbe
mikbe / fiber.rb
Created July 28, 2011 09:35
Fiber Creation
#!/usr/bin/env ruby
#Thread.abort_on_exception = true
require 'fiber'
require 'benchmark'
class FiberRing
attr_reader :id
def initialize(id)
@id = id
@mikbe
mikbe / cairo.h.rb
Created July 10, 2011 15:27
Cairo.h converted to FFI
CAIRO_VERSION_STRING = CAIRO_VERSION_MAJOR.CAIRO_VERSION_MINOR.CAIRO_VERSION_MICRO
attach_function :cairo_version, [ ], :int
attach_function :cairo_version_string, [ ], :string
class CairoMatrix < FFI::Struct
layout(
:xx, :double,
:yx, :double,
:xy, :double,
:yy, :double,
:x0, :double,
@mikbe
mikbe / foo.rb
Created July 9, 2011 14:47
FFI testing
require "ffi"
class TimeValue < FFI::Struct
layout :seconds, :int,
:microseconds, :int
end
#struct task_basic_info
#{
# integer_t suspend_count;
@mikbe
mikbe / foo.c
Created July 9, 2011 14:36
Sample task info for current task
#include <stdio.h>
#include <mach/mach_init.h>
#include <mach/mach_port.h>
#include <mach/task_info.h>
#include <mach/thread_act.h>
#include <mach/vm_map.h>
#include <mach/task.h>
#include <sys/types.h>