Skip to content

Instantly share code, notes, and snippets.

Jacob Swanner jswanner

Block or report user

Report or block jswanner

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
View allow_ctrl_v.js
var ctrlKey = 17,
ctrlDown = false,
vKey = 86,
allowCtrlPaste,
allowPaste,
captureCtrl,
releaseCtrl;
allowCtrlPaste = function(e){
if (ctrlDown && e.keyCode == vKey) {
View Rakefile
require 'redcarpet'
desc "generate index.html from README.md"
file "index.html" => "README.md" do |task|
puts "Processing README.md to generate a new index.html..."
# `r` means we're using the "read" mode with the file
# we need a String for Redcarpet, it doesn't accept File objects.
string = File.open(task.prerequisites.first, 'r') { |file| file.read }
markdown = ::Redcarpet::Markdown.new(Redcarpet::Render::HTML, extensions = {})
@jswanner
jswanner / v2.3.18-v3.0.0.diff
Created Apr 28, 2014
Rails diff of v2.3.18 to v3.0.0
View v2.3.18-v3.0.0.diff
diff -Nr -U 1000 tmp/generated/v2.3.18/.gitignore tmp/generated/v3.0.0/.gitignore
--- tmp/generated/v2.3.18/.gitignore 1969-12-31 16:00:00.000000000 -0800
+++ tmp/generated/v3.0.0/.gitignore 2014-02-21 19:34:53.000000000 -0800
@@ -0,0 +1,4 @@
+.bundle
+db/*.sqlite3
+log/*.log
+tmp/**/*
diff -Nr -U 1000 tmp/generated/v2.3.18/Gemfile tmp/generated/v3.0.0/Gemfile
--- tmp/generated/v2.3.18/Gemfile 1969-12-31 16:00:00.000000000 -0800
View method_modifiers.rb
module MethodModifiers
def privatize
on_method_defined do |klass, method|
Priv.call klass, method
end
end
def memoize
on_method_defined do |klass, method|
Memo.call klass, method
@jswanner
jswanner / gist:5863448
Created Jun 25, 2013
Including multiple modules into class
View gist:5863448
$ irb
irb(main):001:0> module Mod1
irb(main):002:1> def self.included base
irb(main):003:2> puts 'included Mod1'
irb(main):004:2> end
irb(main):005:1> end
=> nil
irb(main):006:0> module Mod2
irb(main):007:1> def self.included base
irb(main):008:2> puts 'included Mod2'
@jswanner
jswanner / migrate.rake
Last active Dec 6, 2017
Rolls back migrations in current branch not present in specified branch.
View migrate.rake
desc 'rolls back migrations in current branch not present in other'
task :rollback_branch_migrations, [:other_branch] do |t, args|
load "#{Dir.pwd}/Rakefile"
branch_migrations = BranchMigrations.new(args.other_branch)
puts ['Rollback the following migrations', branch_migrations, 'y,n? ']
next if %w[no n NO N].include?(STDIN.gets.chomp)
Rake::Task['environment'].invoke
View searchable_example.rb
require 'textacular/searchable'
class Book
# :title, String
# :author, String
extend Searchable(:title)
end
Book.create :title => "Poignant Guide to Ruby", :author => "_why"
@jswanner
jswanner / routes.rb
Last active Dec 12, 2015
Rails 3 concern-like, with options.
View routes.rb
sociable = ->(options = {}) {
resources :comments, options
resources :categories, options
resources :tags, options
}
resources :messages do sociable.(only: :create) end
resources :posts, &sociable
resources :items, &sociable
@jswanner
jswanner / nulls_last.rb
Created Sep 13, 2012
ActiveRecord Postgres Nulls Last
View nulls_last.rb
ActiveSupport.on_load(:active_record) do
module Arel::NullsLastPredications
def nulls_last
Arel::Nodes::NullsLast.new self
end
end
module Arel::Nodes
class NullsLast < Unary
def gsub *args
@jswanner
jswanner / Weather.js.diff
Created Jul 20, 2012
Prevent OS X dashboard weather widget from moving around.
View Weather.js.diff
--- /Library/Widgets/Weather.wdgt/Weather.js 2012-07-20 10:53:24.000000000 -0400
+++ /Library/Widgets/Weather.wdgt/Weather.js 2012-07-20 10:53:40.000000000 -0400
@@ -406,7 +406,7 @@
if (entry != null)
{
iconData.push(entry);
- maxOffset = entry.voffset > maxOffset ? entry.voffset : maxOffset;
+ // maxOffset = entry.voffset > maxOffset ? entry.voffset : maxOffset;
if (entry.hoffset < 0)
You can’t perform that action at this time.