Skip to content

Instantly share code, notes, and snippets.

View safwank's full-sized avatar

Safwan Kamarrudin safwank

  • Melbourne, Australia
View GitHub Profile
@safwank
safwank / gist:3262724
Created August 5, 2012 07:51
Sample view (using Jade) that displays the progress of Neo4J batch imports
head
script(src='http://code.jquery.com/jquery-1.6.2.min.js')
script(src='/socket.io/socket.io.js')
script(type='text/javascript')
var socket = io.connect('http://localhost:3000')
socket.on('downloadZipFileProgress', function (data) {
var progress = data.progress
if (progress < 100)
$('#downloadZipFileProgress').text(progress.toFixed(2) + '%')
@safwank
safwank / gist:3262602
Created August 5, 2012 07:15
Sample code on how to poll Redis to keep track of the progress of Neo4J batch imports
var sys = require('sys'),
http = require('http'),
url = require('url'),
fs = require('fs'),
path = require('path'),
io = require('socket.io').listen(app),
uuid = require('node-uuid'),
redisUtil = require('../common/redisutil');
@safwank
safwank / gist:3262543
Created August 5, 2012 07:07
Sample code on how to use Redis to keep track of the total number of nodes exported to Neo4J
Business.loadFromCSV = function(csvFilePath) {
csv().fromPath(csvFilePath, { columns: true, trim: true })
.on('data', loadBusiness)
.on('end', handleSuccess)
.on('error', handleLoadError);
};
function loadBusiness(data, index) {
var business = data;
util.removeNullOrEmptyPropertiesIn(business);
@safwank
safwank / gist:3152328
Created July 20, 2012 18:08
Sample code on how to remove null or empty properties before creating a node in Neo4J.
function isNullOrEmpty(value) {
return !value || value.length === 0 || /^\s*$/.test(value);
}
function removeNullOrEmptyPropertiesIn(object) {
for (var propertyName in object)
{
var propertyValue = object[propertyName];
if (isNullOrEmpty(propertyValue))
@safwank
safwank / business.js
Created July 1, 2012 01:22
Sample code on how to populate a Neo4j database with CSV data
// Initialization
var csv = require('csv');
var neo4j = require('neo4j');
var db = new neo4j.GraphDatabase(process.env.NEO4J_URL || 'http://localhost:7474');
// Constants:
var INDEX_NAME = 'nodes';
var INDEX_KEY = 'type';
@safwank
safwank / TweetStreamer.cs
Created June 17, 2012 07:12
Streaming tweets in 'real-time' using Rx
public partial class TweetStreamer : Form
{
private List<Tweet> tweets;
private readonly IObservable<EventPattern<EventArgs>> stopClicked;
private readonly DataContractJsonSerializer jsonSerializer;
public TweetStreamer()
{
InitializeComponent();
jsonSerializer = new DataContractJsonSerializer(typeof (TweetSearchResult));
@safwank
safwank / gist:2940031
Created June 16, 2012 05:09
Example usage of InstanceSpinner.ps1
powershell .\InstanceSpinner.ps1 -operation start -secretKeyId "[your secret key]" -secretAccessKeyId "[your access key]" -instanceIds "[first instance ID]","[second instance ID]"
powershell .\InstanceSpinner.ps1 -operation stop -secretKeyId "[your secret key]" -secretAccessKeyId "[your access key]" -instanceIds "[first instance ID]","[second instance ID]"
@safwank
safwank / InstanceSpinner.ps1
Created June 16, 2012 03:17
A simple PowerShell script to spin EC2 instances up and down.
param([string]$operation, [string]$secretKeyId, [string]$secretAccessKeyId, [string[]]$instanceIds)
Add-Type -Path ".\AWSSDK.dll"
function StartInstances()
{
$ec2Client = CreateEC2Client
$request = New-Object -TypeName Amazon.EC2.Model.StartInstancesRequest
$request.InstanceId = GetInstancesFromParameterList