Skip to content

Instantly share code, notes, and snippets.

View ruslander's full-sized avatar

Ruslan Rusu ruslander

View GitHub Profile
@ruslander
ruslander / AppDependencies.cs
Created April 7, 2011 16:01
Track explicitly all application dependencies, verify them before letting the business to go wrong
public class AppDependencies
{
public static void AreAllSatisfied()
{
IsValidConnectionString();
IoC.AllTheTypesAreResolvable();
var appConfig = IoC.Resolve<IAppConfig>();
AssertDirectoryExists(appConfig.Logs);
AssertDirectoryExists(appConfig.Assets);
@ruslander
ruslander / Pipeline.cs
Created April 12, 2011 21:32
Pipeline steps in complex processes
public class Pipe<T>
{
private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private readonly List<Type> _operations = new List<Type>();
public Pipe<T> Register<TOperation>() where TOperation : IOperation<T>
{
_operations.Add(typeof(TOperation));
IoC.Register<TOperation>();
@ruslander
ruslander / TaskScheduler.cs
Created April 12, 2011 21:38
A task scheduler which will escape current tick if is busy with previous
public class TaskScheduler
{
private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private readonly Timer _timer;
public ServiceContext(DrawingsController controller, IAppConfig config): base(controller)
{
var _interval = 1000 * 60 * config.DrawEveryNMinutes;
@ruslander
ruslander / SqlBackupToRestoreFromFile
Created April 18, 2011 13:47
MS Sql Backup, Restore script
=========== BACKUP
USE master;
BACKUP DATABASE [Ecp]
TO DISK = N'C:\dbbackups\ecp.Bak' WITH NOFORMAT, NOINIT,
NAME = N'Ecp-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10
=========== RESTORE
USE master;
ALTER DATABASE [Ecp] SET OFFLINE WITH
ROLLBACK IMMEDIATE
@ruslander
ruslander / gist:1674375
Created January 25, 2012 03:00
Bootstrap your blog with Tumblr
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>{Title}</title>
<link rel='icon' href='{Favicon}'>
<link rel='shortcut icon' href='{Favicon}'>
<link rel='alternate' type='application/rss+xml' href='{RSS}'>
<meta name='description' content='{MetaDescription}'>
<meta name='color:Link' content='#6699cc'>
@ruslander
ruslander / Bcp.TableToFile.And.FileToTable.cmd
Created September 4, 2012 14:31
BCP dump table to file and load table from file
Dump
BCP PRO_CITIFXRPTDB01.dbo.network_metrics OUT c:\network_metrics.txt -T -c
Load
BCP PRO_CITIFXRPTDB01.dbo.network_metrics IN C:\reporting\network_metrics.txt -T -c
More details here
http://sqlwithmanoj.wordpress.com/tag/bcp-queryout/
http://msdn.microsoft.com/en-us/library/ms162802.aspx
@ruslander
ruslander / eunitrunner
Created December 4, 2012 04:06
Erlang Rebar continuous test runner
$app = "C:\Users\rrusu\Documents\GitHub\Er101"
$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = "$app\src\"
$watcher.IncludeSubdirectories = $true
$watcher.EnableRaisingEvents = $false
$watcher.NotifyFilter = [System.IO.NotifyFilters]::LastWrite -bor [System.IO.NotifyFilters]::FileName
set-location $app
while($TRUE){
@ruslander
ruslander / Install vimerl
Last active December 9, 2015 17:18
Install vim erl on ubuntu
# Create required directories
mkdir -p ~/.vim/autoload ~/.vim/bundle
# Install pathogen
wget -O ~/.vim/autoload/pathogen.vim https://raw.github.com/tpope/vim-pathogen/HEAD/autoload/pathogen.vim
echo "call pathogen#infect()" >> ~/.vimrc
# Install vimerl
wget -O vimerl.tar.gz https://github.com/jimenezrick/vimerl/tarball/master
[Test]
public void decodeTest() {
Assert.AreEqual(19158, decode("e9a"));
}
[Test]
public void encodeTest()
{
Assert.AreEqual("cb", encode(125));
}
@ruslander
ruslander / gist:4950210
Created February 14, 2013 02:44
routing debug
Dispatch = cowboy_router:compile([
{'_', [
{"/", cowboy_static,
[{directory, {priv_dir, web, []}},
{mimetpyes, [{<<".html">>, [<<"text/html">>]}]},
{file, <<"index.html">>}]},
{"/js/[...]", cowboy_static,
[{directory, {priv_dir, web, [<<"js">>]}},
{mimetypes, {fun mimetypes:path_to_mimes/2, default}}]},