Skip to content

Instantly share code, notes, and snippets.

View hjc's full-sized avatar

Hayden Chudy hjc

  • Mobile, AL
  • 19:50 (UTC -05:00)
View GitHub Profile
@hjc
hjc / oo_example.rb
Created January 8, 2013 08:31
A simple script that shows how Ruby's basic OO concepts work and some common errors.
# Simple example of basic object oriented concepts and how they work in Ruby
#
# AUTHOR: HAYDEN CHUDY
# First is instance and class variable example
# parent class, keep track of the count of all its children
class Shape
# count class variable. Keeps count of all shapes we have made, in general
@hjc
hjc / analyzer.rb
Created January 4, 2013 06:36
Simple Ruby Text Analyzer. Grabs simple document metrics from a text file, such as sentence count, word count, average words per sentence, etc.
#
# TEXT ANALYZER
# BY: Hayden Chudy
#
# basic setup for text analysis
stopwords = %w{the a by on for of are with just but and to the my I has some in}
lines = File.readlines(ARGV[0])
line_count = lines.size
text = lines.join
@hjc
hjc / Fixnum_DateTime_Extensions.rb
Last active December 10, 2015 10:08
Simple extension of Fixnum to help with manipulating dates and times.
class Fixnum
def seconds
self
end
def minutes
self * 60
end
def hours
self * 60 * 60
end
@hjc
hjc / add_to_assoc_ordered+numeric.php
Last active October 2, 2015 01:57
PHP: Add a key to an associative array and keep it's key ordering intact and sequential
/**
* Implements add_to_assoc_numeric
*
* Goal of this function is to allow us to modify an associative, numeric array
* (one that uses string numbers as keys, so there is no 0,1,2,3 ordering, but
* rather the ordering is based on when the keys were inserted [they are treated
* like other string keys]). If we modify this array using array_unshift or
* array_shift, we destory this associative, numeric structure (each key is
* destroyed and the array is simply renumbered, with ints, from 0 to num_elems),
* which we don't want. This function will allow us to insert a new value anywhere