Skip to content

Instantly share code, notes, and snippets.

View itsgreggreg's full-sized avatar
🍹
chillin

Greg Baraghimian itsgreggreg

🍹
chillin
View GitHub Profile
/**
* You may use this code for free on any web page provided that
* these comment lines and the following credit remain in the code.
* Cross Browser Fireworks from http://www.javascript-fx.com
*/
/*************************************************/
if(!window.JSFX) JSFX=new Object();
if(!JSFX.createLayer)
{/*** Include Library Code ***/
@itsgreggreg
itsgreggreg / opposite_day.ex
Created October 5, 2015 17:42
Elixir opposite day
defmodule OppositeDay do
defmacro opposite_day(do: block) do
do_opposite(block)
end
def do_opposite({:==, c, a}), do: {:!=, c, a}
def do_opposite({:!=, c, a}), do: {:==, c, a}
def do_opposite({:-, c, a}), do: {:+, c, a}
def do_opposite({:+, c, a}), do: {:-, c, a}
def do_opposite({:*, c, a}), do: {:/, c, a}
@itsgreggreg
itsgreggreg / advanced.js
Created September 27, 2015 03:11
Advanced JS stuff
// Tell me what is going on here:
function oneHitter(name, val){
if(!oneHitter.cache) oneHitter.cache = {};
if(!oneHitter.cache[name]) oneHitter.cache[name] = val
return oneHitter.cache[name];
}
// Tell me what's going on here':
var days = ["sun","mon","tues","wed","thurs","fri","sat"];
function lastElement(arr){
@itsgreggreg
itsgreggreg / functional_find_prime_factors.js
Last active September 11, 2015 14:48
JS functional find prime factors
// Calling find_prime_factors on numbers that functional languages can easily handle
// will cause a stack size exception. JS can't handle functional programming. :)
// http://jsbin.com/qakodivepe/edit?js,console
// try:
// primeFactors(10)
// primeFactors(7775460)
// primeFactors(7919)
// primeFactors(1056884) <- Boom, stack size exception
// Entry point
@itsgreggreg
itsgreggreg / README.md
Last active August 29, 2015 14:24
blog server

##What? A quick lesson in serverside javascript. Creates a super basic blog that gets and posts via AJAX and saves to a JSON file. Demonstrates many important web development concepts. After finishing the project get students to talk about how they would implement other features like editing posts and basic security.

##Features

  • posts.json holds all the posts, students can see just how data is stored and can edit it manually.
  • jquery handles ajax requests for geting and posting blog posts.
  • post form is initially hidden, shows when there is a location.search like ?admin
  • handlebars handles templates for super simple templating, just two lines of JS and the templates are written in HTML

##Setup

@itsgreggreg
itsgreggreg / tracker.html
Last active August 29, 2015 14:24
tracker
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-2.1.4.js"></script>
<script src="https://rawgit.com/jonthornton/jquery-timepicker/master/jquery.timepicker.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/3.0.3/handlebars.js"></script>
<link rel="stylesheet" href="https://rawgit.com/jonthornton/jquery-timepicker/master/jquery.timepicker.css">
<script src="tracker.js"></script>
<script id="activity-template" type="text/x-handlebars-template">
<div class="activity">
@itsgreggreg
itsgreggreg / reduce.md
Last active August 29, 2015 14:24
What is reduce

###Reduce is just a convenience method.
You can write any reduction as a simple loop

Given this list:

var list = [1,2,3,4,5];

This "reduction"

http://api.openweathermap.org/data/2.5/weather?q=New%20Orleans&mode=json&units=imperial
@itsgreggreg
itsgreggreg / index.html
Created June 29, 2015 21:02
JQuery Warmup
<!DOCTYPE html>
<html>
<head></head><body>
<div id="everything">
<h1>A heading!</h1>
<p>Here's some text!</p>
<p>Here's a second set of text!</p>
<div class="holder">
<ul>
<li>List Item 1</li>
['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']