Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View jordanhudgens's full-sized avatar

Jordan Hudgens jordanhudgens

View GitHub Profile
@jordanhudgens
jordanhudgens / gist:8033986
Last active February 4, 2022 09:51
Functional Programming Exercises
### Generate an array of numbers, from 1 to 10:
(1..10).to_a
# => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
### Generate an array of letters from 'a' to 'g':
("a".."g").to_a
# ⇒ ["a", "b", "c", "d", "e", "f", "g"]
### Generate an array of double letters from 'aa' do 'gg':
("a".."g").to_a.map {|i| i * 2}
#python2.6 <
from math import log
def getDigit(num, base, digit_num):
# pulls the selected digit
return (num // base ** digit_num) % base
def makeBlanks(size):
# create a list of empty lists to hold the split by digit
return [[] for _ in xrange(size)]
sorts
#nodes=1..4.
#colors={red,green,blue}.
predicates
node(#nodes).
edge(#nodes,#nodes).
has_color(#nodes,#colors).
rules
#!/usr/bin/env python
def counting_sort(array, maxval):
"""in-place counting sort"""
m = maxval + 1
count = [0] * m # init with zeros
for a in array:
count[a] += 1 # count occurences
i = 0
for a in range(m): # emit
@jordanhudgens
jordanhudgens / merge_sort.py
Created May 29, 2014 17:23
Merge sort implementation
# Python version 2.6+
from heapq import merge
def merge_sort(m):
if len(m) <= 1:
return m
middle = len(m) / 2
left = m[:middle]
@jordanhudgens
jordanhudgens / gist:d4f4a9e6c5744886ad49
Created August 7, 2014 21:25
Instagram Follower Counter
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
$(function() {
$.ajax({
type: "GET",
dataType: "jsonp",
cache: true,
error: function(data) { console.log(data); },
gem 'sass-rails', '>= 3.2' # sass-rails needs to be higher than 3.2
gem 'bootstrap-sass', '~> 3.1.1'
<div class="row">
<%= form_for @invoice, html: { class: 'form-horizontal' } do |f| %>
<% if @invoice.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@invoice.errors.count, "error") %> prohibited this invoice from being saved:</h2>
<ul>
<% @invoice.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
@jordanhudgens
jordanhudgens / map-lasso.js
Created February 27, 2015 03:11
Map Lasso Feature
var map;
var points=[];
var pointsrand=[];
var areaDiv=document.getElementById('area');
var areaDivkm=document.getElementById('areakm');
var randomMarkers=new Array(0);
var routeMarkers=new Array(0);
var lines=[];
var lineColor='#ff0000';
var fillColor='#00FF00';
# This is to be used as a process flow, not an executable implementation
## Dynamic Ruby View
# Situation: You have a very similar views that needs to be rendered, currently they are two separate models/views/controllers.
# This isn't an ideal setup since it means that anytime you want to make changes to one view you also need to make changes to the other view.
# And if they ever want more views created that are like this it will mean you need to change more, this can be bad from a time and
# code duplication perspective.
# To fix this: