Skip to content

Instantly share code, notes, and snippets.


Jason Larsen jarsen

View GitHub Profile
jarsen / nfa_converter.rb
Created May 18, 2009
For a cs theory class. Will take a NFA-lambda machine and print out it's corresponding DFA
View nfa_converter.rb
#!/usr/bin/env ruby -wKU
# converts a given NFA-lambda to it's corresponding DFA and prints
# corresponding transition rules.
$: << File.expand_path(File.dirname(__FILE__))
require 'NFA'
ARGV.each do |fileName| # each argument passed through bash is a file to convert
jarsen / contacts.rb
Created May 25, 2009
just something I cooked up real quick to show Art ruby's expressive power after he had done this same project in C++
View contacts.rb
#!/usr/bin/env ruby -wKU
class Contact
attr_accessor :name, :address, :city, :state, :zip_code, :phone
def initialize( name, address, city, state, zip_code, phone )
@name, @address, @city, @state, @zip_code @phone = name, address, city, state, zip_code, phone
def to_s
jarsen / installing everything.txt
Created Jul 18, 2009
the commands i use to install set up everything on my ubuntu 9.04 server edition
View installing everything.txt
sudo aptitude update; sudo aptitude safe-upgrade; sudo reboot
sudo aptitude -y install build-essential; sudo aptitude -y install php5-cgi php5-mysql php5-xcache php5-common php5-dev php5-sqlite php5-tidy php5-xmlrpc php5-xsl php5-mcrypt php5-curl php5-gd php5-memcache php5-mhash php5-pspell php5-snmp php5-sqlite libmagick9-dev php5-cli php5-xcache subversion git-core libreadline5-dev; sudo aptitude -y install php-pear; sudo aptitude -y install imagemagick; sudo pecl install imagick; sudo aptitude -y install mysql-server mysql-client libmysqlclient15-dev; mysql_secure_installation; sudo aptitude -y install libpcre3 libpcre3-dev libpcrecpp0 libssl-dev zlib1g-dev; mkdir ~/src/; cd ~/src/; wget; sudo tar xvzf ruby*; cd /ruby*; sudo ./installer
wget; sudo tar xzvf passenger-2.2.4.tar.gz -C /opt/;
wget; t
View rel_prime.rb
print "x = "
x = gets.chomp.to_i
print "y = "
y = gets.chomp.to_i
# repeat until y = 0
until y == 0
# Assign x <- x mod y
puts "x = #{x} % #{y} = #{x%y} "
x = x % y
View crawler.rb
# crawler.rb
# by: Jason Larsen
# a generic web crawler that allows the user to do whatever they want by passing blocks
# @version 0.7
# 14 Dec 2009
# 0.6 things seem to be working well
# 0.7 modified so that URL's being added to the queue truncate fragments,
# this should save a lot of work
# from IRC hacks -
import sys
import socket
import string
View .bashrc
# this is my simple, humble .bashrc file
alias ls='ls --color=auto'
alias ll='ls -l'
alias la='ls -A'
alias l='ls -CF'
alias crawler='cd ~/code/webcrawler;clear'
alias e='gedit'
void HTML::parse_links() {
string::const_iterator start, end;
start = src.begin();
end = src.end();
boost::match_results<std::string::const_iterator> what;
// handles single,double, and no quotes, and space/newlines, etc
boost::regex hrefs("href(\\s*)=(\\s)*[\"']?(.*?)[\"']?(\\s)*>",boost::regex_constants::icase);
while(boost::regex_search(start, end, what, hrefs)) {
cout << "link: " << string(what[3].first, what[3].second) << endl;
View telme.c
// Author: Jason Larsen
// Project: A program that downloads a webpage using an HTTP GET request. I probably
// will never use this because I'll just use curl -I anyway... but it was fun
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
View regexs.rb
#!/usr/bin/env ruby -wKU
require 'highline/import'
letters_only = /^[a-z]+$/i
phone_number = /^\(\d{3}\)\s?\d{3}-\d{4}$/
numbers_below_18 = /^(([0-1]?[0-8])|(-\d*))$/
html_tag = /^<([A-Z]*)>(.*)<\/\1>$/
input = ask "Input text: "
until input == "quit" do
puts case input