Skip to content

Instantly share code, notes, and snippets.

View manchicken's full-sized avatar
🦀
I pinch.

Mike Stemle manchicken

🦀
I pinch.
View GitHub Profile
@manchicken
manchicken / LSB.pm
Created August 21, 2013 21:33
A quick Perl module to read LSB release info
# Copyright (c) 2013, Michael D. Stemle, Jr.
# This module may be distributed under the same terms as Perl itself.
package LSB;
our $VERSION = "1.0.0";
use Fcntl qw/:DEFAULT/;
use IO::File;
use Readonly;
@manchicken
manchicken / mouse_swap.js
Created August 22, 2013 14:46
I'm a lefty, and sometimes you need to be able to switch which button your mouse settings use (for example, when you use RDP in with a Macbook into a Windows 7 machine) to use right-handed norms on OS' which use "right" and "left" rather than "primary" and "secondary." This is JScript, not JavaScript.
obsS=WScript.CreateObject("WScript.Shell")
obsS.Run("control mouse", 5)
WScript.sleep(1000)
obsS.AppActivate("Mouse")
WScript.Sleep(300)
obsS.Sendkeys(" ")
WScript.Sleep(123)
obsS.SendkEys("{Enter}")
#!/usr/bin/env python
import sys, getopt, csv, pprint
from pymongo import MongoClient
global_mongo = None
global_db = None
global_coll = None
def usage(msg):
db.foo.find().forEach(printjson);
db.foo.mapReduce(
function () {
emit (this["First Name"].toLowerCase().split('')[0], 1);
},
function (key,value) {
return Array.sum(value);
},
{
@manchicken
manchicken / mount_with_ascript.m
Created August 26, 2013 03:47
This is a snippet of a program I wrote a LONG time back. This actually lets you use ascript to mount a network drive onto a local mount point. I used this as part of an application I was working on to mount Windows (CIFS mostly) shares onto Mac workstations. NOTE: This code probably doesn't compile (definitely doesn't), and it would take some wo…
#define APPLESCRIPT_MOUNT_SCRIPT(X) [\
NSString \
stringWithFormat:@"tell application \"Finder\" to mount volume \"%@\"",\
X\
]
- (BOOL) mount {
NSAppleScript *ascript = [[NSAppleScript alloc]
initWithSource:APPLESCRIPT_MOUNT_SCRIPT(originalPath)];
NSDictionary *errorInfo = nil;
@manchicken
manchicken / simple_threads.pl
Created August 27, 2013 03:42
Here's a simple example of threading in Perl. `perldoc perlthrtut` is also a good place to look.
#!/usr/bin/env perl
use strict;use warnings;
use threads;
sub number_crunch {
my ($sub, @set) = @_;
my $product = 0;
my $n = 0;
@manchicken
manchicken / quicksort.pl
Created August 27, 2013 19:43
A very simple quicksort implementation.
#!/usr/bin/env perl
use strict;use warnings;
use Test::More tests => 5;
use Data::Dumper;
sub quicksort {
my (@list) = @_;
my $len = scalar(@list);
@manchicken
manchicken / simple_threads.py
Created August 28, 2013 18:38
This is me essentially doing the same thing as in my Perl playing with threads. This is more of me trying to do something in Perl and then replicate it in Python as a means of learning Python.
#!/usr/bin/env python
import sys
import threading
def process_number(func,input_list):
x = 0
n = 0
for one in input_list:
n = n + 1
@manchicken
manchicken / balanced_tree.py
Created August 30, 2013 16:42
Here's a re-implementation of my balanced binary tree in Python, but with the special bonus that this time it balances itself.
#!/usr/bin/env python
import unittest
class Node:
def __init__(self, key, data):
self.key = key
self.data = data
self.left = None
self.right = None
@manchicken
manchicken / Piece1-DestroyDetector.pm
Created August 31, 2013 21:11
DestroyDetector class, helps us to detect when a variable is garbage-collected.
package DestroyDetector;
sub new {
my ($pkg, $val) = @_;
my $self = {value=>$val};
return bless $self, $pkg;
}
sub value {
my ($self) = @_;
return $self->{value};