Skip to content

Instantly share code, notes, and snippets.

View nizaroni's full-sized avatar
🍕
Teaching code with pizza examples.

Nizar Khalife nizaroni

🍕
Teaching code with pizza examples.
View GitHub Profile
@nizaroni
nizaroni / async_social.js
Created July 12, 2012 18:17
Asynchronous Social Plugins
(function(doc, script) {
var js,
fjs = doc.getElementsByTagName(script)[0],
add = function(url, id) {
if (doc.getElementById(id)) {return;}
js = doc.createElement(script);
js.src = url;
id && (js.id = id);
fjs.parentNode.insertBefore(js, fjs);
};
@nizaroni
nizaroni / .htaccess
Created September 19, 2012 19:46
Force SSL / https in .htaccess
<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301]
</IfModule>
@nizaroni
nizaroni / top_countries.php
Created April 19, 2013 21:48
PHP script that parses a CSV data file and adds certain stats from rows with keys in common. Receives path to CSV file, amount of expected columns on data rows and (optionally) the amount of rows to parse and add. It will ignore empty rows, rows that begin with `#` (comments) and rows that don't have the right amount of columns.
<?php
// Config
//------------------------------------------
define('COUNTRY_KEY', 1);
define('ADD_KEY', 3);
@nizaroni
nizaroni / Request Headers.http
Created May 6, 2013 22:12
Facebook iframe's HTTP response and request data for Download Tab
POST /b/en-US/facebookapps/downloadtab/noscroll/ HTTP/1.1
Host: www.mozilla.org
Connection: keep-alive
Content-Length: 277
Cache-Control: no-cache
Pragma: no-cache
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Origin: https://s-static.ak.facebook.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.65 Safari/537.31
Content-Type: application/x-www-form-urlencoded
@nizaroni
nizaroni / rails-glossary.md
Created February 3, 2015 15:50
Glossary of Rails terms for beginners.

Rails Glossary

A glossary of Rails terms for beginners.

Router

The router is the component of Rails that takes your config/routes.rb file, reads your routes from it and uses them to respond to incoming requests.

New Project

Create the project

These all do the same thing:

rails new pizza-project --skip-bundle --skip-test-unit --skip-turbolinks --database=postgresql
rails new pizza-project -B -T -d postgresql --skip-turbolinks
@nizaroni
nizaroni / github-credit.sh
Created February 20, 2015 15:14
How to clone someone else's repository and still get GitHub credit for your changes.
# Clone the other person's repo.
# MAKES A NEW FOLDER! CAUTION!
$ git clone https://github.com/khalifenizar/bbq
# Rename that person's remote GitHub repo.
$ git remote rename origin khalifenizar
# Add your remote GitHub repo
$ git remote add origin https://github.com/yourusername/bbq
@nizaroni
nizaroni / project-structure.md
Created March 24, 2015 00:01
Ruby project folder structure.

Ruby project structure

my-project-folder/
└─┬── Gemfile
  ├── server.rb
  ├─┬ lib/
  │ └── (Ruby files: classes, modules, etc.)
 ├─┬ public/
@nizaroni
nizaroni / Gemfile
Created April 7, 2015 17:03
Sinatra Twitter example.
source 'https://rubygems.org'
gem 'sinatra'
@nizaroni
nizaroni / 01-config--routes.rb
Last active August 29, 2015 14:20
Twitter in Rails: Showing posts.
Rails.application.routes.draw do
# ...
# Add a get route for listing posts
get '/posts' => 'posts#index'
# ...
end