Skip to content

Instantly share code, notes, and snippets.

View hrs's full-sized avatar

Harry R. Schwartz hrs

View GitHub Profile
@hrs
hrs / wombat.rb
Created June 22, 2014 15:04
Illustrate differences between private and public
# The key difference between public and private methods is that you
# can call public methods on instances of the class, but you can't
# call private methods on instances of the class.
# You can only call private methods *inside* the class. It's fine for
# a public method to call a private method, but you can't call a
# private methods directly on an instance.
class Wombat
def eat_bacon
@hrs
hrs / decks.txt
Created June 19, 2014 17:26
Decks for the flashcard problem
2
french
2
chat
cat
papillon
butterfly
spanish
2
gato
@hrs
hrs / intro-to-emacs-lisp.el
Created June 19, 2014 17:02
Code used in my Emacs Lisp talk
;;; An Introduction to Emacs Lisp
;;; Harry Schwartz, 2014
;; What we'll be covering:
'(atoms
functions
lists
variables
defining-functions
@hrs
hrs / zeller.rb
Created June 19, 2014 16:57
Implementation of Zeller's algorithm
def weekday(day, month, year)
day_names = %w(Saturday Sunday Monday Tuesday Wednesday Thursday Friday)
century = (year.to_f / 100.0).floor
year_of_century = year % 100
month += 12 if month < 3
h = (day +
((13 * (month + 1)) / 5.0).floor +
year_of_century +
(year_of_century / 4.0).floor +
@hrs
hrs / brainfuck.rb
Created June 18, 2014 18:25
Brainfuck interpreter
class Brainfuck
attr_reader :data, :data_pointer, :instruction_pointer, :code
def initialize(code)
@data = Hash.new(0)
@data_pointer = 0
@instruction_pointer = 0
@code = code
end
@hrs
hrs / alligators.cpp
Last active December 26, 2015 03:38
the alligators are heading east, unobfuscatedly.
int even_sum = 0;
int input = 0;
bool is_even = false;
cin >> input;
while (input > 0) {
is_even = ! (input % 2);
if (is_even) {
@hrs
hrs / random_emoji.rb
Created September 25, 2013 21:23
Generate a random GitHub emoji.
#!/usr/bin/env ruby
# Because sometimes you need a script that generates a random
# Github-compatible emoji.
emoji = %w{+1 -1 100 1234 8ball a ab abc abcd accept aerial_tramway
airplane alarm_clock alien ambulance anchor angel anger angry
anguished ant apple aquarius aries arrow_backward arrow_double_down
arrow_double_up arrow_down arrow_down_small arrow_forward
arrow_heading_down arrow_heading_up arrow_left arrow_lower_left
@hrs
hrs / obfuscated_christmas.c
Last active September 26, 2015 09:18
An Obfuscated Christmas
#include <stdio.h>
main(t,_,a)
char *a;
{
return!0<t?t<3?main(-79,-13,a+main(-87,1-_,main(-86,0,a+1)+a)):
1,t<_?main(t+1,_,a):3,main(-94,-27+t,a)&&t==2?_<13?
main(2,_+1,"%s %d %d\n"):9:16:t<0?t<-72?main(_,t,
"@n'+,#'/*{}w+/w#cdnr/+,{}r/*de}+,/*{*+,/w{%+,/w#q#n+,/#{l+,/n{n+,/+#n+,/#\
;#q#n+,/+k#;*+,/'r :'d*'3,}{w+K w'K:'+}e#';dq#'l \
q#'+d'K#!/+k#;q#'r}eKK#}w'r}eKK{nl]'/#;#q#n'){)#}w'){){nl]'/+#n';d}rw' i;#\