Skip to content

Instantly share code, notes, and snippets.

View geeksunny's full-sized avatar

Justin Swanson geeksunny

View GitHub Profile
@geeksunny
geeksunny / csv_split.py
Created November 26, 2012 08:18
csv file splitter
import csv
# Configuration
header_line = 1
limit = 65000
target_file = 'file-to-split.csv'
# Initial output file
iterator = 0
new_file_prefix = target_file.replace('.csv','')+'_split_'
file_num = 1
# Reading file
@geeksunny
geeksunny / class.divide_num.php
Created October 19, 2012 07:20
A simple PHP class to evenly distribute an integer across a set of multiple integer values.
<?php
//error_reporting(E_ALL);
//ini_set('display_errors', '1');
$dv = new divide_num(101);
$arr = array(111, 222, 333);
var_dump($arr);
foreach ($arr as $key=>$ar) {
@geeksunny
geeksunny / gist:3376694
Created August 17, 2012 07:17
parseSshConfig: My first ever from-scratch Objective-C program. Parses the contents of your .ssh config file into a dictionary variable. To be used in a future project. -- UPDATED: 2012-09-27 00:13:12 - Rewrote parsing logic to be much more flexible!
//
// main.m
// parseSshConfig
//
// "A very simple .ssh config file parser."
//
// Created by Justin Swanson on 8/17/12.
// Copyright (c) 2012 h4xful.net. All rights reserved.
//
@geeksunny
geeksunny / gist:3346990
Created August 14, 2012 06:46
Fix for PyQt's _triggered() functions being double called.
# Instead of this...
def on_actionBuild_Zip_triggered(self):
[...]
# ... We do this.
def on_actionBuild_Zip_triggered(self, checked=None):
if checked is None: return # Makes certain the action does not get ran twice.
[...]
# This ensures that when it does get called twice, the second time will be ignored immediately.
@geeksunny
geeksunny / gist:3346809
Created August 14, 2012 06:09
A simple console data input function with rudimentary type validation for Python.
def data_input(type, prompt):
# Initialize variables.
valid = False
return_value = False
# Loop until data input is valid.
while valid == False:
input = raw_input(prompt)
try:
if type == 'int':
return_value = int(input)
@geeksunny
geeksunny / gist:3322352
Created August 11, 2012 08:00
An AppleScript file to open a new tab in Terminal.app and immediately execute a given command.
on run argv
if (count argv) is not equal to 0 then
tell application "Terminal"
activate
tell application "System Events" to tell process "Terminal.app" to keystroke "t" using command down
do script item 1 of argv in front window
end tell
#else
# display alert "Oops!" message "You didn't pass any parameters to this script!" as critical
end if
@geeksunny
geeksunny / build.py
Created July 25, 2012 07:39
Custom universal scripts for PyQt projects. -- pyqt_template.py: Generic boilerplate for new PyQt projects. -- compile.py: Generic compile script for .ui and .rsc files. -- build.py: Automated .app building & trimming for Py2App projects on OSX.
#!/usr/local/bin/python2
import os # For running system commands.
import argparse # For argument parsing.
# Configuration
_setup_file_ = 'setup.py' # Your Py2App setup file.
_app_file_ = 'start.py' # Should mirror the APP variable in your Py2App setup file.
_delete_ = ['Frameworks/QtDeclarative.framework', 'Frameworks/QtMultimedia.framework', 'Frameworks/QtScript.framework', 'Frameworks/QtSvg.framework','Frameworks/QtXml.framework', 'Frameworks/QtDesigner.framework', 'Frameworks/QtNetwork.framework', 'Frameworks/QtScriptTools.framework','Frameworks/QtTest.framework', 'Frameworks/QtXmlPatterns.framework', 'Frameworks/QtHelp.framework', 'Frameworks/QtOpenGL.framework','Frameworks/QtSql.framework', 'Frameworks/QtWebKit.framework', 'Frameworks/libQtCLucene.4.dylib', 'Frameworks/phonon.framework', 'Frameworks/*.framework/*.prl'] # Files within [name].app/Contents/ to be deleted during the trimming process.
# DU function... uses the system's du command because Python's os.w
@geeksunny
geeksunny / n00b.py
Created July 23, 2012 00:21
A Python script to determine an arbitrary date to name as the birthday of our adopted stray cat, n00blet.
#!/usr/bin/python
name = 'n00blet'
# adopted: march 11, 2011 (the 3rd month of the year)
# born: ~june 2010? (Was approximately 9 months old at time of adoption.)
def strToInt(string):
total = 0
for letter in string:
total += ord(letter)
@geeksunny
geeksunny / osxTweaks.py
Created June 21, 2012 05:56
osxTweaks: A simple Python script for easily toggling a few options in OSX.
#!/usr/bin/python
__author__ = 'Justin Swanson'
__version__ = '0.2'
import os # For running system commands & getting directory contents.
# Configuration dictionary variable: Will store the live OS's config status
configuration = {}
### Clear screen function... clears the command prompt window.
@geeksunny
geeksunny / betterTwitter.user.js
Created May 29, 2012 05:44
A Chrome/GreaseMonkey compatible user script flip the layout of twitter.com and remove extraneous data.
// ==UserScript==
// @name betterTwitter
// @version 0.5
// @namespace http://www.h4xful.net/
// @description Gets rid of the garbage on Twitter's side-panel.
// @include http://twitter.com/*
// @include https://twitter.com/*
// ==/UserScript==
// __ Change Log __