Skip to content

Instantly share code, notes, and snippets.

View jrotolo's full-sized avatar

Jarrod Rotolo jrotolo

View GitHub Profile

Keybase proof

I hereby claim:

  • I am jrotolo on github.
  • I am jarrodrotolo (https://keybase.io/jarrodrotolo) on keybase.
  • I have a public key ASCQRWa5lItLHjVZIYjZ68Gfcs8m-ubcdXXtx6KN95CggQo

To claim this, I am signing this object:

@jrotolo
jrotolo / base_conversion.rb
Created March 5, 2018 18:18
Change base of decimal number
ALPHABET = %w(0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z)
def change_base(number, base, result)
if number <= 0
puts result
else
result = ALPHABET[number % base] << result
change_base(number / base, base, result)
end
end
// Reverse each word in string
function reverseWords(str) {
return str.split(' ').map(function(word) {
return word.split('').reverse().join("");
}).join(" ");
}
// Reverse whole string
function reverse(str) {
return str.split("").reverse().join("");
@jrotolo
jrotolo / trim.js
Last active August 29, 2015 14:13
A simple way to add trim method to Strings in javascript
// A Simple Trim Example from Javascript The Good Parts
Function.prototype.method = function (name, func) {
if (!this.prototype[name]) {
this.prototype[name] = func;
}
return this;
};
String.method('trim', function () {
return this.replace(/^\s+|\s+$/g, '');
#!/bin/sh
cleanup()
{
DIR=~/Downloads
if [ "$(ls -A $DIR)" ]; then
echo "Total size of $DIR in KB: $(du -k $DIR | sed 's/\([0-9][0-9]*\).*/\1/')"
printf "Confirm deletions? (yes/no) "
read ANSWER
# Some simple array functions
# more from the enumerable module to come
# Filter array based on predicate
old = [3, 5, 9, 24, 2, 1, 21, 54]
new = old.keep_if { |x| x < 8 }
# Sum of every element in array
arr.reduce { |x, y| x + y }
@jrotolo
jrotolo / gist:bd2125513cdb9d26b559
Last active August 29, 2015 14:07
A simple web server written in Racket.
#lang racket
(require xml net/url)
(define (serve port-no)
(define main-cust (make-custodian))
(parameterize ([current-custodian main-cust])
(define listener (tcp-listen port-no 5 #t))
(define (loop)
(accept-and-handle listener)
@jrotolo
jrotolo / gist:c85682f5d38cb3a25e9f
Last active August 29, 2015 14:07
A basic movie database for tracking digital media collection
(defvar *db* nil)
(defun make-dvd (title director genre rating resolution fformat)
(list :title title :director director :genre genre :rating rating
:resolution resolution :fformat fformat))
(defun add-record (dvd) (push dvd *db*))
(defun dump-db ()
(format t "~{~{~a:~12t~a~%~}~%~}" *db*))