Skip to content

Instantly share code, notes, and snippets.

View itsgreggreg's full-sized avatar
🍹
chillin

Greg Baraghimian itsgreggreg

🍹
chillin
View GitHub Profile
@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 / 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 / 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}
/**
* 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 / counter-full.elm
Last active February 19, 2016 16:20
Elm FEP Talk
module Main where
import Html exposing (div,button,Html,text,Attribute)
import Html.Events exposing(onClick)
import Html.Attributes exposing (style)
import StartApp.Simple exposing (start)
type alias Model = Int
type Action = Increment | Decrement
  • MAMP: https://www.mamp.info/en/downloads/
  • Craft CMS: https://craftcms.com/pricing
  • Open up MAMP
    • Preferences -> Web Server
      • Change Document Root to public folder in Craft CMS download
    • Start Servers
  • If it doesn't open automatically hit "open WebStart page"
  • tools -> phpMyAdmin
    • top left "new" button
  • database name: project_name
@itsgreggreg
itsgreggreg / instachat.md
Last active April 8, 2016 19:33
Phoenix Intsachat

Instachat

The Phoenix Framework was built with realtime communication as a first class priority. Using its built in socket handling and channels we can implement a basic, realtime chat application with little effort.

For this video we’re going to assume that you already have Elixir and Phoenix Setup. You will not need a database as the messages will not be persisted. This tutorial is taken pretty much directly from the Phoenix Documentation.

Setting up the app

To start let’s generate a standard phoenix application:

$> mix phoenix.new instachat
@itsgreggreg
itsgreggreg / 15-minutes-to-prototypal-inheritance.md
Last active May 26, 2016 20:12
15 minutes to Prototypal Inheritance

Prototypal Inheritance

Goals

By the end of this lesson students should be able to:

  • Demonstrate a use case that explains prototypal inheritance
  • Demonstrate what kind of flexibility prototypal inheritance gives programmers

Summary

In this lesson we are going to learn about a type of inheritance called Prototypal Inheritance. We are going to see how with prototypes we can share functionality between related objects. We are going to see how with Object.create we can easily set up prototypes and how we can extend prototypes to easily add functionality.

@itsgreggreg
itsgreggreg / elixir_debugging.md
Last active June 28, 2017 11:56
Elixir Debugging

Keybase proof

I hereby claim:

  • I am itsgreggreg on github.
  • I am greggreg (https://keybase.io/greggreg) on keybase.
  • I have a public key whose fingerprint is EEE7 1FC8 7328 62C1 7482 5689 8749 2ABC 1645 F5B7

To claim this, I am signing this object: