Skip to content

Instantly share code, notes, and snippets.

@mrcsparker
mrcsparker / hackyprogress.rb
Created September 28, 2011 01:01
Sample hacky Ruby progress bar
def progress(percent)
left = 100 - percent
STDOUT.write "\r\e[0K" # clear cursor to the end of line
STDOUT.write "[#{'#' * percent}#{'.' * left}]\t[ #{percent}/100 ]"
STDOUT.flush
end
1.upto(100) do |i|
progress(i)
@mrcsparker
mrcsparker / arithmetic_evaluator.rb
Created February 21, 2012 06:27
Ruby arithmetic evaluator
# Copyright (c) 2012 Chris Parker <mrcsparker@gmail.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
@mrcsparker
mrcsparker / parslet_lr.rb
Created April 12, 2012 03:16
Parslet with proper LR support
# Evaluates expressions left to right, with presedence
# using a PEG
require "parslet"
class Parser < Parslet::Parser
root :expression
rule(:expression) { additive | block | number }
@mrcsparker
mrcsparker / test_jdbc_teradata.rb
Created September 25, 2012 17:31
Testing out Teradata JDBC / JRuby
require 'rubygems'
require 'jdbc/teradata'
require 'java'
begin
Java::com.teradata.jdbc.TeraDriver
userurl = "jdbc:teradata://10.0.1.2/DATABASE=database_name,DBS_PORT=1025,COP=OFF"
connSelect = java.sql.DriverManager.get_connection(userurl, "username", "password")
stmtSelect = connSelect.create_statement
@mrcsparker
mrcsparker / teradata_stats.rb
Created June 1, 2013 07:36
Code to automatically generate Teradata stats
# You are going to need to use jruby and install the jdbc-teradata gem
# Create a file named database.yml and fill it out. It will look something like this:
# production:
# adapter: jdbc
# driver: com.teradata.jdbc.TeraDriver
# url: jdbc:teradata://localhost/DATABASE=ods,DBS_PORT=1025,COP=OFF
# username: your_username
# password: your_password
@mrcsparker
mrcsparker / column.js
Created July 9, 2013 22:49
Playing with formula evaluation
// Eval data is coming from a secure source.
var columns = {};
columns['_A1'] = "this.A2";
columns['_A2'] = "3";
columns['_A3'] = "this.A1 + this.A2";
Object.defineProperty(columns, "A1", {
get: function() {
@mrcsparker
mrcsparker / sample.js
Created July 16, 2013 04:04
Playing with Javascript sub-classing and data hiding
var Sample = (function (Sample) {
"use strict";
var SampleColumn = (function () {
var SampleColumn = {};
SampleColumn.parseColumns = function () {
var columns = [],
@mrcsparker
mrcsparker / TeradataDump.java
Created November 16, 2013 03:56
Dump a Teradata database to MySQL. Also will work with SQLite with modifications.
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.sql.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
class TeradataDump {
# Brewfile
# `brew bundle`
install openssl
install emacs
install node
install unrar
install leiningen
install readline
install ruby-build
@mrcsparker
mrcsparker / nrepl.rb
Created June 30, 2015 04:39
NRepl for Ruby: simple nrepl client for Ruby 2+
require 'socket'
require 'bencode'
require 'securerandom'
module Loader
class NRepl
def self.connect(server, port)
new(server, port)
end