Skip to content

Instantly share code, notes, and snippets.

@jtprince
jtprince / generate_fake_peak.rb
Created April 15, 2014 21:27
Creates a gamma distribution peak, then adds noise in both x and y values. Writes out a CSV file and plots the thing.
#!/usr/bin/env ruby
require 'distribution'
require 'gnuplot'
require 'csv'
params = {
step: 0.01,
stop: 1.0,
xwiggle: 0.01,
@jtprince
jtprince / risk2_saver.rb
Created May 29, 2014 16:50
Save and load your Risk II (Hasbro Interactive) game with this simple ruby GUI
require 'Win32API'
require 'fileutils'
require 'tk'
# supposed to hide base window... not working with cygwin ruby
getConsoleWindow = Win32API.new("kernel32" , "GetConsoleWindow" , [] , 'L')
ptr_to_console = getConsoleWindow.call()
wndConsole = Win32API.new( "user32" , "ShowWindow" , ['p' , 'i'] , 'i' )
wndConsole.call( ptr_to_console , 1 )
@jtprince
jtprince / Rakefile
Last active August 29, 2015 14:04
Rakefile Template (after "bundle gem <some_gem>")
require "bundler/gem_tasks"
@module_name = Mspire::Mass
@gem_name = 'mspire-mass'
@gem_path_name = @gem_name.gsub('-','/')
require "#{@gem_path_name}/version"
require 'rspec/core'
require 'rspec/core/rake_task'
@jtprince
jtprince / opening_an_inherited_class.rb
Created August 1, 2014 04:52
ruby, do I need to include the inheritance each time I open a class? Answer: NO (but the inheritance must be there the 1st time or you'll get a superclass mismatch TypeError)
# [be careful, though, if you switch the order of introduction, then you will get this error:
# <file>.rb:11:in `<main>': superclass mismatch for class Dog (TypeError)
class Dog < Hash
def silly(key)
self[key] = 88 + key.to_i
end
end
# This is the *key* point: we can re-open this class and it won't give us any trouble!
class Dog
@jtprince
jtprince / drop_tables_matching_regexp.py
Created September 19, 2014 23:46
delete all tables in an sqlite database that match a regular expression
#!/usr/bin/env python
import sys
import sqlite3
import argparse
import re
parser = argparse.ArgumentParser(description='deletes tables matching some regular expression')
parser.add_argument('database', help='the database file')
parser.add_argument('regexp', help='the regexp you are matching')
@jtprince
jtprince / __init__.py
Last active August 29, 2015 14:06
dynamically include all files in folder with the package (and alternatively import each of those source files)
import os
_python_source_files = list(
filter(
lambda basename: basename.endswith(".py") and
not basename.startswith('_'),
os.listdir( os.path.dirname(os.path.realpath(__file__)) )
)
)
@jtprince
jtprince / quiet boot for arch
Created December 11, 2014 01:27
some notes on quiet boot in arch
# for syslinux, you want something like this:
APPEND root=/dev/sda2 rw vga=current quiet loglevel=0
# OR
APPEND root=/dev/sda2 rw vga=865 quiet loglevel=0
# edit the files systemd-fsck-root.service and systemd-fsck@.service located at /usr/lib/systemd/system/ to configure StandardOutput and StandardError like this:
(...)
[Service]
Type=oneshot
import scipy.stats as sts
from math import log
def fisher_combine_p_values(pvalues):
degrees_freedom = 2*len(pvalues)
summed = sum(-2*log(pval) for pval in pvalues)
return 1.0 - sts.chi2.cdf(summed, degrees_freedom)
#print(fisher_combine_p_values( [0.05, 0.05] ))
# Very simple tk application to save progress on Microprose's Risk II game
# (written many years ago)
#
# Create a bat file to run, like this:
# ----save_risk.bat----
# c:\cygwin\bin\rubyw /home/john/risk2_saver.rb c:/Users/john/Desktop/RISK_SAVES
require 'Win32API'
require 'fileutils'
require 'tk'
#!/usr/bin/env ruby
# for working with Doba_Product descriptions
require 'redcarpet'
if ARGV.size == 0
puts "usage: #{File.basename(__FILE__)} <file>.txt ..."
puts "output: text and html, ready for sql upload"
puts ""
puts "notes:"