Skip to content

Instantly share code, notes, and snippets.

View ivanrad's full-sized avatar

ivanrad

  • Dublin, Ireland
View GitHub Profile
@ivanrad
ivanrad / RunApplyMigration.bat
Created October 23, 2012 10:34
Windows scripts
@echo off
rem RunApplyMigration -- run all ApplyMigration.bat scripts found in the modification scripts subfolders that are under source control
rem ApplyMigration.bat script will not be run if it contains ApplyMigration.exclude file next to itself (the file is a text file that may contain a reason why that particular migration step is to be skipped)
if "%1"=="" goto usemsg
setlocal
set migration_script=ApplyMigration.bat
set migration_exclude=ApplyMigration.exclude
echo Running migration scripts located under root folder: %1
@ivanrad
ivanrad / stopsvc.bat
Created October 23, 2012 12:49
Stop Windows service
@echo off
rem Stop Windows service
if _%1==_ goto help
for /f "tokens=2" %%i in ('sc query^|findstr /i /r "DISPLAY_NAME:.*%1"') do (
sc stop %%i
)
goto die
@ivanrad
ivanrad / install-user-to-sudoersd.sh
Last active March 20, 2021 16:00
Add user to sudoers (ALL NOPASSWD)
#!/bin/bash
#
# Add user to sudoers (ALL NOPASSWD).
# Usage: $0 [username] (if no username provided, the username of the current user is used)
#
[ $UID -eq 0 ] ||
{ echo "This script needs to be run with sudo -- \"sudo `basename $0`\"."; exit 1; }
[ -z "$1" ] && SUDOERS_USERNAME=$SUDO_USER || SUDOERS_USERNAME=$1
@ivanrad
ivanrad / s3cmd.bat
Created January 10, 2013 20:40
s3cmd.bat for (a more friendly) invocation of s3cmd on win32 envs
@echo off
if _%PYTHONHOME% == _ (python.exe %~dp0s3cmd -c %~dp0s3cmd.cfg %*) else (%PYTHONHOME%\python.exe %~dp0s3cmd -c %~dp0s3cmd.cfg %*)
@ivanrad
ivanrad / .pythonrc
Created May 6, 2013 01:39
Enable tab completion for interactive Python (PYTHONSTARTUP script)
# PYTHONSTARTUP=~/.pythonrc
#
# Enable tab completion for interactive python
try:
import readline
import rlcompleter
except ImportError:
pass
else:
@ivanrad
ivanrad / sqlservercentral.com.js
Last active December 18, 2015 03:49
Bookmarklet to strip/remove read gate on sqlservercentral.com
javascript:$('div#limitContainer').removeClass('transparent').removeAttr('id');$('div#displayStopperContainer').css('display', 'none');
@ivanrad
ivanrad / non_caching_filterprovider.md
Created February 15, 2014 13:23
Disable FilterAttribute Instance Caching in ASP.NET MVC 3/4 (by replacing the default instance of FilterAttributeFilterProvider with a non-caching one)

One of the breaking changes in ASP.NET MVC 3 (and upwards) is that action filters, once instantiated, are cached and re-used on subsequent requests. Here is the relevant excerpt from the official [ASP.NET MVC 3 release notes][aspnetmvc-relnotes]:

In previous versions of ASP.NET MVC, action filters are create per request except in a few cases. This behavior was never a guaranteed behavior but merely an implementation detail and the contract for filters was to consider them stateless. In ASP.NET MVC 3, filters are cached more aggressively. Therefore, any custom action filters which improperly store instance state might be broken.

Essentially, if you are dealing with legacy code, that has poorly implemented custom action filters, you may end up with unexpected behavior once you migrate to a newer ASP.NET MVC release.

So, what is one to do?

Well, apparently, the default filter provider (FilterAttributeFilterProvider) can be coerced into not caching instances of action filters. As it happens, its construct

@ivanrad
ivanrad / maintenance.js
Last active July 10, 2022 23:39
quick and dirty node.js maintenance (503 all -- well, almost all) server
var http = require('http');
var fs = require('fs');
var health_ok_body = "OK\n";
var default_503_body = "Back soon!\n";
var maintenance_file = __dirname + "/maintenance.html";
http.createServer(function (request, response) {
console.log('request: ' + request.url);
@ivanrad
ivanrad / gist:b0ba178ef590974ddfce
Created April 14, 2015 11:41
decode from URL-safe base64
public static byte[] FromUrlSafeBase64(string input)
{
// restore padding, if padding trimmed
int padding = 4 - (input.Length%4);
input = input.PadRight(padding, '=');
char[] buf = Array.ConvertAll(Encoding.UTF8.GetBytes(input), c => (char) c);
for (int i = 0; i < buf.Length; ++i)
switch (buf[i]) {
@ivanrad
ivanrad / generate_guid.cmd
Last active August 29, 2015 14:23
generate guid [powershell]
@echo off
powershell -ExecutionPolicy Unrestricted -Command "Write-Output([guid]::NewGuid().ToString())"