Skip to content

Instantly share code, notes, and snippets.

View evanwalsh's full-sized avatar
❤️‍🔥
You make me feel almost human

Evan Walsh evanwalsh

❤️‍🔥
You make me feel almost human
View GitHub Profile
@evanwalsh
evanwalsh / import.rb
Last active April 3, 2024 19:12
I imported my Jekyll from Squarespace's Wordpress XML with this
# coding: utf-8
require 'rubygems'
require 'hpricot'
require 'fileutils'
require 'safe_yaml'
require 'time'
module JekyllImport
# This importer takes a wordpress.xml file, which can be exported from your
@evanwalsh
evanwalsh / mithril-query.d.ts
Created July 24, 2018 18:14
mithril-query.d.ts
declare var MithrilQuery: (...options: any[]) => MithrilQueryInstance
interface KeyEventOptions {
target?: any
value?: any
altKey?: boolean
shiftKey?: boolean
ctrlKey?: boolean
silent?: boolean
}
@evanwalsh
evanwalsh / imgur.rb
Created August 21, 2012 00:32
Download an imgur.com gallery with Ruby and Nokogiri
#!/usr/bin/env ruby
# Download imgur.com galleries easily
#
# Requirements:
# gem install nokogiri
#
# Usage:
# ruby imgur.rb [url of gallery] [directory to download into] [namespace for files]
#
• What does the app do?
• How to start a timer?
• How to stop a timer?
• How does idle time work?
• How does summary bar/time summary work?
• How to change preferences?
• Where do I get it?
                                                                                                    
@evanwalsh
evanwalsh / weather_geeklet.rb
Last active December 17, 2015 04:59
Forecast.io script for GeekTool
#!/usr/bin/env ruby
# Get an API key from https://developer.forecast.io/
#
# Outputs something like this:
#
# Clear, 65°F
# Moderate chance of rain until tonight
FORECAST_IO_API_KEY = "YOUR KEY GOES HERE"
Capybara.add_selector :record do
xpath { |record| XPath.css("#" + ActionController::RecordIdentifier.dom_id(record)) }
match { |record| record.is_a?(ActiveRecord::Base) }
end
@evanwalsh
evanwalsh / meta_tag_helper.rb
Created August 12, 2012 00:45
Meta tag helper for Rails
# Accepts arguments like:
# meta_tag :warning, "HC SVNT DRACONES"
# or
# meta_tag charset: "utf-8"
def meta_tag *options
if (options.select {|o| o.is_a?(String) || o.is_a?(Symbol) }.count == options.count) && (options.count == 2)
tag :meta, name: options.first, content: options.last
else
tag :meta, *options
end
@evanwalsh
evanwalsh / app--helpers--application_helper.rb
Created May 4, 2012 03:46 — forked from nickhoffman/app--helpers--application_helper.rb
pjax is awesome, but causes code within #content_for not to be rendered. Here's a solution.
module ApplicationHelper
def content_for_or_pjax(name, &block)
request.headers['X-PJAX'] ? capture(&block) : content_for(name, &block)
end
end
@evanwalsh
evanwalsh / gist:2552100
Created April 29, 2012 17:26 — forked from joelmoss/gist:2470666
Capistrano recipe for Puma start/stop/restarts
set :shared_children, shared_children << 'tmp/sockets'
namespace :deploy do
desc "Start the application"
task :start, :roles => :app, :except => { :no_release => true } do
run "cd #{current_path} && RAILS_ENV=#{stage} bundle exec puma -b 'unix://#{shared_path}/sockets/puma.sock' -S #{shared_path}/sockets/puma.state --control 'unix://#{shared_path}/sockets/pumactl.sock' >> #{shared_path}/log/puma-#{stage}.log 2>&1 &", :pty => false
end
desc "Stop the application"
task :stop, :roles => :app, :except => { :no_release => true } do
@evanwalsh
evanwalsh / levenshtein.rb
Created April 20, 2012 13:27
Levenshtein distance
# http://ruby-snippets.heroku.com/string/levenshtein-distance
class String
def levenshtein(other, ins=2, del=2, sub=1)
# ins, del, sub are weighted costs
return nil if self.nil?
return nil if other.nil?
dm = [] # distance matrix