Skip to content

Instantly share code, notes, and snippets.

View iconara's full-sized avatar
🤖

Theo iconara

🤖
View GitHub Profile
SELECT
category,
segment,
SUM(exposures) AS exposures,
SUM(impressions)/(SUM(exposures) - SUM(indeterminate_visibility)) AS impression_rate,
SUM(engagements)/SUM(exposures) AS engagement_rate
FROM (
SELECT
date,
ad_id,
~% rvm --trace wrapper 1.8.7@wukong wukong 15:19 reventon
+__rvm_parse_args:414> [[ -z 4.3.9 ]]
+__rvm_parse_args:570> [[ -z '' && -n '' ]]
+__rvm_parse_args:572> [[ 0 -eq 1 || -n '' ]]
+__rvm_parse_args:15> [[ -n wrapper ]]
+__rvm_parse_args:17> rvm_token=wrapper
+__rvm_parse_args:19> [[ 2 -gt 0 ]]
+__rvm_parse_args:19> next_token=1.8.7@wukong
+__rvm_parse_args:19> shift
+__rvm_parse_args:21> case wrapper (fetch|version|srcdir|reset|debug|reload|update|monitor|notes|implode|seppuku|question|answer|env)
~% cat .rvm/bin/wukong_\ 15:21 reventon
#!/usr/bin/env bash
if [[ -s "/Users/theo/.rvm/environments/ruby-1.8.7-p302@wukong" ]] ; then
\. "/Users/theo/.rvm/environments/ruby-1.8.7-p302@wukong"
exec "$@"
else
echo "ERROR: Missing RVM environment file: '/Users/theo/.rvm/environments/ruby-1.8.7-p302@wukong'" >&2
exit 1
fi
@iconara
iconara / Redis questions on StackOverflow
Created January 24, 2011 16:20
How to query StackOverflow for the most recent, unanswered but upvoted, questions tagged "redis"
#!/usr/bin/env ruby
require 'zlib'
require 'open-uri'
require 'json'
io = Zlib::GzipReader.new(open("http://api.stackoverflow.com/1.0/questions?tagged=redis&sort=votes&min=1"))
obj = JSON.parse(io.read)
@iconara
iconara / benchmarks
Created March 8, 2011 13:06
The benchmark results
Result of running bm.rb four times (which runs 100K iterations of encode or decode
over a set of values), taking the "user" column from the results:
+------------------+--------+---------+---------+---------+---------+
| | Method | 1st run | 2nd run | 3rd run | 4th run |
+------------------+--------+---------+---------+---------+---------+
| Baseline | Decode | 1.92 | 1.92 | 1.94 | 2.22 |
| | Encode | 1.90 | 1.91 | 1.91 | 1.92 |
+------------------+--------+---------+---------+---------+---------+
| Constant Strings | Decode | 2.07 | 1.81 | 1.82 | 1.84 |
@iconara
iconara / brew install -vd imagemagick output
Created April 8, 2011 07:37
Trying to install imagemagick
% brew install -vd imagemagick
/usr/local/bin/git
==> Cloning git://github.com/adamv/ImageMagick.git
Updating /Users/theo/Library/Caches/Homebrew/imagemagick--git
git fetch git://github.com/adamv/ImageMagick.git
From git://github.com/adamv/ImageMagick
* branch HEAD -> FETCH_HEAD
==> Checking out ref fdb125591a17a4002798742014118d5cfee44394
git checkout-index -a -f --prefix=/private/tmp/homebrew-imagemagick-6.6.7-10-dXf5/
==> ./configure --disable-osx-universal-binary --without-perl --prefix=/usr/local/Cellar/imagemagick/6.6.7-10 --disable-dependency-tracking --enable-shared --disable-static --with-modules --without-gslib --without-magick-plus-plus
require 'mongo'
mongo = Mongo::Connection.new
db = mongo.db('test')
collection = db.collection('helloworld')
collection.remove
collection.insert({:x => 3})
collection.insert({:x => 2})
collection.insert({:x => 5})
@iconara
iconara / gist:968259
Created May 12, 2011 09:44
AMQP monkey patch
# This monkey patches tmm1's amqp gem to handle Basic Return
module AMQP
class ConsumerHijacker
attr_reader :header, :body
def receive(header, body)
@header, @body = header, body
end
@iconara
iconara / gist:977308
Created May 17, 2011 20:27
Buffered IO
CHUNK_SIZE = 1024 * 1024
EMPTY_STRING = ''.freeze
NEWLINE = "\n".freeze
# line_enum('path/to/huge/file').each do |line|
# puts line
# end
def line_enum(path)
Enumerator.new do |y|
File.open(path) do |io|
@iconara
iconara / gist:978897
Created May 18, 2011 16:12
rabbitmq log
=ERROR REPORT==== 18-May-2011::14:20:55 ===
** Generic server <0.15956.26> terminating
** Last message in was {'$gen_cast',emit_stats}
** When Server state == {ch,running,rabbit_framing_amqp_0_9_1,2,<0.15950.26>,
<0.15955.26>,<0.15950.26>,<0.15957.26>,
#Fun<rabbit_channel_sup.0.15412730>,none,
{set,0,16,16,8,80,48,
{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],
[]},
{{[],[],[],[],[],[],[],[],[],[],[],[],[],[],