Skip to content

Instantly share code, notes, and snippets.

@cam-gists
cam-gists / nodejs
Created May 27, 2012 00:03
NodeJS: init.d script for CentOS
#!/bin/sh
#
# chkconfig: 35 99 99
# description: Node.js /home/nodejs/sample/app.js
#
. /etc/rc.d/init.d/functions
USER="nodejs"
@cam-gists
cam-gists / api.js
Created May 27, 2012 00:04 — forked from fwielstra/api.js
Node.JS: / Mongoose / Express application based on their respective tutorials
/* The API controller
Exports 3 methods:
* post - Creates a new thread
* list - Returns a list of threads
* show - Displays a thread and its posts
*/
var Thread = require('../models/thread.js');
var Post = require('../models/post.js');
@cam-gists
cam-gists / nodejs
Created May 27, 2012 00:04 — forked from alessioalex/nodejs
Node.JS: app under nginx
# node.js app under nginx
upstream node {
server 127.0.0.1:8001;
}
server {
listen 80;
server_name node;
@cam-gists
cam-gists / pop.js
Created June 1, 2012 21:17
JavaScript: Popunder
$(function(){
//specify site script is hosted on
var site = "www.example.com";
//specify page to pop-under
var data ="http://syndication.traffichaus.com/popserve.php?z=279&p=25";
var height = 800;
//var height = (screen.availHeight - 122).toString(); // Fullscreen
var width = 510;
//var width = (screen.availWidth - 10).toString(); // Fullscreen
@cam-gists
cam-gists / date.js
Created June 4, 2012 21:40
JavaScript: Date Calculation + Date Parser
/************************************************************************
Calculate Number of Days in Date Range
************************************************************************/
function days_between(date1, date2) {
var d1 = parseDate(date1.replace(/\-/g,'.'));
var d2 = parseDate(date2.replace(/\-/g,'.'));
// The number of milliseconds in one day
var ONE_DAY = 1000 * 60 * 60 * 24;
@cam-gists
cam-gists / debug.php
Created June 6, 2012 17:31
PHP: Debug
//*----------------------------------DEBUG ----------------------------------------*/
error_reporting(E_ALL);
ini_set("display_errors", 1);
//*----------------------------------DEBUG ----------------------------------------*/
@cam-gists
cam-gists / split.js
Created June 7, 2012 18:53
AJAX: Split Data
/************************************************************************
Split Data Returned From AJAX
************************************************************************/
$.post('dir/file.php',{ params: params },function(data){
// arrays for each
var attr = [];
for(var j = 0; j < data.length; j++){
for(var index in data[j]){
if(index == "attr"){
// Add to array
@cam-gists
cam-gists / curlScrape.php
Created June 7, 2012 21:44
PHP: cURL Scrape Page
<?php
/*
PHP: cURL Scrape page
*/
function getData($url) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$contents = curl_exec ($ch);
curl_close ($ch);
return $contents;
@cam-gists
cam-gists / xmlParse.php
Created June 8, 2012 16:51
PHP: XML -> Associative Array
<?php
/*
Parse XML feed => Assocative Array
*/
//*----------------------------------DEBUG ----------------------------------------*/
error_reporting(E_ALL);
ini_set("display_errors", 1);
//*----------------------------------DEBUG ----------------------------------------*/
@cam-gists
cam-gists / db.php
Created June 10, 2012 00:11
PHP: PDO
<?php
require 'config.php';
try {
# MySQL with PDO_MYSQL
$DBH = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
$DBH->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING );
}
catch(PDOException $e) {
echo $e->getMessage();