Skip to content

Instantly share code, notes, and snippets.

View entp's full-sized avatar

ENTP entp

View GitHub Profile
@entp
entp / Rakefile
Created February 15, 2011 02:02
Downloads all the messages in your imap mailbox and saves them as files.
IMAP = { :user => "you@gmail.com", :pass => "yourpassword" }
namespace :imap do
wrapper = nil
task :connect do
dir = "#{File.dirname(__FILE__)}/../../../../"
require 'imap_wrapper'
include ImapWrapper::Constants
wrapper = ImapWrapper.new(IMAP[:user], IMAP[:pass], ENV['PURGE'], ENV['VERBOSE'])
@entp
entp / gist:662049
Created November 4, 2010 02:23
Get around FireSheep issues for non-SSL connections
One of the problems with requiring SSL for all pages in a site is that you can't rely on a lot of the benefits of browser caching. However, many sites DO require login over SSL.
During login process, set a LocalStorage private key. This won't be visible to any attacker.
Periodically, ask user to encrypt or hash something asymmetrically and send the (public) result back.
If a user sends back the same result twice, or it wasn't encrypted correctly, log them out.
This may require some way to track individual tabs - if a user opens a new tab/window, there's likely some way to track this. Maybe they can encrypt the last URL they opened, and set that as a cookie.
class ApiSerializer < ActiveRecord::Serialization::JsonSerializer #:nodoc:
def serializable_record
@host_name = @options.delete :host
@is_supporter = @options.delete :supporter
@site_permalink = @options.delete :site_permalink
@site_prefix = nil
super
end
def site_prefix
~vp(master)> cat ~/.gitconfig
...SNIP...
[alias]
datetag = !git tag `date \"+%Y%m%d%H%M\"`
update = pull --rebase
commdiff = log --pretty=oneline --left-right
...SNIP...
~vp(master)> git commdiff master...staging
>bb569b9a8c70a61ecffd4def3ac5e460848e0f36 Merge branch 'master' into staging
>f95b7db13fb48b3b5e1c2c484d00909a89f468d5 bulk edit on search page is no longer experimental
module ThinkingSphinx
def self.index_documents_in_testing
ThinkingSphinx::Deltas::Job.cancel_thinking_sphinx_jobs
config = ThinkingSphinx::Configuration.instance
config.build
FileUtils.mkdir_p config.searchd_file_path
cmd = "#{config.bin_path}indexer --config #{config.config_file} --all"
cmd << " --rotate" if ThinkingSphinx.sphinx_running?
gem 'activesupport', '~> 2.1.1'
gem 'sequel', '~> 2.7'
gem 'activemerchant', '~> 1.4'
%w(array/extract_options hash/keys hash/indifferent_access).each { |lib| require "active_support/core_ext/#{lib}" }
class Array #:nodoc:
include ActiveSupport::CoreExtensions::Array::ExtractOptions
end
class Hash #:nodoc:
module MyApp
class TestCase < Test::Unit::TestCase
def self.transaction(&block)
Sequel::Model.db.transaction &block
end
def transaction(&block)
self.class.transaction(&block)
end
class << ActiveRecord::Base
def none?(*args)
!exists?(*args)
end
end
# fuck you for judging me! LOL
class << ActiveRecord::Base
def second(options = {})
first(options.update(:offset => 1))
end
def third(options = {})
first(options.update(:offset => 2))
end
end
<% @changes.select(&:diffable?).each do |change| -%>
<% begin -%>
<%= diff_for change %>
<% rescue -%>
?
<% end -%>
<% end -%>