Skip to content

Instantly share code, notes, and snippets.

View geeksunny's full-sized avatar

Justin Swanson geeksunny

View GitHub Profile
@geeksunny
geeksunny / gist:2502609
Created April 26, 2012 20:02
A PHP function to determine if a given IP address lies within a given range.
<?php
function check_ip_range($target, $range_start, $range_end)
{
if (ip2long($target) >= ip2long($range_start) && ip2long($target) <= ip2long($range_end))
return true;
else
return false;
}
@geeksunny
geeksunny / string_tools.php
Created May 15, 2012 05:25
stringTools: an interface to quickly automate common string conversion tasks.
<?php
/**
* StringTools
* Justin Swanson
* www.github.com/geeksunny | www.faecbawks.com | www.h4xful.net
*
* An example of this script can be found at http://beta.h4xful.net/tools/string_tools.php
*/
if (isset($_POST['mode']))
{
@geeksunny
geeksunny / gist:2818423
Created May 28, 2012 10:34
A folder-action script to automatically add new files to the iTunes library
global app_state
-- check if itunes is running
set app_state to false
tell application "System Events"
if (exists process "iTunes") then set app_state to true
end tell
-- Adding files to the iTunes library when they are added to the watched folder
on adding folder items to my_folder after receiving the_files
@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 __
@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 / 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 / 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 / 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 / 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: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.