Skip to content

Instantly share code, notes, and snippets.

View jarsen's full-sized avatar

Jason Larsen jarsen

View GitHub Profile
@jarsen
jarsen / nfa_converter.rb
Created May 18, 2009 07:06
For a cs theory class. Will take a NFA-lambda machine and print out it's corresponding DFA
#!/usr/bin/env ruby -wKU
#nfa_converter.rb
# 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
jarsen / contacts.rb
Created May 25, 2009 23:53
just something I cooked up real quick to show Art ruby's expressive power after he had done this same project in C++
#!/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
end
def to_s
@jarsen
jarsen / installing everything.txt
Created July 18, 2009 04:59
the commands i use to install set up everything on my ubuntu 9.04 server edition
THE SUPER SCRIPTS
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 http://rubyforge.org/frs/download.php/58677/ruby-enterprise-1.8.6-20090610.tar.gz; sudo tar xvzf ruby*; cd /ruby*; sudo ./installer
wget http://rubyforge.org/frs/download.php/59007/passenger-2.2.4.tar.gz; sudo tar xzvf passenger-2.2.4.tar.gz -C /opt/;
wget http://sysoev.ru/nginx/nginx-0.8.5.tar.gz; t
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
#!/usr/local/bin/ruby
# 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 - http://oreilly.com/pub/ht/113
import sys
import socket
import string
HOST="irc.freenode.net"
PORT=6667
NICK="MauBot"
IDENT="maubot"
REALNAME="MauritsBot"
# 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;
// 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>
#!/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