Skip to content

Instantly share code, notes, and snippets.

@brunomlopes
brunomlopes / time_tracking_in_270_lines.cs
Created February 7, 2011 11:28
Preview of how to do simple and stupid time tracking in 270 lines and 45 minutes as an ilovelucene "plugin"
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Core.Abstractions;
using Lucene.Net.Documents;
@brunomlopes
brunomlopes / ShowBranchOnMainWindowTitle.ps1
Created December 20, 2011 15:42
Open "Package Manager Console" and execute this to show the full solution name and git branch on the main window title
$output = git status
$branchbits = $output[0].Split(' ')
$branch = $branchbits[$branchbits.length - 1]
$signature = @"
[DllImport("user32.dll")]
public static extern bool SetWindowText(IntPtr hWnd, string lpString);
"@
@brunomlopes
brunomlopes / ResetCacheOnDefaultWidgetChangePlugin.cs
Created December 22, 2011 16:10
Telligent 6.0 plugin to auto-reset cache when a default widget file changes
#if DEBUG
public class ResetCacheOnDefaultWidgetChangePlugin : IPlugin
{
public void Initialize()
{
SetupFileSystemWatcher();
}
private void SetupFileSystemWatcher()
{
@brunomlopes
brunomlopes / get-endlineformat.ps1
Created January 10, 2012 19:01
Powershell function to get the endline format of a file.
function Get-EndlineFormat {
param($filepath)
# by default get-content reads one 'item' at a time.
# and reading 1 byte at a time will take a long long time
# -ReadCount 0 makes it read it all at once.
$bytes = get-content -encoding byte -ReadCount 0 $filepath
$string = [Text.Encoding]::Ascii.GetString($bytes, 0, $bytes.Count)
$is_unix = ([regex] "[^`r]`n").Matches($string).Count -gt 0 `
-and ([regex] "`r`n").Matches($string).Count -eq 0
@brunomlopes
brunomlopes / behaviour.cs
Created May 7, 2012 02:55
Strange RavenDB behaviour with counts
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Raven.Client;
using Raven.Client.Embedded;
using Raven.Client.Indexes;
namespace ConsoleApplication5
{
class Program
@brunomlopes
brunomlopes / DeobfuscateSmartAssemblyString
Created November 27, 2012 14:30
Simple code to load a SmartAssembly assembly and extract strings based on the obfuscated numbers
internal class DeobfuscateString
{
private readonly string[] _args;
private MethodInfo _method;
private string _assemblyPath;
private DeobfuscateString(string[] args)
{
_args = args;
}
@brunomlopes
brunomlopes / ravendb.py
Last active December 10, 2015 06:58 — forked from anonymous/ravendb.py
A very dumb and simple API to get and put objects from ravendb
# gist: https://gist.github.com/4397669
import logging, requests, simplejson
from datetime import datetime
dthandler = lambda obj: obj.isoformat() if isinstance(obj, datetime) else None
def dumps(obj):
return simplejson.dumps(obj, use_decimal=True, default=dthandler)
l = logging.getLogger("ravendb")
@brunomlopes
brunomlopes / cgd.py
Last active January 17, 2025 15:46
Simple api to fetch accounts, balances and transactions from Caixa Geral de Depósitos's ( CGD ) API used by their Windows 8 application.
# gist: https://gist.github.com/4397792
# Usage:
# session = cgd.CgdSession(uid, password)
# session.login()
# session.load_latest_transactions(account_key)
# 'session.known_accounts' is now populated with the initial accounts taken from the login response,
# and the data for the 'account_key' account.
# session.load_latest_transactions(account_key) loads the latest transactions and balances for a given account.
@brunomlopes
brunomlopes / GlimpseServiceLocator
Created July 31, 2013 18:04
Overriding Glimpse's default resource so we can enable it in production and doesn't leak information when someone tries to access glimpse.axd
using System.Collections.Generic;
using System.Linq;
using System.Net;
using Glimpse.Core.Extensibility;
using Glimpse.Core.Framework;
using Glimpse.Core.ResourceResult;
namespace weListen.Infrastructure
{
public class GlimpseServiceLocator : IServiceLocator
using System.Collections.Generic;
using System.Diagnostics;
using ServiceStack;
using ServiceStack.Auth;
namespace Test
{
public class CustomAuthUserSession : AuthUserSession
{
public string UserId { get; set; }