Skip to content

Instantly share code, notes, and snippets.

@pix0r
pix0r / cj.sh
Created August 21, 2013 20:38
in-place cleanjson
#!/bin/sh
if [ "$1" = "" ]; then
echo "Usage: $0 <file.json> [file2.json...]"
exit -1
fi
CLEANJSON=`which cleanjson`
if [ "$CLEANJSON" = "" ]; then
echo "Please install cleanjson and ensure it's on your PATH"
@pix0r
pix0r / UnityView.mm
Last active December 21, 2015 18:48
UnityView.mm that uses rotation notification
#include "UnityView.h"
#include "iPhone_View.h"
#include "iPhone_OrientationSupport.h"
#include "Unity/UnityInterface.h"
#include "Unity/GlesHelper.h"
#include "Unity/DisplayManager.h"
extern void UnitySendTouchesBegin(NSSet* touches, UIEvent* event);
extern void UnitySendTouchesEnded(NSSet* touches, UIEvent* event);

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 / output.txt
Created September 25, 2015 13:50
unscientific test of different foreach syntax
$ php test.php
Running 10 tests of 5000 iterations
finished 1 of 10
finished 2 of 10
finished 3 of 10
finished 4 of 10
finished 5 of 10
finished 6 of 10
finished 7 of 10
finished 8 of 10