Skip to content

Instantly share code, notes, and snippets.

@pix0r
pix0r / machine.js
Last active January 8, 2021 20:12
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
#!/bin/sh
device="en0"
IFS=$'\n'
networks=`networksetup -listpreferredwirelessnetworks $device | tail -n+2 | sed -e 's/^[[:space:]]*//'`
function usage() {
echo "Usage: $0 [options]"
@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
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 / 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
@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
#include <stdio.h>
int test() {
static int val = 0;
val += 1;
return val;
}
int main() {
printf("val: %d\n", test());
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|
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):

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: