Skip to content

Instantly share code, notes, and snippets.

View eltiare's full-sized avatar

Jeremy Nicoll eltiare

View GitHub Profile
@eltiare
eltiare / interleave.rb
Created January 15, 2011 22:10
Interleaves another array into the current one, returns a new array
class Array
def interleave(other)
arr = []
size.times { |i| arr << self[i]; arr << other[i] unless i + 1 > other.size }
left = other[size - 1 .. -1]
arr += left if left
arr
end
end
@eltiare
eltiare / view-hack.rb
Created January 26, 2011 03:36
Hacking Sinatra's views to make organization easier when using multiple apps.
require 'sinatra/base'
class Kazoo::Sinatra < Sinatra::Base
def render(engine, data, options = {}, *args)
if !options[:views] && data.is_a?(Symbol) && !data.to_s.match('/')
data = :"#{decamelize(self.class.name)}/#{data}"
options[:layout] ||= :'layouts/application'
end
@eltiare
eltiare / simple-slideshow.html
Created March 6, 2011 07:46
An easy way to rotate images in a slideshow via jQuery
<html>
<head>
<title>Simple Slideshow</title>
<style type='text/css'>
#slideshow { position: relative; }
#slideshow img { position: absolute; top: 0; left: 0; }
</style>
<script src="jquery.js" type="text/javascript"></script>
<script type="text/javascript">
var image_counter = -1;
@eltiare
eltiare / runthis.sh
Created April 6, 2011 21:54
Bash script to use the Rails' runner action via cron
#!/bin/bash
cd `dirname $0`/../
rails runner script/${1}.rb
@eltiare
eltiare / abuse.rb
Created November 22, 2011 04:26
Is this DRY or just plain abuse? :)
@users = User.all(if params[:verified]
{ needs_verification: false }
elsif params[:admin]
{ User.roles.name => 'admin' }
else
{ needs_verification: true }
end)
@eltiare
eltiare / gist:3055805
Created July 5, 2012 19:16
vips-ruby segfault
screamer:carrierwave-vips eltiare$ rspec
(rspec:2129): GLib-CRITICAL **: g_hash_table_lookup: assertion `hash_table != NULL' failed
(rspec:2129): GLib-GObject-WARNING **: cannot retrieve class for invalid (unclassed) type `<invalid>'
/Users/eltiare/.rvm/gems/ruby-1.9.3-p194/gems/ruby-vips-0.2.0/lib/vips_ext.bundle: [BUG] Segmentation fault
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.3.0]
-- Control frame information -----------------------------------------------
c:0023 p:-17580534911092 s:0068 b:0068 l:000067 d:000067 TOP
@eltiare
eltiare / carrierwave_config.rb
Created July 18, 2012 16:47
Example of a CarrierWave S3 configuration
# Here's what I have in my CarrierWave configuration file
require 'carrierwave/processing/mime_types'
CarrierWave.configure do |config|
config.fog_credentials = {
:provider => 'AWS', # required
:aws_access_key_id => 'REPLACE WITH AWS KEY', # required
:aws_secret_access_key => 'REPLACE WITH AWS SECRET' # required
}
@eltiare
eltiare / brew-vips-install-fail
Created August 2, 2012 00:12
Fail log of brew install vips
This file has been truncated, but you can view the full file.
screamer:carrierwave-vips eltiare$ brew install vips -HEAD
==> Downloading http://www.vips.ecs.soton.ac.uk/supported/current/vips-7.28.0.tar.gz
Already downloaded: /Library/Caches/Homebrew/vips-7.28.0.tar.gz
==> ./configure --prefix=/usr/local/Cellar/vips/7.28.0
==> make install
Making install in libvips
Making install in include
Making install in vips
glib-mkenums --template enumtemplate \
../../../libvips/include/vips/memory.h ../../../libvips/include/vips/foreign.h ../../../libvips/include/vips/arithmetic.h ../../../libvips/include/vips/conversion.h ../../../libvips/include/vips/util.h ../../../libvips/include/vips/image.h ../../../libvips/include/vips/object.h > xgen-geth && \
@eltiare
eltiare / ruby-vips crash.txt
Created September 10, 2012 23:59
Crash from ruby-vips
eltiare@debian:~/apps/rballey$ rails c
Loading development environment (Rails 3.2.8)
1.9.3p194 :001 > img = VIPS::JPEGReader.new('spec/fixtures/butterfly.jpg')
=> #<VIPS::JPEGReader:0x000000041154a0>
1.9.3p194 :003 > img.exif?
(irb):3: [BUG] Segmentation fault
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
-- Control frame information -----------------------------------------------
c:0029 p:---- s:0103 b:0103 l:000102 d:000102 CFUNC :exif?
@eltiare
eltiare / copy-to-s3.rb
Created November 22, 2012 18:34
Multithreaded file copying to S3 via Fog and JRuby
#!/usr/bin/env jruby
# Usage:
# Save this file to /usr/local/bin/copy-to-s3.rb
# You'll want to chmod +x this file to use it on the command line (Linux/OS X: chmod +x /usr/local/bin/copy-to-s3.rb)
# If you're having trouble using JRuby, check out RVM (https://rvm.io/)
# Install the fog gem: gem install fog (after running rvm use jruby, if required)
# This only works if the environment variable JRUBY_OPTS=--1.8. e.g.: export JRUBY_OPTS=--1.8 (Linux/OS X)
# You'll have to edit the options in the file at the top to match your S3 settings.
#