Skip to content

Instantly share code, notes, and snippets.

View julsfelic's full-sized avatar

Julian Feliciano julsfelic

View GitHub Profile
@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);
var name = "Julian";
console.log(name);
console.log(window.name);
function sayHello(name) {
console.log("Hello there, " + name + "!");
}
sayHello(name);
window.sayHello(window.name);
var myObject = {
name: "Julian",
sayHello: function() {
console.log("Hello there, " + this.name + "!");
}
};
console.log(myObject.name);
myObject.sayHello();
console.log(myObject);
# Clearest way possible
0.upto(1000) do |n|
if n.zero?
puts n
elsif (n % 3 == 0) && (n % 5 == 0) && (n % 7 == 0)
puts "SuperFizzBuzz"
elsif (n % 3 == 0) && (n % 7 == 0)
puts "SuperFizz"
elsif (n % 5 == 0) && (n % 7 == 0)
@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