Skip to content

Instantly share code, notes, and snippets.

View doesTableHaveField.php
<?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))
View get_links.rb
@mweppler
mweppler / rm_svn_dirs.rb
Created Oct 6, 2012
Recursively remove .svn directories for given path
View rm_svn_dirs.rb
#!/usr/bin/env ruby
%w{fileutils}.each { |lib| require lib }
Dir.glob((ARGV[0][-1] == '/') ? ARGV[0] + '**/*' : ARGV[0] + '/**/*', File::FNM_DOTMATCH) { |node| FileUtils.rm_rf node if File.directory?(node) && File.basename(node) =~ /\.svn$/ }
@mweppler
mweppler / mv_videos_and_source.rb
Created Oct 4, 2012
Move files sorted by video/source into same directory
View mv_videos_and_source.rb
#!/usr/bin/env ruby
require 'fileutils'
Dir.glob('/Volumes/Share/Media/Videos/Software\ Training/video/*').each do |file|
fn = File.basename file, File.extname(file)
sd = File.dirname(file) + '/../' + 'source/'
sf = sd + fn + '.zip'
nd = File.dirname(file) + '/../' + fn
(File.exists? nd) ? next : Dir.mkdir(nd)
@mweppler
mweppler / emailer.rb
Created Sep 14, 2012
A ruby emailer
View emailer.rb
# http://ruby-doc.org/stdlib-1.9.3/libdoc/net/smtp/rdoc/Net/SMTP.html
require 'digest/md5'
require 'mime/types'
require 'net/smtp'
require 'optparse'
require 'ostruct'
require 'yaml'
class Emailer
@mweppler
mweppler / flat_file.rb
Created Sep 12, 2012
Incomplete implementation of a flat file storage system.
View flat_file.rb
module FlatFileProperties
def properties(*attributes)
@file_properties = attributes
end
def file_properties
@file_properties
end
end
View crawler.rb
#!/usr/bin/env ruby
require 'open-uri'
require 'nokogiri'
def get_anchors_from_html_doc html_doc
# Returns a Nokogiri::XML::NodeSet
html_doc.css('a')
end
View modal_window.js
var modal = {
modalWindow : $('#modalWindow'),
windowMask : $('#mask'),
config: {
// maskEffect : 'fadeToggle',
// maskSpeed : 'fast',
// modalEffect : 'fadeToggle',
// modalSpeed : 'fast'
},
init: function(config) {
@mweppler
mweppler / remove_new_lines.rb
Created Jan 16, 2012
Remove newlines from files
View remove_new_lines.rb
out_file = File.new("/Users/username/column_names-new.csv", "w")
File.open("/Users/username/column_names.csv", "r") do |in_file|
while line = in_file.gets
out_file.write line.tr("\n","")
end
end
@mweppler
mweppler / compare_repo.rb
Last active Sep 28, 2015
Compares file hashes
View compare_repo.rb
#!/usr/bin/env ruby
require 'digest/md5'
require 'optparse'
class RepositoryFile
attr_accessor :obj_hash, :file_hash, :file_mtime, :file_name, :file_path
def initialize(obj_hash, file_hash, file_mtime, file_name, file_path)
@obj_hash = obj_hash
@file_hash = file_hash