Skip to content

Instantly share code, notes, and snippets.

@caspian311
caspian311 / auth.conf
Last active August 29, 2015 14:05
pass along an HTTP header containing the logged-in username for authenticated requests to backend reverse proxied services
LoadModule auth_kerb_module modules/mod_auth_kerb.so
LoadModule rewrite_module modules/mod_rewrite.so
<Location /services>
AuthType Kerberos
AuthName "Kerberos Login"
KrbMethodNegotiate On
KrbMethodK5Passwd On
KrbAuthRealms <DOMAIN-NAME>
Krb5KeyTab /etc/krb5.keytab
@caspian311
caspian311 / firewall.sh
Last active August 29, 2015 14:04
firewall settings that only allows ssh and web access
#!/bin/sh
# Flushing all rules
iptables -F
iptables -X
# Setting default filter policy
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP
@caspian311
caspian311 / git-shell.sh
Last active August 29, 2015 14:01
bash prompt with git status
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"
WHITE="\[\033[1;37m\]"
function parse_git_branch {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
foo=${ref#refs/heads/}
status=$(git status -s | awk '{print $1}' 2>&1)
echo "$status" | grep M > /dev/null 2>&1
@caspian311
caspian311 / node-file-watch.sh
Last active August 29, 2015 14:00
See how many files are opened due to nodejs
watch -n 1 "lsof -a -p $(ps -ef | grep node | grep -v grep | awk '{print $2}') | wc -l"
@caspian311
caspian311 / nginx-node.conf
Created April 8, 2014 13:56
nginx reverse-proxy to node
# the IP(s) on which your node server is running. I chose port 3000.
upstream app_yourdomain {
server 127.0.0.1:3000;
}
# the nginx server instance
server {
listen 0.0.0.0:80;
server_name yourdomain.com yourdomain;
access_log /var/log/nginx/yourdomain.log;
/*
Usage:
var compile = require('build-utils').compile;
compile('less-src', 'public/css', function(lessFile, destFile) {
var cssFile = destFile.substr(0, destFile.indexOf('.less')) + '.css';
run('./node_module/.bin/lessc' + lessFile + ' > ' + cssFile);
});
*/
@caspian311
caspian311 / ThingTest.cs
Created May 9, 2013 13:51
Argument captures with Rhino.Mocks
using System;
using NUnit.Framework;
using Rhino.Mocks;
namespace Thing
{
public class Thing
{
private readonly IMesasgeService _messageService;
@caspian311
caspian311 / Entity.cs
Created April 12, 2013 13:54
In nHibernate, when you soft delete entries and don't want to duplicated query logic to filter those out and don't want to add business rules into your hibernate configuration this is useful. Uses reflection to filter out the entities where the IsDeleted property is set to true. Makes for a manageable/testable solution. All nHibernate entities e…
namespace Sample.DataAccess
{
public abstract class Entity
{
public virtual int Id { get; set; }
public virtual bool IsDeleted { get; set; }
}
public class Foo : Entity
{
@caspian311
caspian311 / client.py
Created January 30, 2013 19:36
Simple client-service dbus example in python.
#!/usr/bin/env python
import dbus
class Client():
def __init__(self):
bus = dbus.SessionBus()
service = bus.get_object('com.example.service', "/com/example/service")
self._message = service.get_dbus_method('get_message', 'com.example.service.Message')
self._quit = service.get_dbus_method('quit', 'com.example.service.Quit')
@caspian311
caspian311 / build.sh
Created September 25, 2012 12:34
self-extracting shell script
#!/bin/bash -ex
tar zcvf app.tgz ./app
cp installer-script-only.sh installer.sh
cat app.tgz >> installer.sh