Skip to content

Instantly share code, notes, and snippets.

View samullen's full-sized avatar

Samuel Mullen samullen

View GitHub Profile
@samullen
samullen / todo.rb
Last active August 29, 2015 14:08
Very basic todo script for use in an "Intro to Ruby" project I'm developing.
#!/usr/bin/env ruby
require "date"
class Todo
attr_accessor :complete
attr_reader :name, :due_on
def initialize(name, due_on=nil, complete=false)
@name = name
#!/usr/bin/env ruby
require 'rb-inotify'
notifier = INotify::Notifier.new
notifier.watch("/path/to/watch", :moved_to, :create) do |event|
puts "I found #{event.name}!"
end
notifier.run
@samullen
samullen / blueprints.rb
Created January 28, 2010 14:56
Testing MongoMapper with Machinist
require 'machinist/mongomapper'
require 'sham'
require 'faker'
Sham.define do
username { Faker::Internet.user_name }
email { Faker::Internet.email }
# confirmed_at { ...date... }
# confirmation_sent_at { ...date... }
# remember_token { 'Cj4ja2A3Xp6MEK6rdUej' }
#!/usr/bin/env ruby
require 'rubygems'
require 'basic_daemon'
class MyDaemon < BasicDaemon
def run
foo = open("/tmp/out", "w")
i = 1
#!/usr/bin/env ruby
require 'rubygems'
require 'basic_daemon'
basedir = "/tmp"
d = BasicDaemon.new
# for restarts to work properly, you can't use anonymous blocks. In other
# requires and stuff go here
def load_irbrc(path)
return if (path == ENV["HOME"]) || (path == '/')
load_irbrc(File.dirname path)
irbrc = File.join(path, ".irbrc")
load irbrc if File.exists?(irbrc)
@samullen
samullen / last_day_of_month.rb
Created April 30, 2010 14:01
find the last day of the month
require 'date'
(Date.new(year, 12, 31) << (12-month)).day # Ruby 1.8.x
Date.new(2010, 12, 31).prev_month(12 - 4).day # Ruby 1.9.x
@samullen
samullen / mp.html
Created August 1, 2010 13:55
mp.html
<div id="message-popdown" class="grid_12">
<% if flash[:error_msg] %>
<span class="error-msg"><%= flash[:error_msg] %></span>
<% elsif flash[:success_msg] %>
<span class="success-msg"><%= flash[:success_msg] %></span>
<% elsif flash[:warning_msg] %>
<span class="warning-msg"><%= flash[:warning_msg] %></span>
<% elsif flash[:message] %>
<span class="notice-msg"><%= flash[:message] %></span>
<% end %>
@samullen
samullen / mp.css
Created August 1, 2010 13:56
mp.css
#message-popdown {
background-color: #dea852;
display: none;
position: fixed;
z-index: 999;
cursor: pointer;
padding-top: 20px;
padding-bottom: 20px;
-webkit-border-bottom-right-radius: 10px;
-webkit-border-bottom-left-radius: 10px;
@samullen
samullen / mp.js
Created August 1, 2010 13:56
mp.js
if (!RegExp(/^\s*$/).test($("#message-popdown").html())) {
$("#message-popdown").slideDown("slow", function() {
var that = $(this);
setTimeout(function() {that.slideUp();}, 5000);
});
}
$("#message-popdown").click(function() {
$(this).slideUp();
});