This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Rails controller concern to enable Devise authentication for ActiveStorage. | |
# Put it in +app/controllers/concerns/blob_authenticatable.rb+ and include it when overriding | |
# +ActiveStorage::BlobsController+ and +ActiveStorage::RepresentationsController+. | |
# | |
# Optional configuration: | |
# | |
# Set the model that includes devise's database_authenticatable. | |
# Defaults to Devise.default_scope which defaults to the first | |
# devise role declared in your routes (usually :user) | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Natively, Enumerators get JSONized like "#<Enumerator::Lazy:0x007f8714807080>", or they explode, either of which is a problem. | |
# We want them to make an array, and do it lazily so we don't have to keep the items in memory! | |
class Enumerator | |
def to_json(state) | |
state.depth += 1 | |
string = "[\n" | |
first_item = true | |
self.each do |item| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Useful Collections | |
def a_array | |
(1..6).to_a | |
end | |
def a_hash | |
{hello: "world", free: "of charge"} | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#encoding: UTF-8 | |
require 'rubygems' | |
require "pismo" | |
require 'punkt-segmenter' | |
require 'htmlentities' | |
require './markov.rb' | |
CLEAN_TEXT = <<-EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Include all rake files in the tasks directory | |
Dir.glob('tasks/*.rake').each { |r| import r } | |
# Read configuration from tasks/config.yaml | |
require 'yaml' | |
CONFIG = YAML.load_file('tasks/config.yaml')[ENV['env'] || 'development'] | |
# Default utility functions available in all tasks | |
def ok_failed(condition) | |
if (condition) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Utils = { | |
/* modified version of https://gist.github.com/1243697 | |
* adds detection of file extension rather than hard-coding .jpg as in the original | |
*/ | |
_getExtension: function(fn) { | |
// from http://stackoverflow.com/a/680982/292947 | |
var re = /(?:\.([^.]+))?$/; | |
var tmpext = re.exec(fn)[1]; | |
return (tmpext) ? tmpext : ''; | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -ex | |
### configuration | |
PKGS_TO_ADD="$PKGS_TO_ADD curl git etckeeper python-software-properties" | |
PKGS_TO_REMOVE="$PKGS_TO_REMOVE geoip-database popularity-contest" | |
PKGS_TO_REMOVE="$PKGS_TO_REMOVE pppoeconf pppconfig ppp" | |
PKGS_TO_REMOVE="$PKGS_TO_REMOVE ubuntu-standard memtest86+" # warning: be careful about what you remove after this | |
KERNEL_MODULES_TO_BLACKLIST="$KERNEL_MODULES_TO_BLACKLIST joydev gameport" | |
KERNEL_MODULES_TO_BLACKLIST="$KERNEL_MODULES_TO_BLACKLIST btusb bluetooth" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
command = '/opt/ruby-enterprise-1.8.6-20080810/bin/passenger-memory-stats' | |
memory_limit = 200 # megabytes | |
def running?(pid) | |
begin | |
return Process.getpgid(pid) != -1 | |
rescue Errno::ESRCH | |
return false |