Skip to content

Instantly share code, notes, and snippets.

View pftg's full-sized avatar
💭
I may be slow to respond.

Paul Keen pftg

💭
I may be slow to respond.
View GitHub Profile
var setCryptData = function (data) {
window.cryptData = data.crypto_key;
};
var submitFormWithCrypto = function (form, callback) {
$.getScript('/profiles/crypto_key?callback=setCryptData', function () {
var queryData = {
key_id: cryptData.id,
encrypted: teaEncrypt($(form).serialize(), cryptData.key)
};
@pftg
pftg / Move instructions
Created March 28, 2012 20:21
Move /home to it’s own partition
mkdir /mnt/newhome
sudo mount -t ext3 /dev/hda5 /mnt/newhome
cd /home/
find . -depth -print0 | cpio –null –sparse -pvd /mnt/newhome/
sudo umount /mnt/newhome
sudo mv /home /old_home
sudo mkdir /home
@pftg
pftg / torrentsync.rb
Created April 6, 2012 11:04 — forked from ohac/torrentsync.rb
transmission-remote for ruby
#!/usr/bin/ruby
require 'rubygems'
require 'nokogiri'
require 'net/http'
require 'json'
require 'timeout'
require 'fileutils'
require 'open-uri'
require 'base64'
require 'choice'
@pftg
pftg / client.rb
Created September 11, 2012 07:24
Rails Isolation snippet with Faraday
#lib/client.rb
require 'faraday_middleware'
module Client
def connection
@connection ||= Faraday.new url: APP_URL do |faraday|
=begin
Some Faraday Builder's code
class BlogsController < ApplicationController
before_filter :setup
def replace
# For some reason we need only mark for destructions old article with name: "My First Article"
blog.articles.each(&:mark_for_destruction)
# params[:articles_attributes] => { name: "My First Article" }
blog.articles.build(params[:articles_attributes])
blog.save! # => raise exception!
@pftg
pftg / test_should_destroy_marked_childs_before_new_child_savings_for_postgres.out
Last active December 15, 2015 02:19
test_should_destroy_marked_childs_before_new_child_savings results output
ruby -Itest:lib /Users/pftg/dev/rails/activerecord/test/cases/autosave_association_test.rb --name=test_should_destroy_marked_childs_before_new_child_savings
Testing started at 11:45 AM ...
Using postgresql
Run options: --name=test_should_destroy_marked_childs_before_new_child_savings --seed 7999
# Running tests:
E
Finished tests in 0.097594s, 10.2465 tests/s, 0.0000 assertions/s.
@pftg
pftg / lib_sprockets_rails_task.rb
Last active December 17, 2015 04:09
spocket-rails refactoring
# sprockets-rails/lib/sprockets/rails/task.rb
require 'rake'
require 'rake/sprocketstask'
require 'sprockets'
module Sprockets
module Rails
class Task < Rake::SprocketsTask
attr_accessor :app
@pftg
pftg / delete_local_branches.sh
Last active December 17, 2015 19:59
Simple command to delete all local branches except selected
git branch | grep -v "master\|staging\|production" | xargs git branch -D
# Activate the gem you are reporting the issue against.
gem 'activerecord', '3.2.13'
require 'active_record'
require 'minitest/autorun'
require 'logger'
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.logger = Logger.new(STDOUT)
unless File.exists?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
gem 'sqlite3'
GEMFILE
system 'bundle'
end