Skip to content

Instantly share code, notes, and snippets.

@camwest
camwest / gist:1633115
Created January 18, 2012 13:58
Stop stop sopa bookmarklet for Wikipedia.
javascript:(function(){document.getElementById("content").style.cssText = "display:block";document.getElementById("mw-sopaOverlay").style.cssText = "display:none";})();
require 'csv'
def transform_merge(csv_file)
CSV.open(@csv_file).read.each do |line|
end
end
def multiple_merge(inputs)
errors = []
def merge(user1, user2, preferred_email)
raise "Email cannot be the same" if (user1 == user2)
u = User.unscoped.find_by_email(user1)
u2 = User.unscoped.find_by_email(user2)
raise "User1 not found" if u.nil?
raise "User2 not found" if u2.nil?
if u.alternate_ids.empty?
@camwest
camwest / gist:1313629
Created October 25, 2011 17:47
Who's behind sample script
log = Logger.new("/tmp/whos_behind.log")
log.info "Producer Number, Full Name, Email, Party Key, Agency Status, Personal Status, Completed Elective Points, Outstanding Essentials"
Certification.where(["code IN(?)", [:agent, :lsp]]).each do |certification|
certification.users.limit(10).each do |user|
if user.party_type == 'Agent'
organization = user.organization
agency_status = organization.status
module Owner
class Response
def each
10.times do |i|
yield("entry #{i}\n")
sleep 1
end
end
end
@camwest
camwest / Stately ViewState support for Backbone.js Views
Created October 23, 2010 21:58
A simple implementation of view states for Backbone.js
// (c) 2010 Cameron Westland, Big Bang Technology Inc.
// Backbone may be freely distributed under the MIT license.
// For all details and documentation:
// http://bigbangtechnology.github.com/stately
/**
Example:
var MyView = Backbone.View.extend(Stately).extend({
states: {
EDITING: "editing",
class ReportsController < ApplicationController
rescue_from ArgumentError, :with => :invalid_report
before_filter :require_user
def show
respond_to do |wants|
wants.json { render :json => UserReportFactory.get_report( current_user, params[:id] ), :status => :ok }
wants.csv {
filename = "woople_#{params[:id]}.csv"
ActiveRecord::Schema.define(:version => 20100527145216) do
create_table "access_rights", :force => true do |t|
t.integer "group_id", :null => false
t.integer "restrictable_id"
t.string "restrictable_type"
t.datetime "created_at"
t.datetime "updated_at"
end
+--------------------+--------+---------+------------+------+----------------+-------------+-------------------+--------------+-----------+----------------+---------------------+---------------------+---------------------+-----------------+----------+----------------+-------------------+
| Name | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | Create_time | Update_time | Check_time | Collation | Checksum | Create_options | Comment |
+--------------------+--------+---------+------------+------+----------------+-------------+-------------------+--------------+-----------+----------------+---------------------+---------------------+---------------------+-----------------+----------+----------------+-------------------+
| access_rights | InnoDB | 10 | Compact | 1 | 16384 | 16384 | 0 | 16384 | 0 | 89 |
PASSWORD = lambda { |login|
Digest::SHA1.hexdigest("--#{Time.now.to_s}--#{login}--")[0,8]
}
PASSWORD.call("username")