Skip to content

Instantly share code, notes, and snippets.

@betesh
betesh / just_log_env.rb
Created September 17, 2014 22:10
middleware that just logs
class JustLogEnv
def initialize(app)
@app = app
end
def call(env)
Rails.logger.info env.inspect
@app.call(env)
end
end
@betesh
betesh / migrate.rb
Created September 23, 2014 23:51
Migrating paperclip attachments from file storage to s3 storage
require 'aws-sdk'
require 'bcdatabase'
config = Bcdatabase.load[:secrets, :paperclip_s3]
AWS.config(config)
BUCKET = AWS::S3.new.buckets[config['bucket']]
require 'find'
Find.find('public/system/') { |f|
@betesh
betesh / fixbash.rb
Last active August 29, 2015 14:07
shellshock repair using sshkit
require 'sshkit'
require 'sshkit/coordinator'
require 'sshkit/host'
require 'sshkit/dsl'
SSHKit::Backend::Netssh.configure do |backend|
backend.pty = true
end
def echo_vulnerability(host, issue)
@betesh
betesh / updateApk.js
Last active August 29, 2015 14:08
Titanium code to automatically update an APK
var updateApk = function(apkUrl) {
var downloader = require("com.mykingdom.downloader").createAsyncDownloader({
filesToDownload: [{url : apkUrl}],
outputDirectory: Ti.Filesystem.getFile("file:///mnt/sdcard/download"),
enableNotification: true, notificationId: 1, notificationTitle: "Downloading new APK" // Optional
});
downloader.addEventListener("error", function(event){
alert(event.error + " : While downloading file at (index 0 based) = " + event.currentIndex);
});
downloader.addEventListener("onload", function(event){
@betesh
betesh / Gemfile
Last active August 29, 2015 14:11
rails-html-sanitizer gem breaks ActionMailer + ActionView + ActiveRecord - Rails 4.2.0 projects
source "https://rubygems.org"
gem "activerecord", "= 4.2.0"
gem "actionview", "= 4.2.0"
gem "sqlite3"
@betesh
betesh / Gemfile
Last active August 29, 2015 14:24
HasManyAssociationIsCreatedWhenMarkedForDestruction
source 'https://rubygems.org'
gem "activerecord", "~> 4.2"
gem "sqlite3"
gem "rspec"
@betesh
betesh / failing-test-rails-issue-20882.rb
Last active August 29, 2015 14:25
failing-test-rails-issue-20882
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
# Dequeueing ActiveJob tasks in the context of your Rails application?
# An alternative is to run a standalone ActiveJob process.
# But making it dequeue and send devise emails isn't so simple.
# Devise is designed to be integrated into a Rails application, not a standalone ActiveJob process.
# Before we address configuring the standalone ActiveJob process,
# there's some code that needs to go into your Rails app.
# Put this in each model in your Rails application:
#
# /usr/bin/env ruby
PAIRS = [
["SHA1_ON_NEW_BRANCH", "SHA1_ON_ORIGINAL_BRANCH"],
# etc...
]
PAIRS.each do |pair|
cmd = "bash -c 'diff <(git show #{pair[0]} -U0 --format=\"\" | grep -v \"^index\") <(git show #{pair[1]} -U0 --format=\"\" | grep -v \"^index\") | grep -v \"> @@ \" | grep -v \"< @@ \" | grep -v \"^---$\" '"
result = `#{cmd}`.chomp
@betesh
betesh / export.js
Last active December 14, 2017 14:57
Export all your passwords from Google Chrome
/* Adapted from https://cmatskas.com/export-your-stored-passwords-from-chrome/
* 1. Go to chrome://settings-frame/passwords
* 2. Paste the following into the JS console:
*/
var decryptedRow="";
var pm = PasswordManager.getInstance();
var model = pm.savedPasswordsList_.dataModel;
var pl = pm.savedPasswordsList_;
for(i=0;i<model.length;i++){