Skip to content

Instantly share code, notes, and snippets.

View alanjcfs's full-sized avatar
🧏‍♂️

Alan Fung-Schwarz alanjcfs

🧏‍♂️
View GitHub Profile
@alanjcfs
alanjcfs / heap_in_ruby
Created August 27, 2011 00:02
An attempt at implementing Priority Queue through solely Ruby
class Binary_heap
def initialize(num = 10)
@ary = Array.new
num.times do @ary << rand(100) end
end
attr_reader :items, :ary
def binary_heap()
@ary.unshift(nil)
@alanjcfs
alanjcfs / dayth of the year
Created September 5, 2011 04:48
Will return the day of the year in a sentence form
t = Time.now
dayth = t.yday
last_digit = dayth.to_s.slice(-1, 1).to_i
def ordinal(last_digit)
case last_digit
when 1
"st"
when 2
"nd"
# Rock Paper Scissors is a usual game
class Opponent
def initialize
@rps = ['rock', 'paper', 'scissors']
end
def play
@rps[rand 3]
end
class Client < ActiveRecord::Base
attr_accessible :first_name, :last_name, :middle_initial, :suffix,
:email, :email_2, :phone, :using, :phone_2, :using_2,
:age_group, :communication_types, :funder,
:street_address, :street_address_2, :city, :county, :zip_code, :state,
:permission_to_photograph, :mailing_list, :email_or_letter,
:notes
validates :first_name, presence: true, length: { maximum: 15 }
validates :last_name, presence: true, length: { maximum: 15 }
@alanjcfs
alanjcfs / grid-question-test.rb
Created April 2, 2013 22:49
sample file for creating a grid question using surveyor
survey "Grid question test", default_mandatory: false do
section 'Communication Skills' do
grid 'Identify communication and interviewing skills' do
a 'Yes'
a 'No'
q 'Able to articulate job duties and skills', pick: :one
q 'Easily understood, clear', pick: :one
q 'Demonstrates good listening skills', pick: :one
q 'Professional via phone/email and in person', pick: :one
object FizzBuzz {
def convertToFizzBuzz(listOfNumber: List[Int]): List[String] = {
listOfNumber.map((i: Int) => fizzbuzz(i))
}
def fizzbuzz(n: Int): String = {
if (n % 3 == 0 && n % 5 == 0) { "FizzBuzz" }
else if (n % 3 == 0) { "Fizz" }
else if (n % 5 == 0) { "Buzz" }
else { n.toString }
@alanjcfs
alanjcfs / generalizefizzbuzz.scala
Last active December 17, 2015 13:29
This is an attempt to generalize FizzBuzz based on my current Scala understanding.
import scala.collection.SortedMap
object FizzBuzz {
def generator(mapping: SortedMap[Int, String], lst: List[Int]): List[String] = {
// sort Map descending - Unimplemented
// Something very simple
// (n: Int) => {
var checkTime = function(){
currTime = myPlayer.currentTime();
if (currTime >= 3 && currTime <= 4 && hsh['calendar'] === false) {
hsh['calendar'] = true;
$('.fc-highlight-this').effect("highlight", 3000);
}
if (currTime >= 13 && currTime <= 14 && hsh['always'] === false) {
hsh['always'] = true;
$('.always span').effect("highlight", {color: '#83c0ff',
@alanjcfs
alanjcfs / xmonad.hs
Created July 24, 2014 18:11
xmonad config (provided by Fedora with some of my modifications)
-- default desktop configuration for Fedora
import System.Posix.Env (getEnv)
import Data.Maybe (maybe)
import XMonad
import XMonad.Config.Desktop
import XMonad.Config.Gnome
import XMonad.Config.Kde
import XMonad.Config.Xfce
use std::old_io::net::tcp::TcpStream;
fn main() {
// use std::old_io::net::ip::{Ipv4Addr, SocketAddr};
// let SocketAddress = SocketAddr { ip: "irc.freenode.net", port: "6667" };
let mut g = 1;
{
let mut stream = TcpStream::connect("irc.freenode.net:6667").unwrap();
let _ = stream.write_all(b"NICK simplerustbot\r\n");