Skip to content

Instantly share code, notes, and snippets.

View sourcec0de's full-sized avatar
:octocat:
Focusing

James R Qualls sourcec0de

:octocat:
Focusing
View GitHub Profile
@sourcec0de
sourcec0de / again.js
Created June 23, 2012 22:21
test again
var html = require('fs').readFileSync(__dirname+'/helloworld.html');
var server = require('http').createServer(function(req, res){
res.end(html);
});
server.listen(8080);
var nowjs = require("now");
var everyone = nowjs.initialize(server);
everyone.now.distributeMessage = function(message){
@sourcec0de
sourcec0de / help.rb
Created June 25, 2012 20:18
New files for Screen Cast
def index
if current_member.subscription.nil?
redirect_to new_subscription_path
end
end
@sourcec0de
sourcec0de / action.html.slim
Created July 8, 2012 06:29
Impressionist belongs_to through has_many for Users association
# You can use What ever type of View you want ERB, SLIM, HAML
#
# Once you have your list of ActiveRecord objects inside of @impressions
# instance variable from your controller, run the variable through a
# for loop to get the count for each ActiveRecord object
#
# Optionally, you can create new instance variables and add to their
# values when running the loop so you can get total number of views for
# that specific user.
@sourcec0de
sourcec0de / global-variables-are-bad.js
Created November 22, 2012 00:17 — forked from hallettj/global-variables-are-bad.js
How and why to avoid global variables in JavaScript
// It is important to declare your variables.
(function() {
var foo = 'Hello, world!';
print(foo); //=> Hello, world!
})();
// Because if you don't, the become global variables.
(function() {
@sourcec0de
sourcec0de / distance.js
Created December 6, 2012 07:59
Javascript Distance Library
$(document).ready(function(){
function distance(element) {
// About object is returned if there is no 'element' parameter
var about = {
Version: 0.1,
Author: "James Qualls",
Created: "Dec 5th, 2012",
Updated: "Not yet"
};
@sourcec0de
sourcec0de / gist:4223972
Created December 6, 2012 12:06 — forked from olistik/gist:2627011
Ubuntu 12.10 setup (rbenv/rvm, janus, postgres)

Basic pre-requisites

  • Some utilities:
sudo apt-get install vim tmux git
  • Copy/paste from the command line:
sudo apt-get install xclip
@sourcec0de
sourcec0de / ApiController.php
Created December 7, 2012 23:14
Cross Origin Resource Sharing with PHP & YII
// add this to your API controller in Yii
public function actionPreflight() {
$content_type = 'application/json';
$status = 200;
// set the status
$status_header = 'HTTP/1.1 ' . $status . ' ' . $this->_getStatusCodeMessage($status);
header($status_header);
@sourcec0de
sourcec0de / FIX.md
Created December 11, 2012 07:08
Nutritionix Response Headers

#How Current Header(Content-Type)

{"content-type":"text/html; charset=UTF-8"}

Render JSON With this content type

{"content-type":"application/json; charset=UTF-8"}
@sourcec0de
sourcec0de / README.md
Created December 13, 2012 07:28 — forked from fnichol/README.md

Why?

There is a long standing issue in Ruby where the net/http library by default does not check the validity of an SSL certificate during a TLS handshake. Rather than deal with the underlying problem (a missing certificate authority, a self-signed certificate, etc.) one tends to see bad hacks everywhere. This can lead to problems down the road.

From what I can see the OpenSSL library that Rails Installer delivers has no certificate authorities defined. So, let's go fetch some from the curl website. And since this is for ruby, why don't we download and install the file with a ruby script?

Installation

The Ruby Way! (Fun)

@sourcec0de
sourcec0de / deviseInstall.rb
Created January 11, 2013 01:32
Devise Remember Notification
===============================================================================
Some setup you must do manually if you haven't yet:
1. Ensure you have defined default url options in your environments files. Here
is an example of default_url_options appropriate for a development environment
in config/environments/development.rb:
config.action_mailer.default_url_options = { :host => 'localhost:3000' }