Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am pix0r on github.
  • I am pix0r (https://keybase.io/pix0r) on keybase.
  • I have a public key whose fingerprint is 24AF 484F 9A25 4A45 EC2B 1A3E 94C0 FC62 8BC3 39FD

To claim this, I am signing this object:

import sys
import unittest
import logging
from tree import Tree, tree, max_depth, max_depth_lr
logging.basicConfig(level=logging.DEBUG)
class TestInitTree(unittest.TestCase):
def all_models
Rails.application.eager_load!
ActiveRecord::Base.descendants
end
def replace_string_across_all_objects(old, new)
all_models().each do |model|
print "Checking #{model} models\n"
model.all.each do |o|
o.attributes.each_pair do |name, value|
#include <stdio.h>
int test() {
static int val = 0;
val += 1;
return val;
}
int main() {
printf("val: %d\n", test());
@pix0r
pix0r / zoom_level.rb
Created August 25, 2014 22:55
Ruby implementation of getBoundsZoomLevel JS
def zoom_level_for_bounds(bounds, map_dim={ height: 1000, width: 1000 }, zoom_max=21)
# See: http://stackoverflow.com/a/13274361/72
return zoom_max if bounds.min_x == bounds.max_x and bounds.min_y == bounds.max_y
world_dim = { height: 256, width: 256 }
def lat_rad(lat)
sin = Math.sin(lat * Math::PI / 180)
rad_x2 = Math.log((1 + sin) / (1 - sin)) / 2
@pix0r
pix0r / pre-commit
Created October 8, 2014 00:53
Pre-commit hook to verify xcode project file has not been converted to XML
#!/bin/sh
PROJFILE=`find . -path \*xcodeproj/project.pbxproj -not -path \*Pods\*`
if [ "$PROJFILE" = "" ]; then
echo "Unable to locate project file; skipping pre-commit hook"
exit 0
fi
git stash -q --keep-index
require "net/http"
require "uri"
require "openssl"
def test_ssl(url, pem_file=nil)
puts "Testing URL: #{url}"
uri = URI.parse(url)
http = Net::HTTP.new(uri.host, uri.port)
@pix0r
pix0r / split-3200x1200-image.sh
Created January 29, 2010 19:41
split a 3200x1200 image into left and right parts
#!/bin/sh
IMAGE=$1
EXT=`echo $IMAGE | sed -e 's/.*\(\.[A-Za-z0-9]*\)$/\1/'`
BASE=`echo $IMAGE | sed -e 's/^\(.*\)\(\.[A-Za-z0-9]*\)$/\1/'`
LEFT_IMAGE="$BASE-left$EXT"
RIGHT_IMAGE="$BASE-right$EXT"
if [ "$IMAGE" = "" ]; then
echo "Usage: $0 image.jpg"
@pix0r
pix0r / shared_followers.rb
Created February 23, 2010 19:52 — forked from damon/shared_followers.rb
find shared twitter followers, then print all usernames
#!/usr/bin/env ruby
# Author: Damon Clinkscales
# Modified 2010-02-23 by Mike Matz
# Loop through all shared follower IDs to expose usernames.
# Not recommended for people with a lot of followers!
require 'rubygems'
require 'hpricot'
require 'net/http'
function get_csv_line($fp) {
$sep = '|';
$quote = '"';
$escape = "\\";
$fields = array();
$field = '';
$in_field = true;
$in_quoted_field = false;
$in_escape = false;