Skip to content

Instantly share code, notes, and snippets.

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

Tyler tylerthebuildor

💭
Hello World!
View GitHub Profile
@tylerthebuildor
tylerthebuildor / 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);
}
@tylerthebuildor
tylerthebuildor / 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
@tylerthebuildor
tylerthebuildor / 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)
@tylerthebuildor
tylerthebuildor / 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
@tylerthebuildor
tylerthebuildor / 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 = ''
@tylerthebuildor
tylerthebuildor / 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>");
}
@tylerthebuildor
tylerthebuildor / 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];
@tylerthebuildor
tylerthebuildor / 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';
@tylerthebuildor
tylerthebuildor / 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');
@tylerthebuildor
tylerthebuildor / 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');
});
})();