Skip to content

Instantly share code, notes, and snippets.

<?php
$field = "field";
$hasField = false;
$table = "table";
$connect = @mysql_connect("host","username","password");
if (!$connect) echo "Server error: CONN";
$select_db = mysql_select_db("database");
if (!$select_db) echo "Server error: DB";
$result = mysql_query("SHOW COLUMNS FROM $table");
while ($row = mysql_fetch_array($result))
@mweppler
mweppler / drop_tables.sh
Created November 29, 2012 00:54
Drop mysql tables in given database
#!/bin/bash
USER="$1"
PASS="$2"
DB="$3"
if [ $# -ne 3 ]
then
echo "Usage: $0 {MySQL-User-Name} {MySQL-User-Password} {MySQL-Database-Name}"
echo "Drops all tables from a MySQL"
exit 1
@mweppler
mweppler / site-manager.rb
Last active December 13, 2015 20:28
THIS IS STILL A WORK IN PROGRESS... If this is the first time running site-manager use the --setup switch I got tired of manually setting up a new site that I have to work on. I use Pow for RoR, rack/sinatra apps, static html sites, and proxy to apache via port 81 for anything else. This script makes a few assumptions about your environment, and…
#!/usr/bin/env ruby
###############################################################################
# Required Application Libraries #
###############################################################################
%w{ rubygems optparse ostruct socket yaml }.each { |lib| require lib }
###############################################################################
@mweppler
mweppler / fsmsim.rb
Last active December 15, 2015 08:08
Fsm Simulator from Udacity CS262 implemented in ruby...
# FSM Simulation
edges = {
[1, 'a'] => 2,
[2, 'a'] => 2,
[2, '1'] => 3,
[3, '1'] => 3
}
accepting = [3]
do () ->
namespacer = (ns, obj) ->
if not typeof ns == "string" or not ns.length
throw new Error '[namespacer] Invalid namespace'
namespace = @
namespace = namespace[part] = namespace[part] or {} for part in ns.split '.'
namespace[attr] = obj[attr] for attr of obj if typeof obj == 'object'
namespace
@['namespacer'] = @['ns'] = namespacer
@mweppler
mweppler / cache.rb
Last active December 17, 2015 03:09
Ruby implementation of the python Cache class from Box CRE "The 'One' Thing" by Peter Potrebic
#!/usr/bin/env ruby
# Ruby implementation of the python Cache class from Box CRE "The 'One' Thing" by Peter Potrebic
$store = {}
$namespace = 'rcache'
class Cache < Object
def initialize(cache_name)
store = {}
store.setdefault = (key, def) ->
@[key] = def unless @[key]
@[key]
namespace = 'pcache'
formatKey = ->
[].slice.call(arguments).join '.'
@mweppler
mweppler / link_helper.rb
Created September 5, 2013 23:55
wip - liquid tag plugin to build links...
def titlize(the_title)
system("echo '#{the_title.downcase.gsub!(' ', '-')}' | pbcopy")
end
@mweppler
mweppler / n_instruction_programs.rb
Created October 3, 2011 00:51
A programming language has 10 different instructions. How many five-instruction programs can be written in this language if no instruction is repeated? How many seven-instruction programs?
#!/usr/bin/ruby
def factorial n
f = n
for i in (n - 1).downto(1)
f *= i
i -= 1
end
return f
end