Skip to content

Instantly share code, notes, and snippets.

View adamloo85's full-sized avatar

Adam Loo adamloo85

  • Millbrae, CA
View GitHub Profile
@adamloo85
adamloo85 / DNA_search.rb
Created July 31, 2014 21:16
A short script that takes a DNA strand, does a pattern search and returns # the indexes of all matches.
# Author: Adam Loo
# Date: 7/31/2014
# A short script that takes a DNA strand, does a pattern search and returns
# the indexes of all matches.
STRAND = "aggcgtatgcgatcctgaccatgcaaaactccagcgtaaatacctagccatggcgacacaaggcgcaaga" +
"caggagatgacggcgtttagatcggcgaaatattaaagcaaacgacgatgacttcttcgggaaattagttccctactcgt" +
"gtactccaattagccataacactgttcgtcaagatatagggggtcacccatgaatgtcctctaaccagaccatttcgtta" +
"cacgaacgtatctgatgacttcttcgggaaattagttccctactcgtgtactccaattagccataacactgttcgtcaag" +
"atatagggggtcacccatgaatgtcctctaaccagaccatttcgttacacgaacgtatcttcggggcgtatgcgatcctg" +
@adamloo85
adamloo85 / 0_reuse_code.js
Created May 13, 2014 19:00
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@adamloo85
adamloo85 / pivot.rb
Last active December 28, 2015 17:49
README Run by typing "ruby (filename)". Drive code is already included. This script adds a method "find_pivot" to the array class which finds the pivot point of any array and returns the index of that point if it exists or -1 otherwise.
#README
#Run by typing "ruby (filename)". Drive code is already included.
#This script adds a method "find_pivot" to the array class which finds the pivot point of any array
#and returns the index of that point if it exists or -1 otherwise.
class Array
def find_pivot
raise NoMethodError, 'Wrong type of input!' if self.class != Array
low = 0
@adamloo85
adamloo85 / gist:7462583
Created November 14, 2013 06:56
Returns the first unique character in a string of duplicates, assuming there are unique characters. Note n-squared performance.
def find_char(string)
word = string.split(//)
word = word.find_all { |x| word.count(x) == 1 }
word.first
end
@adamloo85
adamloo85 / binary.rb
Created November 14, 2013 06:55
Binary search method that searches through a passed array. Takes two parameters, number to be searched and data array.
def binary_search(num, arr)
high = arr.length - 1
low = 0
while low < high
mid = (low + high) / 2
if arr[mid] > num
low = mid + 1
elsif arr[mid] < num
@adamloo85
adamloo85 / gist:7462551
Created November 14, 2013 06:53
Method to determine if a string has a valid representation of "(...)". Ex: "((...)" would return "false"
def nested?(string)
string.gsub!(/[^()]/, '')
string.gsub!(/\(\)/, '')
string.empty?
end
@adamloo85
adamloo85 / hash.rb
Last active December 28, 2015 07:09
Implementing a "hash-like" data structure using arrays. Unit tests through the Shoulda gem.
require 'rubygems'
require 'shoulda-context'
class HashFake
def initialize(size=0)
@body = Array.new(size)
end
def body
@body
@adamloo85
adamloo85 / post-it.js
Created August 14, 2013 01:24
PostIt Version 2. Product of pairing with Jeffrey. Note, CSS change of class "post_board" to "post-board"
var PostIt = function(x, y, boardId) {
//Create post-it
var $div = $("<div class='post-it'><div class='header'><a href='#' id='close'>CLOSE</a></div><div class='content' contenteditable='true'></div></div>")
this.$element = $div;
var self = this;
function initialize() {
$div.draggable({
/* Here is your chance to take over Socrates!
Spend 10 minutes on each of the following hacks to the socrates website.
Enter them in the console to make sure it works and then save
your results here.
Choose a new pair for each. Add your names to the section you complete.
*/

Instructions:

  1. Download this application skeleton.
  2. Convert the app to use AJAX.
  3. Add any files you changed to your gist and submit your code.