Skip to content

Instantly share code, notes, and snippets.

View julsfelic's full-sized avatar

Julian Feliciano julsfelic

View GitHub Profile
@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 / 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;
# 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)
var myObject = {
name: "Julian",
sayHello: function() {
console.log("Hello there, " + this.name + "!");
}
};
console.log(myObject.name);
myObject.sayHello();
console.log(myObject);
var name = "Julian";
console.log(name);
console.log(window.name);
function sayHello(name) {
console.log("Hello there, " + name + "!");
}
sayHello(name);
window.sayHello(window.name);
@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 / 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 / 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 / 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 / xBrowserCORS.js
Created April 20, 2013 15:33
Cross-Browser CORS
function createCORSResquest(method, url) {
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
xhr.open(method, url, true);
} else if (typeof XDomainRequest != "undefined") {
xhr = new XDomainRequest();
xhr.open(method, url);
} else {
xhr = null;
}