Skip to content

Instantly share code, notes, and snippets.

View scott4dev's full-sized avatar

Claudio Maccari scott4dev

View GitHub Profile
@scott4dev
scott4dev / clean.sh
Created November 2, 2016 11:16
Clean Heroku npm cache
heroku config:set NODE_MODULES_CACHE=false
git commit -am 'rebuild' --allow-empty
git push heroku master
heroku config:unset NODE_MODULES_CACHE
public class DataCenterAwareIdGenerator : MongoDB.Bson.Serialization.IIdGenerator
{
public static int Machine { get; set; }
public static byte[] Pack(int timestamp, int machine, short pid, int increment)
{
if ((machine & 0xff000000) != 0)
{
throw new ArgumentOutOfRangeException("machine", "The machine value must be between 0 and 16777215 (it must fit in 3 bytes).");
@scott4dev
scott4dev / replica_and_shard_mongo
Created March 1, 2015 16:50
Deploy a Sharded and replicated database for testing
//start mongod instances for replica set rs0
mongod --port 27010 --dbpath data/rs0-0 --replSet rs0 --smallfiles --oplogSize 128
mongod --port 27011 --dbpath data/rs0-1 --replSet rs0 --smallfiles --oplogSize 128
//add primary
mongo --port 27010
rsconf = {
_id: "rs0",
members: [
{
@scott4dev
scott4dev / mongosharded
Last active August 29, 2015 14:16
Deploy a Sharded database for Testing
//start 2 db instances
mongod --port 27010 --dbpath data/s-0
mongod --port 27011 --dbpath data/s-1
//start the config server
mongod --configsvr --dbpath data/configsvr --port 27015
//start the router
mongos --configdb localhost:27015 --port 27017
@scott4dev
scott4dev / mongoreplica
Last active August 29, 2015 14:16
Deploy a Replica Set for Testing
//start mongod instances
mongod --port 27017 --dbpath data/rs0-0 --replSet rs0 --smallfiles --oplogSize 128
mongod --port 27018 --dbpath data/rs0-1 --replSet rs0 --smallfiles --oplogSize 128
mongod --port 27019 --dbpath data/rs0-2 --replSet rs0 --smallfiles --oplogSize 128
//add primary
rsconf = {
_id: "rs0",
members: [
@scott4dev
scott4dev / helloworld.js
Created September 25, 2011 09:11
Node.js hello world
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, "127.0.0.1");
console.log('Server running at http://127.0.0.1:1337/');
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5"
DefaultTargets="main"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\ExtensionPack\4.0\MSBuild.ExtensionPack.tasks"/>
<Target Name="createdb">
<ItemGroup>
<SqlFiles Include="$(MSBuildProjectDirectory)\db\**\*.sql" />
</ItemGroup>