Skip to content

Instantly share code, notes, and snippets.

View ryanseys's full-sized avatar
🌴

Ryan Seys ryanseys

🌴
View GitHub Profile
@ryanseys
ryanseys / reverse.py
Created January 17, 2013 15:14
Reverse a string in Python
def reverse(s):
return s[::-1]
@ryanseys
ryanseys / fib_r.rb
Created January 20, 2013 18:51
Recursive Fibonacci solution
def fib_r(n)
if(n <= 1)
return 1
else
return fib(n-1) + fib(n-2)
end
end
@ryanseys
ryanseys / fib_i.rb
Created January 20, 2013 18:58
Iterative Fibonacci Solution
def fib_i(n)
result = p1 = p2 = 1;
if(n > 1)
for i in 1..n
result = p1 + p2
p2 = p1
p1 = result
end
end
return result
@ryanseys
ryanseys / print_s.c
Created January 20, 2013 19:10
Print string using no loops in C
#include <stdio.h>
void print_s(const char * s) {
if(*s != 0) {
putchar(*s);
print_s(s+1);
}
}
int main() {
@ryanseys
ryanseys / print_s_r.c
Created January 20, 2013 19:16
Print a reverse string using no loops in C
#include <stdio.h>
void print_s_r(const char * s) {
if(*s != 0) {
print_s_r(s+1);
putchar(*s);
}
}
int main() {
@ryanseys
ryanseys / play_mp3.rb
Created April 3, 2013 03:37
Play MP3 file in terminal using Ruby
pid = fork{ exec 'afplay', "song.mp3" } # on mac osx
@ryanseys
ryanseys / LinkEntry.java
Created April 5, 2013 04:52
Queue Data Structure in Java
/**
* "LinkEntry" class.
* This is an entry (or node) for a linked list containing an
* object of type E as the entry's data.
* @author Ryan Seys
*
* @param <E> the type of element which makes up the link entry.
*/
public class LinkEntry<E> {
protected E element; // The entry's data.
@ryanseys
ryanseys / FixLyricsWorkingWithSelection.scpt
Last active December 15, 2015 20:09
Remove excess strings from lyrics which are inserted and generated from the app "Get Lyrical".
(* This is a script made by Ryan Seys to remove the excess strings from lyrics that are inserted and generated from the application "Get Lyrical". It properly removes the Title and Artist from the start of the Lyrics, and the text "branding" that Get Lyrical inserts to all the lyrics it fetches. Usage: Select the songs that you would like to clean in iTunes, then run the script.*)
on trim_line(this_text, trim_chars, trim_indicator)
-- 0 = beginning, 1 = end, 2 = both
set x to the length of the trim_chars
-- TRIM BEGINNING
if the trim_indicator is in {0, 2} then
repeat while this_text begins with the trim_chars
try
set this_text to characters (x + 1) thru -1 of this_text as string
@ryanseys
ryanseys / passer_rating.py
Created April 6, 2013 22:30
Calculates the Passer Rating (passer efficiency or pass efficiency) of a player given some variables. Use at own risk, old-as-fuck code here.
# This Python application will calculate the passer rating
# (passer efficiency or pass efficiency) given the five required variables.
#
# Variables to be used as values are defined below. Set to strings so input
# can be anything. Later the strings will be converted to numbers, given
# they pass a series of error checking tests.
COMP = "null"
ATT = "null"
YARDS = "null"
@ryanseys
ryanseys / fac_rec.js
Created April 21, 2013 16:38
Recursive Factorial in JavaScript
function fac_rec(n) {
if(n <= 1) return 1;
else return n * fac_rec(n-1);
}