Skip to content

Instantly share code, notes, and snippets.

View geeksunny's full-sized avatar

Justin Swanson geeksunny

View GitHub Profile
@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 / 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 / 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.pagination.php
Last active December 10, 2015 17:18
Simple class for generating pagination links.
<?php
class pagination {
private $forward = true;
private $backward = true;
private $current_page;
private $last_page;
function __construct($current_page=false, $last_page=false, $generate=false) {
if ($current_page) {
$this->current_page = $current_page;
@geeksunny
geeksunny / class.yelp.php
Created January 6, 2013 12:40
A simple class for interfacing with the Yelp API.
<?php
//error_reporting("E_ALL");
//ini_set('display_errors', '1');
// ~~~ EXAMPLE CODE ~~~ //
/*
// Set your keys here
$consumer_key = "xxxxxxxxxxxxxxxxxxxxx";
$consumer_secret = "xxxxxxxxxxxxxxxxxxxxxxxxxx";
$token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
@geeksunny
geeksunny / class.urlstring.php
Created January 6, 2013 13:11
A simple class for handling URL strings for links.
<?php
class urlstring {
private $params = array();
function __construct() {
// Pulling parameters from the URL string.
$str = explode("&",$_SERVER['QUERY_STRING']);
foreach ($str as $item) {
$split = explode("=",$item);
$this->params[$split[0]] = $split[1];
@geeksunny
geeksunny / class.facebook_connect.php
Last active December 10, 2015 20:28
A simple class for interfacing with the Facebook API.
<?php
/* // EXAMPLE CODE!!!
error_reporting("E_ALL");
ini_set('display_errors', '1');
//session_start();$_SESSION = '';var_dump($_SESSION);die; // RESET SESSION
// Facebook App credentials
$app_id = "xxxxxxxxxxxxxxx";
$app_secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$my_url = "http://xxx.xxx.xxx/xxx.xxx";
@geeksunny
geeksunny / gist:5986271
Created July 12, 2013 17:39
A simple jQuery-based tooltip solution.
$('.tooltip')
.mouseenter(function(e) {
e.preventDefault();
pos = $(this).offset();
$(this).append('<div class="tooltip">'+$(this).attr('rel')+'</div>');
div = $('div.tooltip',$(this));
div.attr('top',pos['top']+5).attr('left',pos['left']).fadeIn(200);
})
.mouseleave(function(e) {
e.preventDefault();
@geeksunny
geeksunny / ssh_tunnel.py
Created October 14, 2013 15:32
A quick'n'dirty Python script for starting / stopping a port-forwarded SSH tunnel.
#!/usr/bin/python
import os # For running system commands.
import argparse # For command-line argument parsing.
## Configuration ##
__command__ = "ssh -L [LOCAL PORT]:127.0.0.1:[REMOTE PORT] [USER]@[REMOTE HOST] -f -N"
###################
## TODO ##
# * Build out the argparse system to parameterize the connection details.
@geeksunny
geeksunny / find_replace.py
Created October 14, 2013 15:37
A quick'n'dirty Python script to make find & replace operations on large text files fast and automated. Creates a duplicate file copy and leaves the original file unchanged.
#!/usr/bin/python
## Configuration ##
__target_file__ = "example.txt" # Relative path to the target file to process.
__find__ = "found" # Block of text to find.
__replace__ = "replaced" # Block of text to replace with.
###################
with open(__target_file__) as file_in: # Open source file for reading.
file_out = open(__target_file__+"_replaced", 'w') # Open destination file for writing.
for line in file_in: # Loop through source, line by line.
new_line = line.replace(__find__,__replace__) # Perform find & replace on current line.