Skip to content

Instantly share code, notes, and snippets.

View julsfelic's full-sized avatar

Julian Feliciano julsfelic

View GitHub Profile
@julsfelic
julsfelic / ScopeSafeConstructor01.js
Created April 20, 2013 17:35
Scope safe constructor example
function Person(name, age, job) {
if (this instanceof Person) {
this.name = name;
this.age = age;
this.job = job;
} else {
return new Person(name, age, job)
}
}
@julsfelic
julsfelic / ScopeSafeConstructor02.js
Created April 20, 2013 17:39
Scope safe constructor pattern w/ prototype chaining
function Polygon(sides) {
if (this instanceof Polygon) {
this.sides = sides;
this.getArea = function() {
return 0;
};
} else {
return new Polygon(sides);
}
}
@julsfelic
julsfelic / observer.js
Created April 22, 2013 17:02
The Observer Pattern
function EventTarget() {
this.handlers = {};
}
EventTarge.prototype = {
constructor: EventTarget,
addHandler: function(type, handler) {
if (typeof this.handlers[type] == "undefined") {
this.handlers[type] = [];
@julsfelic
julsfelic / dragAndDrop.js
Created April 22, 2013 17:22
Drag and Drop script with custom events
var DragDrop = function() {
var dragdrop = new EventTarget(),
dragging = null,
diffX = 0,
diffY = 0;
function handleEvent(event) {
event = EventUtil.getEvent(event);
var target = EventUtil.getTarget(event);
@julsfelic
julsfelic / new_ruby_project.bash
Last active January 2, 2016 04:41
Bash Function to Quickly Create Ruby Project Structure
# Copy this function into your .bash_profile found at ~/.bash_profile
# You can rename the function to your preference
function new_ruby_project {
mkdir $1;
cd $1;
mkdir lib/;
touch lib/"$1".rb;
mkdir test/;
touch test/test_helper.rb;
@julsfelic
julsfelic / cfu_crud_in_sinatra.markdown
Last active February 3, 2016 00:20 — forked from rwarbelow/cfu_crud_in_sinatra.markdown
CRUD in Sinatra -- Check for Understanding

Define CRUD.

CRUD stands for Create Read Update & Delete. It allows us to create resources in a database, read or 'get' the resource to display, update a resource without overwriting the original resource and delete a specific resource from the database.

There are seven verb + path combinations that are necessary in a basic Sinatra app in order to provide full CRUD functionality. List each of the seven combinations, and explain what each is for.

All resources: get '/resources' (ex. get '/tasks') => gives us a list of all the resources through a index.erb file that gets interpreted to html.

One resource: get '/resources/:id (ex. get '/tasks/1) => gives us the specific resource through a show.erb file that gets interpreted to html.

@julsfelic
julsfelic / gist:70a1d970c2bfbd63588f
Last active February 17, 2016 19:58
"Migrations, Databases, Models, and Relationships in Rails

One-to-one Relationship Example

A person belongs to one Fitbit and a Fitbit belongs to one person.

One-to-many Relationship Example

A article of clothing belongs to a person and a person has many articles of clothing.

Many-to-many Relationship

@julsfelic
julsfelic / git_rule_of_thumbs.md
Last active February 25, 2016 16:38
Git rule of thumbs for proper commit messages

The seven rules of a great commit messaage

  1. Seperate subject from body with a blank line
  2. Limit the subject line to 50 characters
  3. Capitalize the subject line
  4. Do not end the subject line with a period
  5. Use the imperative mood in the subject line
  6. Wrap the body at 72 characters
  7. Use the body to explain what and why vs. how
@julsfelic
julsfelic / github_shortcuts.md
Created February 25, 2016 16:56
Github shortcuts

Github Shortcuts

Sitewide

Question Mark (?)

The ? gives you all the keyboard shortcuts that are available for the current page.

Go to your notifications

@julsfelic
julsfelic / my_favorite_beer.md
Created February 25, 2016 19:34
My Favorite Beer (Tentative title)

Project: My Favorite Beer (Tentative title)

An app that allows users to choose their favorite breweries in America! You can sort brewery's by their state (or maybe city) and add them to your personal list! Users can see all their favorited breweries, see an individual breweries information, remove a brewery from their personal list. They cannot add, edit or delete a brewery. Admins can add, edit or delete breweries along with creating categories for the breweries.

Categories (brewery specialty)

  • breweries belong to a category
  • categories can be created and destroyed by a logged-in admin user