Skip to content

Instantly share code, notes, and snippets.

View aanari's full-sized avatar

Ali Anari aanari

View GitHub Profile
@aanari
aanari / ifxconvert.py
Created March 21, 2012 14:38
Informix Schema to Fluent nHibernate
import os, re, string
from collections import defaultdict
types = {'char': 'string',
'nchar': 'string',
'varchar': 'string',
'lvchar': 'string',
'text': 'string',
'clob': 'string',
'bigint': 'long',
@aanari
aanari / clean.py
Created March 31, 2012 21:09
Calibre Duplicate Folders
import os, stat, shutil, re
for author in [author for author in os.listdir('.') if os.path.isdir(os.path.join('.', author))]:
lastbook = {}
for book in [re.search('(?P<title>.*)\s?\((?P<id>\d+)\)', book).groupdict() for book in os.listdir(author + '/.') if os.path.isdir(os.path.join('.', author + '/' + book))]:
if book['title'] in lastbook:
if float(book['id']) > float(lastbook[book['title']]):
lastbook[book['title']] = book['id']
else:
lastbook[book['title']] = book['id']
@aanari
aanari / gist:2521748
Created April 28, 2012 20:21
Secure Anonymous Browsing
ssh -c arcfour,blowfish-cbc -XC [server] chromium --incognito
@aanari
aanari / indesign.py
Created May 8, 2012 02:13
Recover InDesign File
#!/usr/bin/python
#-*-coding:utf-8-*-
import re, string, os
inddtags = re.compile('@\S+')
xmltags = re.compile("""<(?:([a-zA-Z\?][\w:\-]*)(\s(?:\s*[a-zA-Z][\w:\-]*(?:\s*=(?:\s*"(?:\\"|[^"])*"|\s*'(?:\\'|[^'])*'|[^\s>]+))?)*)?(\s*[\/\?]?)|\/([a-zA-Z][\w:\-]*)\s*|!--((?:[^\-]|-(?!->))*)--|!\[CDATA\[((?:[^\]]|\](?!\]>))*)\]\])>""")
cleanup = re.compile('[^a-zA-Z0-9\n ]+')
smash = re.compile('(\S+){16}')
inputfile = open('1.indd', 'rb')
@aanari
aanari / changelog.ps1
Created May 8, 2012 13:33
Visual Studio + Git Changelog Generator
$commitlog = '<!doctype html><html><body>'
foreach($line in git log --no-merges --pretty=%H%n%B){
if ($line -match '\w{40}') {
$commit = git show $line -- Properties/AssemblyInfo.cs
[string] $vers = $commit -match '\+\[assembly: AssemblyVersion\("(\d\.\d\.\d\.\d)"\)\]'
if ($vers) {
$vnum = $vers.Split('\"')[1]
if ($vnum) {
$line = '<hr><span class="version">Version ' + $vnum + ':</span>'
} else {
@aanari
aanari / fixgit.sh
Created May 8, 2012 18:48
Git Fix Commit Author + Email
git filter-branch --commit-filter '
if [ "$GIT_COMMITTER_EMAIL" = "old@email" ];
then
GIT_COMMITTER_NAME="Full Name";
GIT_AUTHOR_NAME="Full Name";
GIT_COMMITTER_EMAIL="new@email";
GIT_AUTHOR_EMAIL="new@email";
git commit-tree "$@";
else
git commit-tree "$@";
@aanari
aanari / gist:2701394
Created May 15, 2012 12:30
Clean Names in C#/LINQ
var inputNames = new [] { "Ann Boelyn", "King Henry VIII", "Charles of Macedonia", "Edgar J. Hoover", "Birkenstock", "Teenage Mutant Ninja Turtles", "Henry Ford Sr.", "Alexander the Great Jr.", "Sir Ixion Galahad", "W. Bryan Cranston, Jr.", "Neil Patrick-Harris", "Harold & Kumar", "Tipsy/Topsy/Turvy", "Eddard, House of Stark", "Jay Z"}.ToList();
var excludeList = new [] { ",", "/", "&", "@", "(", ")" }.ToList();
var matchNames = new List<string>();
TextInfo textInfo = Thread.CurrentThread.CurrentCulture.TextInfo;
foreach (var name in inputNames)
{
if (!excludeList.Any(name.Contains))
{
var cleanName = Regex.Match(name, @"(.+?)(\s(?:I|II|III|Jr|Sr)?(?:\.)?)?$").Groups[1].Value;
var match = Regex.Match(cleanName, @"^(\S+) (?:(?:\S.\ )|(?:\S+ ))?(\S+)");
@aanari
aanari / gist:3122542
Created July 16, 2012 12:59
Fix CommandTimeout in DbContext
public class MyContext : DbContext
{
public MyContext ()
: base(ContextHelper.CreateConnection("my connection string"), true)
{
((IObjectContextAdapter)this).ObjectContext.CommandTimeout = 300;
}
}
@aanari
aanari / gist:3177837
Created July 25, 2012 18:46
SQL Return Duplicates
select afield1,count(afield1) from atable
group by afield1 having count(afield1) > 1
@aanari
aanari / gist:3188223
Created July 27, 2012 14:10
MS SQL Kill Database
USE Master;
GO
ALTER DATABASE AnnoyingDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
DROP DATABASE AnnoyingDB;
GO