Skip to content

Instantly share code, notes, and snippets.

@TGOlson
TGOlson / index.html
Last active December 27, 2015 08:48 — forked from dbc-challenges/index.html
DBC Phase 2 Practice Assessment Part 3
<!doctype html>
<html>
<head>
<link rel="stylesheet" href="http://cdn.jsdelivr.net/normalize/2.1.0/normalize.css">
<link rel="stylesheet" href="main.css">
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700,800">
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Lato:100,900">
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/3.0.2/css/font-awesome.min.css">
</head>
@TGOlson
TGOlson / array.js
Created November 6, 2013 07:28
array methods -- saved because of mode calculation
//--- INSTRUCTIONS ------------------
/*
1. `Array.total()`, which returns the total of all the values in the array
2. `Array.mean()`, which returns the mean of the array
3. `Array.median()`, which returns the median of the array
4. `Array.mode()`, which returns an object representing the mode(s) of the array with the property being the mode and the value being the frequency
//--- CODE --------------------------
Array.prototype.total = function() {
@TGOlson
TGOlson / typer.html
Created November 6, 2013 07:50
js practice for type racer project
<html>
<head>
<script src="js.js"></script>
<title>JS Play</title>
<style>
body { font-size: 30px; font-family: sans-serif; }
div { text-align: center;}
input {
width: 500px;
background-color: #2ecc71;
@TGOlson
TGOlson / ajax.js
Last active December 29, 2015 09:59
Name-spaced JS with Ajax for Menu-style app. Built in a Rails app. Notes for parsing out Ajax calls on the same items, and toggling features.
var MenuItems = {
init: function(){
$(".menus").on("ajax:success", '.closed a', this.openMenuItems)
$(".menus").on("ajax:success", '.open a', this.closeMenuItems)
$(".menus").on("ajax:success", 'form', this.addMenuItems)
},
openMenuItems: function(e, data){
var itemDiv = MenuItems.getItemDiv(e)
$(itemDiv).html(data).hide()
<div class="container">
<h1 id='quiz_name'></h1>
<a href='#' id='next_question'>Start Quiz</a>
<div id='question'>
<h3 id='question_text'></h3>
<div id='answers'></div>
<div id='correct'></div>
</div>
</div>
@TGOlson
TGOlson / bubble_sort.rb
Created January 14, 2014 22:46
Ruby sorting algorithms.
def bubble_sort(list)
sorted = false
until sorted
sorted = true
(0...list.length).each do |i|
if !list[i + 1].nil? && list[i] > list[i + 1]
list[i], list[i + 1] = list[i + 1], list[i]
sorted = false
end
end
@TGOlson
TGOlson / linked_list.rb
Last active January 4, 2016 02:29
Creating Linked Lists In Ruby
# Creating a linked list in Ruby, based on this tutorial
# http://www.commandercoriander.net/blog/2012/12/23/reversing-a-linked-list-in-ruby/
require 'benchmark'
class Entry
attr_accessor :next, :data
def initialize(data)
@next = nil
@TGOlson
TGOlson / filters.rb
Created January 23, 2014 08:51
Meta-programming filter tool for applications. Refactor with meta-programming is shown on top, old solution on bottom.
# A filter method using meta-programming to send multiple methods to the class.
# This allows multiple ActiveRecord scopes to be stacked easily.
def self.filter(params)
max = params[:limit] || 10
methods = [:new_prices]
methods << :free if params[:free]
methods << :games if params[:games]
methods << [:limit, max]
Application.send_chain(methods)
@TGOlson
TGOlson / import_script.sh
Created January 28, 2014 06:21
My first shell script -- isn't it cute...
echo '********************************************'
date -u
echo ' Beginning Incremental Import'
echo ' Setting PATH, GEM and RUBYLIB variables'
export PATH=/home/ckoziak/webapps/rails/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/ckoziak/bin;
export GEM_HOME=/home/ckoziak/webapps/rails/gems;
export RUBYLIB=/home/ckoziak/webapps/rails/lib;
echo ' Changing Directory to /home/ckoziak/webapps/rails/fas/'
@TGOlson
TGOlson / refactor.js
Created February 28, 2014 06:23
Refactor your JS
// For a project I needed to find the nearest denominator from a set number and divisor.
// I started off hacking it together to see if it would work in my project.
// Then I refactored. Refactored code is shown first.
// Refactored Code
function findNearestInt(num, div){
for(var i = 0; i < div / 2; i++){
if(num % (div - i) == 0){return div - i}
if(num % (div + i) == 0){return div + i}