Skip to content

Instantly share code, notes, and snippets.

View eltiare's full-sized avatar

Jeremy Nicoll eltiare

View GitHub Profile
@eltiare
eltiare / ss
Created October 24, 2013 23:11
A quick and dirty server script written in Ruby
#!/usr/bin/env ruby
require 'webrick'
include WEBrick
port = ARGV[0] || 4567
puts "Starting server: http://#{Socket.gethostname}:#{port}"
server = HTTPServer.new(:Port=>port,:DocumentRoot=>Dir::pwd )
trap("INT"){ server.shutdown }
server.start
@eltiare
eltiare / viewport-auto-scaler.js
Created August 16, 2013 17:20
Shameless stolen from here: http://stackoverflow.com/questions/15687276/pixels-in-css-vs-pixel-density This is used to account for various DPI differences in mobile devices for web pages. Put this in a script tag or a *.js file and include it in your document.
(function() {
var meta = document.createElement("meta");
meta.setAttribute('name','viewport');
meta.setAttribute('content', 'initial-scale=' + (1 / window.devicePixelRatio) + ',user-scalable=no');
document.getElementsByTagName('head')[0].appendChild(meta);
})();
@eltiare
eltiare / jquery-object-serializer.js
Last active December 20, 2015 22:38
An object serializer for jQuery. I don't know why this isn't already a thing...
(function($) {
$.fn.serializeObject = function() {
var arr = this.serializeArray(), a, ret = {};
$.each(arr, function(i, a) { ret[a.name] = a.value; });
return ret;
}
})(jQuery);
@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.
#
@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 / 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 / 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 / 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 / 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 / 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