Skip to content

Instantly share code, notes, and snippets.

View tylerbuchea's full-sized avatar
💭
Hello World!

Tyler tylerbuchea

💭
Hello World!
View GitHub Profile
@tylerbuchea
tylerbuchea / combinations.js
Created April 20, 2013 01:13
All possible combinations of a string.
function combinations(str) {
var fn = function(active, rest, a) {
if (!active && !rest)
return;
if (!rest) {
a.push(active);
} else {
fn(active + rest[0], rest.slice(1), a);
fn(active, rest.slice(1), a);
}
@tylerbuchea
tylerbuchea / ftp.py
Created April 20, 2013 01:16
Comprehensive FTP class
import ftplib
from ftplib import FTP
# Ftp Class
class Ftp:
conn = False
def __init__(self, address, user, password):
self.address = address
self.user = user
@tylerbuchea
tylerbuchea / bash.py
Last active December 16, 2015 10:59
Three different ways to run bash commands.
import subprocess
#! /usr/bin/env python
import subprocess
# Use a sequence of args
return_code = subprocess.call(["echo", "hello sequence"])
# Set shell=true so we can use a simple string for the command
return_code = subprocess.call("echo hello string", shell=True)
@tylerbuchea
tylerbuchea / deploy.php
Created April 24, 2013 01:06
Automatic deployment script for git
<?php
date_default_timezone_set('America/Los_Angeles');
class Deploy {
/**
* A callback function to call after the deploy has finished.
*
* @var callback
@tylerbuchea
tylerbuchea / ansi.py
Last active December 16, 2015 15:29
ANSI escape sequences class for coloring bash output.
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
def disable(self):
self.HEADER = ''
@tylerbuchea
tylerbuchea / linkify.js
Created April 29, 2013 17:50
Turns urls within a block of text into hyperlinks.
function linkify(text) {
var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
return text.replace(exp,"<a href='$1'>$1</a>");
}
@tylerbuchea
tylerbuchea / hash.js
Last active February 1, 2016 09:52
Hash CRUD "class" for JavaScript
var HashSearch = new function () {
var params;
this.set = function (key, value) {
params[key] = value;
this.push();
};
this.remove = function (key, value) {
delete params[key];
@tylerbuchea
tylerbuchea / json-highlight.js
Created April 29, 2013 18:11
Adds span elements to parts of JSON string for post CSS manipulation.
function syntaxHighlight(json) {
if (typeof json != 'string') {
json = JSON.stringify(json, undefined, 2);
}
json = json.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
var cls = 'number';
if (/^"/.test(match)) {
if (/:$/.test(match)) {
cls = 'key';
@tylerbuchea
tylerbuchea / simulateEvent.js
Created May 27, 2013 18:36
Simulate JavaScript events
function simulateEvent(element, type) {
// Check for createEventObject
if(document.createEventObject){
// Trigger for Internet Explorer
trigger = document.createEventObject();
element.fireEvent('on' + type, trigger);
}
else {
// Trigger for the good browsers
trigger = document.createEvent('HTMLEvents');
@tylerbuchea
tylerbuchea / DOMHighlight.js
Created June 18, 2013 16:31
Adds transparent background to every node in the DOM. Allows for easy collision and overlap inspection. Ctrl-i toggles functionality.
// DOM Highlight (Ctrl-i)
$(function() {
$("<style type='text/css'> .DOMHighlight {background: rgba(0,0,0,0.1);} </style>").appendTo("head");
$('body').keypress(function(e) {
if (e.which === 9)
$('*').toggleClass('DOMHighlight');
});
})();