Skip to content

Instantly share code, notes, and snippets.

Avatar

Jeremy Nicoll eltiare

View GitHub Profile
@eltiare
eltiare / ss
Created Oct 24, 2013
A quick and dirty server script written in Ruby
View ss
#!/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 Aug 16, 2013
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.
View viewport-auto-scaler.js
(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 Dec 20, 2015
An object serializer for jQuery. I don't know why this isn't already a thing...
View jquery-object-serializer.js
(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 Nov 22, 2012
Multithreaded file copying to S3 via Fog and JRuby
View copy-to-s3.rb
#!/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 Sep 10, 2012
Crash from ruby-vips
View ruby-vips crash.txt
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 Aug 2, 2012
Fail log of brew install vips
View brew-vips-install-fail
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 \
@eltiare
eltiare / carrierwave_config.rb
Created Jul 18, 2012
Example of a CarrierWave S3 configuration
View carrierwave_config.rb
# 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 Jul 5, 2012
vips-ruby segfault
View gist:3055805
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 Nov 22, 2011
Is this DRY or just plain abuse? :)
View abuse.rb
@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 Apr 6, 2011
Bash script to use the Rails' runner action via cron
View runthis.sh
#!/bin/bash
cd `dirname $0`/../
rails runner script/${1}.rb
You can’t perform that action at this time.