Skip to content

Instantly share code, notes, and snippets.

@kavu
kavu / attr_scanner.rb
Created January 3, 2013 16:05
attr_scanner.rb by@joernchen
#!/usr/bin/env ruby
#
# Mass assignment scanner for Ruby on Rails
# should be run from rails console in production
# environment.
#make sure all models are loaded
Dir[Rails.root + 'app/models/**/*.rb'].each { |path| require path }
models = ActiveRecord::Base.subclasses
@kavu
kavu / deploy.rb
Created November 8, 2012 14:20 — forked from mertonium/deploy.rb
Capistrano task to notify Ratchet.io about deployment
# I am trying out Ratchet.io and I want to add their deployment notification to my
# normal capistrano deployment process. Here is my first working attempt.
# Add this task to your deploy.rb
task :notify_ratchetio, :roles => :app do
set :revision, `git log -n 1 --pretty=format:"%H"`
set :local_user, `whoami`
set :ratchetio_token, YOUR_ACCESS_TOKEN
rails_env = fetch(:rails_env, "production")
run "curl https://submit.ratchet.io/api/1/deploy/ -F access_token=#{ratchetio_token} -F environment=#{rails_env} -F revision=#{revision} -F local_username=#{local_user} >/dev/null 2>&1"
@kavu
kavu / 1.9.3-p327-perf
Created October 31, 2012 09:37
RBenv — Ruby 1.9.3 with the latest @funny-falcon perf patch
build_package_combined_patch() {
local package_name="$1"
{
curl https://raw.github.com/gist/4136373/falcon.diff | patch -p1
autoconf
./configure --prefix="$PREFIX_PATH" $CONFIGURE_OPTS
make -j 8
make install
} >&4 2>&1
}
@kavu
kavu / homebrew.patch
Created October 27, 2012 19:38
Homebrew OrientDB Formula patch
diff --git a/bin/console.sh b/bin/console.sh
index 1932011..5edbeae 100644
--- a/bin/console.sh
+++ b/bin/console.sh
@@ -3,24 +3,10 @@
# Copyright (c) 1999-2010 Luca Garulli
#
-# resolve links - $0 may be a softlink
-PRG="$0"
@kavu
kavu / 1.9.3
Created January 26, 2012 19:48
Puppet rDoc specs
% rspec spec/integration/application/doc_spec.rb spec/integration/util/rdoc spec/unit/application/doc_spec.rb spec/unit/util/rdoc*
/Users/kavu/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': iconv will be deprecated in the future, use String#encode instead.
/Users/kavu/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- rdoc/tokenstream (LoadError)
from /Users/kavu/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/kavu/Work/GitHub/puppet/lib/puppet/util/rdoc/parser.rb:9:in `<top (required)>'
from /Users/kavu/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/kavu/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/kavu/Work/GitHub/puppet/spec/integration/util/rdoc/parser_spec.rb:5:in `<top (required)>'
from /Users/kavu/.rvm/gems
@kavu
kavu / class-exp.hs
Created January 18, 2012 12:17
Haskell class experiments
{-# LANGUAGE FlexibleInstances, TypeSynonymInstances, IncoherentInstances #-}
class (MyClass t) where
doShow :: (Show t) => t -> String
instance (MyClass String) where
doShow x = "Your string is " ++ x
instance (MyClass t) where
doShow x = "Your parameter is " ++ show x
instance (MyClass [t]) where
doShow x = do
@kavu
kavu / google_speech_recognition.rb
Created December 11, 2011 13:05 — forked from pachacamac/google_speech_recognition.rb
google speech recognition with ruby
require 'rest_client'
require 'json'
a = `sox -d --norm -t .flac - silence -l 1 0 1% 1 6.0 1% rate 16k`
#a = `arecord -q -d 3 -c 1 -f S16_LE -r 22050 -t wav | flac - -f --totally-silent -o-`
r = RestClient.post 'https://www.google.com/speech-api/v1/recognize?lang=en-US', a,
:content_type => 'audio/x-flac; rate=16000'
(p j; `espeak 'you said: #{j['hypotheses'].first['utterance']}'`) if (j = JSON.parse(r))
// ПоПацански.cpp : Defines the entry point for the console application.
//
// #include "stdafx.h"
#define подъёбку setlocale
#define чуть_чуть 7
#define так_себе 12
#define пошло_оно_всё 120
@kavu
kavu / gist:1023207
Created June 13, 2011 17:13
Net::HTTP::Patch
require 'net/http'
require 'json'
class Net::HTTP::Patch < Net::HTTPRequest
METHOD = 'PATCH'
REQUEST_HAS_BODY = true
RESPONSE_HAS_BODY = true
end
url = URI.parse('https://api.github.com/user')
@kavu
kavu / jshint_spec.js
Created February 20, 2011 10:40
Jasmine + JSLint
/*
Original code:
https://github.com/brandon/lucid/blob/master/spec/javascripts/z_jshint_spec.js
*/
describe('JSHint', function () {
var options = {curly: true, white: true, indent: 2},
files = /^\/src|.*spec\.js$/;
function get(path) {