Skip to content

Instantly share code, notes, and snippets.

Jonathan Rochkind jrochkind

Block or report user

Report or block jrochkind

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jrochkind
jrochkind / gist:2161449
Created Mar 22, 2012
A Capistrano Rails Guide
View gist:2161449

A Capistrano Rails Guide

by Jonathan Rochkind, http://bibwild.wordpress.com

why cap?

Capistrano automates pushing out a new version of your application to a deployment location.

I've been writing and deploying Rails apps for a while, but I avoided using Capistrano until recently. I've got a pretty simple one-host deployment, and even though everyone said Capistrano was great, every time I tried to get started I just got snowed under not being able to figure out exactly what I wanted to do, and figured I wasn't having that much trouble doing it "manually".

@jrochkind
jrochkind / gist:59b6330e3f52710cc49e
Last active Sep 4, 2018
Monkey patch to ActiveRecord to forbid
View gist:59b6330e3f52710cc49e
######################
#
# Monkey patch to ActiveRecord to prevent 'implicit' checkouts. Currently tested with Rails 4.0.8, prob
# should work fine in Rails 4.1 too.
#
# If you create a thread yourself, if it uses ActiveRecord objects without
# explicitly checking out a connection, one will still be checked out implicitly.
# If it is never checked back in with `ActiveRecord::Base.clear_active_connections!`,
# then it will be leaked.
#
@jrochkind
jrochkind / gist:2636355
Created May 8, 2012
reddit 'hot' algorithm, in ruby, with typo fixed
View gist:2636355
require 'date'
# Actually doesn't matter WHAT you choose as the epoch, it
# won't change the algorithm. Just don't change it after you
# have cached computed scores. Choose something before your first
# post to avoid annoying negative numbers. Choose something close
# to your first post to keep the numbers smaller. This is, I think,
# reddit's own epoch.
$our_epoch = Time.local(2005, 12, 8, 7, 46, 43).to_time
View char_investigation_output.txt
expected Lu category: 1415
Lt (31)
Dž,Lj,Nj,Dz,ᾈ,ᾉ,ᾊ,ᾋ,ᾌ,ᾍ,ᾎ,ᾏ,ᾘ,ᾙ,ᾚ,ᾛ,ᾜ,ᾝ,ᾞ,ᾟ,ᾨ,ᾩ,ᾪ,ᾫ,ᾬ,ᾭ,ᾮ,ᾯ,ᾼ,ῌ,ῼ
no_categories_found (105)
Ϳ,Ԩ,Ԫ,Ԭ,Ԯ,Ᏽ,Ꚙ,Ꚛ,Ꞗ,Ꞙ,Ꞛ,Ꞝ,Ꞟ,Ɜ,Ɡ,Ɬ,Ʞ,Ʇ,Ʝ,Ꭓ,Ꞵ,Ꞷ,𐲀,𐲁,𐲂,𐲃,𐲄,𐲅,𐲆,𐲇,𐲈,𐲉,𐲊,𐲋,𐲌,𐲍,𐲎,𐲏,𐲐,𐲑,𐲒,𐲓,𐲔,𐲕,𐲖,𐲗,𐲘,𐲙,𐲚,𐲛,𐲜,𐲝,𐲞,𐲟,𐲠,𐲡,𐲢,𐲣,𐲤,𐲥,𐲦,𐲧,𐲨,𐲩,𐲪,𐲫,𐲬,𐲭,𐲮,𐲯,𐲰,𐲱,𐲲,𑢠,𑢡,𑢢,𑢣,𑢤,𑢥,𑢦,𑢧,𑢨,𑢩,𑢪,𑢫,𑢬,𑢭,𑢮,𑢯,𑢰,𑢱,𑢲,𑢳,𑢴,𑢵,𑢶,𑢷,𑢸,𑢹,𑢺,𑢻,𑢼,𑢽,𑢾,𑢿
Lo (85)
View investigate_char_properties.rb
require 'twitter_cldr'
chars = "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮİIJĴĶĹĻĽĿŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŸŹŻŽƁƂƄƆƇƉƊƋƎƏƐƑƓƔƖƗƘƜƝƟƠƢƤƦƧƩƬƮƯƱƲƳƵƷƸƼDŽDžLJLjNJNjǍǏǑǓǕǗǙǛǞǠǢǤǦǨǪǬǮDZDzǴǶǷǸǺǼǾȀȂȄȆȈȊȌȎȐȒȔȖȘȚȜȞȠȢȤȦȨȪȬȮȰȲȺȻȽȾɁɃɄɅɆɈɊɌɎͰͲͶͿΆΈΉΊΌΎΏΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩΪΫϏϒϓϔϘϚϜϞϠϢϤϦϨϪϬϮϴϷϹϺϽϾϿЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯѠѢѤѦѨѪѬѮѰѲѴѶѸѺѼѾҀҊҌҎҐҒҔҖҘҚҜҞҠҢҤҦҨҪҬҮҰҲҴҶҸҺҼҾӀӁӃӅӇӉӋӍӐӒӔӖӘӚӜӞӠӢӤӦӨӪӬӮӰӲӴӶӸӺӼӾԀԂԄԆԈԊԌԎԐԒԔԖԘԚԜԞԠԢԤԦԨԪԬԮԱԲԳԴԵԶԷԸԹԺԻԼԽԾԿՀՁՂՃՄՅՆՇՈՉՊՋՌՍՎՏՐՑՒՓՔՕՖႠႡႢႣႤႥႦႧႨႩႪႫႬႭႮႯႰႱႲႳႴႵႶႷႸႹႺႻႼႽႾႿჀჁჂჃჄჅჇჍᎠᎡᎢᎣᎤᎥᎦᎧᎨᎩᎪᎫᎬᎭᎮᎯᎰᎱᎲᎳᎴᎵᎶᎷᎸᎹᎺᎻᎼᎽᎾᎿᏀᏁᏂᏃᏄᏅᏆᏇᏈᏉᏊᏋᏌᏍᏎᏏᏐᏑᏒᏓᏔᏕᏖᏗᏘᏙᏚᏛᏜᏝᏞᏟᏠᏡᏢᏣᏤᏥᏦᏧᏨᏩᏪᏫᏬᏭᏮᏯᏰᏱᏲᏳᏴᏵḀḂḄḆḈḊḌḎḐḒḔḖḘḚḜḞḠḢḤḦḨḪḬḮḰḲḴḶḸḺḼḾṀṂṄṆṈṊṌṎṐṒṔṖṘṚṜṞṠṢṤṦṨṪṬṮṰṲṴṶṸṺṼṾẀẂẄẆẈẊẌẎẐẒẔẞẠẢẤẦẨẪẬẮẰẲẴẶẸẺẼẾỀỂỄỆỈỊỌỎỐỒỔỖỘỚỜỞỠỢỤỦỨỪỬỮỰỲỴỶỸỺỼỾἈἉἊἋἌἍἎἏἘἙἚἛἜἝἨἩἪἫἬἭἮἯἸἹἺἻἼἽἾἿὈὉὊὋὌὍὙὛὝὟὨὩὪὫὬὭὮὯᾈᾉᾊᾋᾌᾍᾎᾏᾘᾙᾚᾛᾜᾝᾞᾟᾨᾩᾪᾫᾬᾭᾮᾯᾸᾹᾺΆᾼῈΈῊΉῌῘῙῚΊῨῩῪΎῬῸΌῺΏῼℂℇℋℌℍℐℑℒℕℙℚℛℜℝℤΩℨKÅℬℭℰℱℲℳℾℿⅅⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫⅬⅭⅮⅯↃⒶⒷⒸⒹⒺⒻⒼⒽⒾⒿⓀⓁⓂⓃⓄⓅⓆⓇⓈⓉⓊⓋⓌⓍⓎⓏⰀⰁⰂⰃⰄⰅⰆⰇⰈⰉⰊⰋⰌⰍⰎⰏⰐⰑⰒⰓⰔⰕⰖⰗⰘⰙⰚⰛⰜⰝⰞⰟⰠⰡⰢⰣⰤⰥⰦⰧⰨⰩⰪⰫⰬⰭⰮⱠⱢⱣⱤⱧⱩⱫⱭⱮⱯⱰⱲⱵⱾⱿⲀⲂⲄⲆⲈⲊⲌⲎⲐⲒⲔⲖⲘⲚⲜⲞⲠⲢⲤⲦⲨⲪⲬⲮⲰⲲⲴⲶⲸⲺⲼⲾⳀⳂⳄⳆⳈⳊⳌⳎⳐⳒⳔⳖⳘⳚⳜⳞⳠⳢⳫⳭⳲꙀꙂꙄꙆꙈ
View gist:55fe26499cc32cd4df3ce995f573cebd
RuntimeError: Cannot load `Rails.application.database_configuration`:
Could not load database configuration. No such file - ["config/database.yml"]
/Users/jrochkind/.gem/ruby/2.4.2/gems/railties-5.2.0/lib/rails/application/configuration.rb:185:in `database_configuration'
/Users/jrochkind/.gem/ruby/2.4.2/gems/activerecord-5.2.0/lib/active_record/railtie.rb:133:in `block (2 levels) in <class:Railtie>'
/Users/jrochkind/.gem/ruby/2.4.2/gems/activesupport-5.2.0/lib/active_support/lazy_load_hooks.rb:71:in `instance_eval'
/Users/jrochkind/.gem/ruby/2.4.2/gems/activesupport-5.2.0/lib/active_support/lazy_load_hooks.rb:71:in `block in execute_hook'
/Users/jrochkind/.gem/ruby/2.4.2/gems/activesupport-5.2.0/lib/active_support/lazy_load_hooks.rb:62:in `with_execution_control'
/Users/jrochkind/.gem/ruby/2.4.2/gems/activesupport-5.2.0/lib/active_support/lazy_load_hooks.rb:67:in `execute_hook'
/Users/jrochkind/.gem/ruby/2.4.2/gems/activesupport-5.2.0/lib/active_support/lazy_load_hooks.rb:52:in `block in run_loa
@jrochkind
jrochkind / Explanation.md
Created Oct 15, 2012
Truncating html with nokogiri, with/without Rails
View Explanation.md

Rails has a handy truncate helper (which is actually mostly a method added to String ), but it warns you it's not safe to use on html source, it'll cut off end tags and such.

What if you want an HTML safe one? There are a variety of suggested solutions you can google, none of which were quite robust/powerful enough for me.

So I started with my favorite, by Andrea Singh, using nokogiri.

But:

  • I modified it to not monkey-patch Nokogiri, but be a static method instead (sadly making already confusing code yet more confusing, but I didn't want to monkey patch nokogiri)
View From InheritPermissionsJob, LDP::NotFound
[GEM_ROOT]/gems/ldp-0.6.4/lib/ldp/client/methods.rb:119 :in `block in check_for_errors`
[GEM_ROOT]/gems/ldp-0.6.4/lib/ldp/client/methods.rb:117 :in `tap`
[GEM_ROOT]/gems/ldp-0.6.4/lib/ldp/client/methods.rb:117 :in `check_for_errors`
[GEM_ROOT]/gems/ldp-0.6.4/lib/ldp/client/methods.rb:53 :in `block in get`
[GEM_ROOT]/gems/activesupport-4.2.7.1/lib/active_support/notifications.rb:166 :in `instrument`
[GEM_ROOT]/gems/ldp-0.6.4/lib/ldp/client/methods.rb:33 :in `get`
[GEM_ROOT]/gems/active-fedora-11.1.6/lib/active_fedora/caching_connection.rb:13 :in `get`
/usr/local/lib/ruby/2.3.0/delegate.rb:83 :in `method_missing`
[GEM_ROOT]/gems/active-fedora-11.1.6/lib/active_fedora/initializing_connection.rb:27 :in `get`
[GEM_ROOT]/gems/ldp-0.6.4/lib/ldp/resource.rb:54 :in `get`
View From InheritPermissionsJob, LDP::Gone
[GEM_ROOT]/gems/ldp-0.6.4/lib/ldp/client/methods.rb:119 :in `block in check_for_errors`
[GEM_ROOT]/gems/ldp-0.6.4/lib/ldp/client/methods.rb:117 :in `tap`
[GEM_ROOT]/gems/ldp-0.6.4/lib/ldp/client/methods.rb:117 :in `check_for_errors`
[GEM_ROOT]/gems/ldp-0.6.4/lib/ldp/client/methods.rb:25 :in `block in head`
[GEM_ROOT]/gems/activesupport-4.2.7.1/lib/active_support/notifications.rb:166 :in `instrument`
[GEM_ROOT]/gems/ldp-0.6.4/lib/ldp/client/methods.rb:17 :in `head`
/usr/local/lib/ruby/2.3.0/delegate.rb:83 :in `method_missing`
[GEM_ROOT]/gems/active-fedora-11.1.6/lib/active_fedora/initializing_connection.rb:22 :in `head`
[GEM_ROOT]/gems/ldp-0.6.4/lib/ldp/resource.rb:59 :in `head`
[GEM_ROOT]/gems/ldp-0.6.4/lib/ldp/resource.rb:42 :in `new?`
View imagedata.json
{
"Exif": {
"PixelXDimension": 3100,
"DateTimeDigitized": "2014:01:28 10:58:59",
"PixelYDimension": 2488,
"ColorSpace": 65535
},
"Orientation": 1,
"Content-Type": "image/tiff",
"Output": {},
You can’t perform that action at this time.