Skip to content

Instantly share code, notes, and snippets.

View unixpickle's full-sized avatar

Alex Nichol unixpickle

View GitHub Profile
@unixpickle
unixpickle / Determinant Finder
Created November 3, 2010 18:42
Find the determinant of any 3x3 matrix.
def determineMatrix (matrix):
# here we do some major if statements
n1 = 0.0
n2 = 0.0
size = len(matrix)
if len(matrix[0]) != size:
print "Bad matrix for determination. (" + str(len(matrix)) + "x" + str(len(matrix[0])) + ") "
return 0.0
else:
print "determining matrix (" + str(len(matrix)) + "x" + str(len(matrix[0])) + ") "
@unixpickle
unixpickle / Little Snitch Allow
Created November 3, 2010 21:57
a simple objective-c application to allow little snitch connections
#import <Foundation/Foundation.h>
int main (int argc, char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSAppleScript * scrpt = [[NSAppleScript alloc] initWithSource:@"set volume 0\n\
tell application \"System Events\" to set app_name to name of the first process whose frontmost is true\n\
tell application \"Little Snitch UIAgent\" to activate\n\
tell application \"System Events\" to keystroke return\n\
tell application app_name to activate\n\
delay 0.5\n\
@unixpickle
unixpickle / sprintfalloc
Created November 4, 2010 15:38
create a C string from a format without manually allocating a buffer
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
int strappend (char ** buff, int alloclen, const char * nstring) {
int slen = strlen(buff[0]);
int slen2 = strlen(nstring);
char * newbuff = (char *)malloc(slen + slen2 + 2);
memset(newbuff, 0, slen+slen2+2);
@unixpickle
unixpickle / testtetris.pl
Created November 4, 2010 21:45
post a fake high score to tetris1d
#!/usr/bin/perl
#
# Highscore forger for tetris1d
#
use strict;
use IO::Socket;
use Socket;
my $numArgs = $#ARGV + 1;
@unixpickle
unixpickle / python.pl
Created November 5, 2010 01:00
detect weather python is better than perl
#!/usr/bin/perl
$_ = "the quick brown fox jumps over the lazy dog.";
$mstr = "python";
s/( ?)[a-z]+/\1${mstr}/g;
$i = length($_);
$_ = "the quick brown fox jumps over the lazy dog.";
$mstr = "perl";
s/( ?)[a-z]+/\1${mstr}/g;
$i1 = length($_);
unless ($i1 > $i) {
@unixpickle
unixpickle / argcount.pl
Created November 5, 2010 02:33
count the number of command-line arguments in perl
#!/usr/bin/perl
use strict;
sub arrcount {
my ($arr) = @_;
my $c = 0;
foreach my $str (@{$arr}) {
++$c;
}
@unixpickle
unixpickle / macrumors.pl
Created November 6, 2010 04:19
mac rumors reading app for perl
#!/usr/bin/perl
use strict;
use LWP::UserAgent;
sub getmacrumors {
my $ua = new LWP::UserAgent;
$ua->timeout(120);
my $request = new HTTP::Request('GET', 'http://www.macrumors.com/');
my $response = $ua->request($request);
@unixpickle
unixpickle / rumors2.pl
Created November 6, 2010 06:34
another short perl script for viewing mac rumors
#!/usr/bin/perl
use LWP::UserAgent;
use strict;
sub getmacrumors {
my $ua = new LWP::UserAgent;
$ua->timeout(120);
my $request = new HTTP::Request('GET', 'http://www.macrumors.com/');
@unixpickle
unixpickle / Latest Video
Created December 23, 2010 05:04
A PHP script to get the latest video on a channel
function latestYoutube ($channel) {
error_reporting(E_ALL);
$feedURL = 'http://gdata.youtube.com/feeds/api/users/' . $channel . '/uploads?max-results=20';
$sxml = simplexml_load_file($feedURL);
$i = 0;
foreach ($sxml->entry as $entry) {
$media = $entry->children('media', true);
$url = (string)$media->group->player->attributes()->url;
$index = strrpos($url, "&");
$url = substr($url, 0, $index);
//
// NSData+hex.h
// NSData+hex
//
// Created by Alex Nichol on 3/29/11.
// Copyright 2011 Jitsik. All rights reserved.
//
#import <Foundation/Foundation.h>