Skip to content

Instantly share code, notes, and snippets.

@fauxparse
fauxparse / sortable.coffee
Created January 13, 2015 01:49
Sortable lists in < 100 LoC
class SortableList
constructor: (el) ->
@el = $(el)
down: (e) =>
e.preventDefault()
top = @el.offset().top
@el.find(".sortable").each (i, el) ->
$el = $(el)
offset = $el.offset().top
@fauxparse
fauxparse / gist:445b8dc4df934c54d02b
Created July 20, 2015 06:47
fauxparse.zsh-theme
PROMPT='%{$fg_bold[yellow]%}★%{$fg_bold[green]%}%p %{$fg[blue]%}%c % %{$reset_color%}'
RPROMPT='$(git_prompt_info)'
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[green]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg_bold[red]%} ✗%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_CLEAN=" "
#!/bin/sh
# Clean up the stale cached files from a theme
rake themes:uncache
# Restart the server: necessary to reload classes etc in production mode
touch tmp/restart.txt
namespace :themes do
desc "Clear out old cached versions of theme files"
task :uncache do
Dir[File.join(RAILS_ROOT, "themes/*")].each do |theme|
%w(images javascripts stylesheets).each do |dir|
if File.directory?(File.join(theme, dir))
Dir[File.join(theme, dir, "*")].each do |file|
dest = File.join RAILS_ROOT, "public", dir, File.basename(file)
if File.exist?(dest) && File.mtime(dest) < File.mtime(file)
puts "X #{dest}"
#!/bin/sh
# Clean up the stale cached files from a theme
rake themes:uncache
# Restart the server: necessary to reload classes etc in production mode
touch tmp/restart.txt
#!/usr/bin/env ruby
# Find common Twitter friends
# Usage: ./twat.rb user1 user2 ...
lists = ARGV.inject({}) do |hash, username|
page = 1
friends = []
while !(output = `curl -s http://twitter.com/statuses/friends/#{username}.xml?page=#{page} | grep "<screen_name>"`.gsub(%r{</?screen_name>}, '').split).empty?
friends += output
page += 1
$(document).ajaxSuccess(function() {
jQuery('.wymeditor').wymeditor({
/* options */
});
});
def response_keys
d = {}
responses.genuine.find_in_batches(:batch_size => 100) do |batch|
batch.each { |response| d.merge! response.data }
end
d.keys - [ "id" ]
end
# Custom types are scoped to a particular site instance,
# so their class names are suffixed with the site ID.
# This also helps Content#const_missing figure out when we're
# trying to load a custom type, because it gets numbers at the
# end of the class name.
# Note: I've put some validation logic in CustomType to ensure
# that the name in the database is a valid Ruby constant name.
# new_custom_type = Content::CustomType.create(:site_id => 1, :name => "My custom type")
# Content::MyCustomType1 #=> Content::MyCustomType1(...)
#!/usr/bin/env ruby
words = {}
stop_words = File.open("stop.txt") { |file| file.read.split }
def valid?(word)
case word
when /^\@/ then false # reject @usernames
when /^\#/ then true # keep #hashtags (separate from the word 'hashtags')
when /\.+/ then false # reject things that look like URLs