Skip to content

Instantly share code, notes, and snippets.

@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 / 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;
/*
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 / 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;
@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 / 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 / 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 / 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 / .inputrc
Created December 12, 2014 20:51
Fix for terminal ctrl arrows
# goes into ~/.inputrc or /etc/inputrc
"\e[1;5C": forward-word
"\e[1;5D": backward-word
"\e[5C": forward-word
"\e[5D": backward-word
"\e\e[C": forward-word
"\e\e[D": backward-word
@caspian311
caspian311 / jenkins_console.groovy
Last active August 29, 2015 14:20
Jenkins script console to find out where a slave lives
println InetAddress.localHost.canonicalHostName