Skip to content

Instantly share code, notes, and snippets.

@maftieu
maftieu / CacheHelper.cs
Created January 11, 2016 09:11
ASP.Net Cache helper
/// <summary>
/// Implements a cache helper.
/// Taken from http://codereview.stackexchange.com/questions/25907/asp-net-caching-helper (comments added).
/// </summary>
public static class CacheHelper
{
/// <summary>
/// Retrieve the specified item from the cache if it is cached. Otherwise, insert it to the cache.
/// Note: of the cache is not available, the <paramref name="initializer"/> method may be called on every call.
/// </summary>
@maftieu
maftieu / NLogExtensions.cs
Created November 25, 2015 09:42
NLog extensions
public static class NLogExtensions
{
public static void WarnIf(this NLog.ILogger @this, bool condition, string message)
{
if (condition && @this.IsWarnEnabled)
{
@this.Warn(message);
}
}
#!/usr/bin/env node
/**
* After prepare, files are copied to the platforms/[platform] folder.
* Lets clean up some of those files that arent needed with this hook.
*/
var fs = require('fs');
var path = require('path');
var rootdir = process.argv[2];
@maftieu
maftieu / shrink.sql
Created September 17, 2015 10:53
Shrink database
-- réduire les LOGS
BACKUP LOG [Concours] TO DISK = N'E:\Backup\Concours-logs.bak'
USE [Concours]
ALTER DATABASE [Concours] SET RECOVERY SIMPLE WITH NO_WAIT
DBCC SHRINKFILE(Concours_Log, 1)
ALTER DATABASE [Concours] SET RECOVERY FULL WITH NO_WAIT
-- réduire le fichier de DATA
@maftieu
maftieu / app.py
Last active August 29, 2015 14:26 — forked from panchr/app.py
Queued (I/O intensive) operations in Python
from queue_db import QueuedWriter
from pymongo import Connection
from flask import Flask
from json import dumps
def main():
'''This is just an example using Flask and MongoDB/pymongo.
Of course, you can use any web server and any database as long as you set up the methods appropriately'''
@maftieu
maftieu / generate-pass.html
Created July 28, 2015 14:42 — forked from flesler/generate-pass.html
Bookmarklet to generate deterministic passwords based on a service name
<pre>
(function(length, prefix, suffix, map) {
/* Version 1.0 */
var p = location.hostname.split('.');
// Find service name
do { var pass = p.pop(); }
while (p.length && pass.length <= 3);
// First time assume domain
if (!this._custom_) {
this._custom_ = true;
@maftieu
maftieu / vs.ps1
Last active August 29, 2015 14:26
Edit all C# files inside a project
# this requires NuGet to be installed, so it will bring the PowerShell command line
# and the EnvDTE object. See: https://msdn.microsoft.com/en-us/library/EnvDTE.aspx
function DoItOnProjectItem($item) {
$doc = $item;
if ($doc.Name -match "\.cs$") {
write-host $doc.Name;
# open and display document
$foo = $doc.Open("{7651A701-06E5-11D1-8EBD-00A0C90F26EA}"); # vsViewKindCode -> to display code window
@maftieu
maftieu / Benchmark.cs
Last active February 5, 2016 13:01
Quick benchmark method
using System;
class Benchmarker
{
const int NB_RUN = 5;
public static void Benchmark(Action testMethod, string testName = null, bool blankRun = false)
{
if (string.IsNullOrEmpty(testName))
testName = testMethod.Method.Name;
@maftieu
maftieu / EnumExtensions.cs
Created January 15, 2015 11:23
C# - Extension methods for Enum
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
namespace Untunh.Helpers
{
/// <summary>
/// Provides a set of static methods for querying objects that represent an enumeration.
/// </summary>
@maftieu
maftieu / Extensions.cs
Last active February 5, 2016 13:46
C# - IEnumerable extensions
using System;
using System.Collections.Generic;
using System.Linq;
namespace Untunh.Helpers
{
/// <summary>
/// Provides a set of static methods for querying objects that implement System.Collections.Generic.IEnumerable<T>.
/// </summary>
public static class Extensions