Skip to content

Instantly share code, notes, and snippets.

@speier
speier / visitor.js
Created May 16, 2012 22:05
node-visitor recursively visits every required file using node-detective
var fs = require('fs');
var path = require('path');
var Module = require('module');
var detective = require('detective');
// node-visitor
function visit(request, parent) {
var fn;
try {
@speier
speier / gist:5974014
Created July 11, 2013 09:32
install redis-server via ppa
1. apt-get install software-properties-common
2. add-apt-repository ppa:chris-lea/redis-server
3. apt-get update
4. apt-get install redis-server
@speier
speier / steps
Last active December 19, 2015 14:59
install lastest stable nginx package on ubuntu raring
1. wget http://nginx.org/keys/nginx_signing.key
2. apt-key add nginx_signing.key
3. nano /etc/apt/sources.list
paste `deb http://nginx.org/packages/ubuntu/ raring nginx`
paste `deb-src http://nginx.org/packages/ubuntu/ raring nginx`
4. apt-get update
5. apt-get install nginx
@speier
speier / 1. on the server
Last active December 19, 2015 13:49
experimenting with git powered deployment
01. `apt-get install git`
02. `adduser git`
03. `visudo` add `git ALL=(ALL:ALL) NOPASSWD: ALL` to user privilege specification
04. `login git`
05. `ssh-keygen -t rsa`
06. `mkdir project`
07. `mkdir project.git`
08. `cd project.git`
09. `git init --bare`
10. `cd hooks`
@speier
speier / gist:5964332
Created July 10, 2013 08:04
List systemd symbolic links on Archlinux:
ls -la /etc/systemd/system/multi-user.target.wants/
@speier
speier / Program.cs
Created December 13, 2012 15:54
The first term in the Fibonacci sequence to contain 2012 digits.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Numerics;
namespace ConsoleApplication4
{
class Program
{
@speier
speier / app.js
Created October 2, 2012 11:34 — forked from pixelhandler/app.js
Develop a RESTful API Using Node.js With Express and Mongoose - See: http://pixelhandler.com/blog/2012/02/09/develop-a-restful-api-using-node-js-with-express-and-mongoose/
var application_root = __dirname,
express = require("express"),
path = require("path"),
mongoose = require('mongoose');
var app = express.createServer();
// database
mongoose.connect('mongodb://localhost/ecomm_database');
@speier
speier / api.js
Created September 14, 2012 20:07 — forked from fwielstra/api.js
An example NodeJS / 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');
@speier
speier / ReportService.cs
Created August 30, 2012 10:51
ServiceStack MQ mockup
[Auth]
public class ReportService : RestServiceBase<Report>
{
public IReportRepository Repository { get; set; }
public override object OnGet(Report request)
{
using (var producer = MessageFactory.CreateMessageProducer())
{
producer.Publish(request);
@speier
speier / cssincimages
Created May 4, 2012 14:04
Replace CSS images with inline base64 data
var fs = require('fs');
var path = require('path');
function cssIncImages(cssFile) {
var imgRegex = /url\s?\(['"]?(.*?)(?=['"]?\))/gi;
var css = fs.readFileSync(cssFile, 'utf-8');
while (match = imgRegex.exec(css)) {
var imgPath = path.join(path.dirname(cssFile), match[1]);
try {
var img = fs.readFileSync(imgPath, 'base64');