This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
N = 10_000_000 | |
S = 'string,' * N | |
Benchmark.bmbm do |x| | |
x.report('#count') do | |
(length = S.count(',')) && (length + 1).times{|i| "line #{i} of #{length}" } | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// -*- compile-command: "javac -Xlint Matrix.java && java Matrix" -*- | |
import java.lang.Math; | |
/** | |
* Square matrix class. | |
* | |
* @author Jon-Michael Deldin <[email protected]> | |
*/ | |
public class Matrix { | |
private int N; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# sampling.rb -- approximate the probability distribution of Pr[A,B|-C,+F] | |
# | |
# Author: Jon-Michael Deldin | |
def label_table(label, n, fields) | |
puts "#{label} (n = #{n}):" | |
hdr = "%-15s %-10s" % fields | |
puts hdr | |
puts "-" * hdr.length | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def add_vectors(x, y); x.zip(y).map { |xj, yj| xj + yj }; end | |
def mult_scalar_to_vector(x, vec); vec.map { |v| v * x }; end | |
def dot_product(vec1, vec2) | |
vec1.zip(vec2).map { |v1, v2| v1 * v2 }.reduce(:+) | |
end | |
# Hypothesis function | |
# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* reader.cc -- demonstrate the inanity of line endings | |
* | |
* compile with | |
* g++ -Wall -ansi -pedantic reader.cc -o reader | |
* run it with | |
* ./reader some_file.txt | |
* | |
* You can create Windows line endings in Vim with :se ff=dos and Unix files | |
* with :se ff=unix (or run dos2unix and unix2dox on a text file). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# | |
# Clears all IPC queues. | |
# | |
# Author: Jon-Michael Deldin <[email protected]> | |
# | |
# different position of the queue id on Linux | |
`ipcs -q`.scan(/^q (\d+)/) do |m| | |
puts "removing #{m.first}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# from http://stackoverflow.com/questions/13149146/ruby-rails-determine-if-variable-is-a-number | |
require 'benchmark' | |
def is_num_e(num_given) | |
!!Integer(num_given) rescue false | |
end | |
def is_num_r(num_given) | |
num_given =~ /\d+(\.\d+)?/ | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun get-last-modifed (file) | |
"Returns the last modified date of a FILE." | |
(interactive) | |
(format-time-string "%Y-%m-%d %T" | |
(nth 5 (file-attributes file)))) | |
(defun most-recent-p (file1 file2) | |
"Returns t if FILE1 was modified more recently than FILE2." | |
(string< (get-last-modifed file1) (get-last-modifed file2))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def disable_ar | |
class << ActiveRecord::Base | |
def fail_connection; fail 'Tried to access the DB'; end | |
alias_method :old_connection, :connection | |
alias_method :connection, :fail_connection | |
end | |
end | |
def restore_ar | |
class << ActiveRecord::Base |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Jon-Michael Deldin | |
## Pattern Recognition, SP 2013 | |
## LDA Project | |
## | |
## Usage: | |
## Rscript lda.R | |
## | |
## clear existing vars | |
rm(list = ls(all=TRUE)) |