Skip to content

Instantly share code, notes, and snippets.

View meziantou's full-sized avatar

Gérald Barré meziantou

View GitHub Profile
@meziantou
meziantou / SR.tt
Created June 24, 2014 07:02
SR.tt
<#@ template language="C#" hostspecific="true" debug="true" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="System.Windows.Forms" #>
<#@ assembly name="System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" #>
<#@ assembly name="System.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" #>
<#@ import namespace="System.Collections" #>
<#@ import namespace="System.Globalization" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Reflection" #>
@meziantou
meziantou / PasswordHasher.cs
Created June 24, 2014 07:06
ASP.NET Identity
public class PasswordHasher : IPasswordHasher
{
public int Pbkdf2IterCount { get; set; }
public int Pbkdf2SubkeyLength { get; set; }
public int SaltSize { get; set; }
public PasswordHasher()
{
@meziantou
meziantou / directive.js
Created June 24, 2014 07:07
Angularjs RegisterForm
app.directive('input', ['$parse', function ($parse) {
/*
* Initialize model from input value
*/
return {
restrict: 'E',
require: '?ngModel',
link: function (scope, element, attrs) {
if (attrs.ngModel && attrs.value) {
$parse(attrs.ngModel).assign(scope, attrs.value);
@meziantou
meziantou / app.config
Last active August 29, 2015 14:03
ETW
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
</startup>
<system.diagnostics>
<trace autoflush="true" indentsize="4">
<listeners>
<remove name="Default" />
@meziantou
meziantou / SearchUniqueIdentifier
Last active August 29, 2015 14:13
Search uniqueidentifier (guid) in SQL Server database
DECLARE @searchValue uniqueidentifier = 'a2843a1e-6ed4-4045-a179-51f0743943b8'
DECLARE @sql NVARCHAR(MAX);
WITH cte_sql_queries(sql_query) AS (
-- SELECT '[dbo].[Customer]' FROM [dbo].[Customer] WHERE [Customer_Id]=@searchValue
SELECT 'SELECT ''' + QUOTENAME(t.TABLE_SCHEMA) + ''' schema_name '
+ ' , ''' + QUOTENAME(t.TABLE_NAME) + ''' table_name '
+ ' , ''' + QUOTENAME(c.COLUMN_NAME) + ''' column_name '
+ ' , ''SELECT ' + QUOTENAME(c.COLUMN_NAME) + ', * FROM ' + QUOTENAME(t.TABLE_SCHEMA) + '.' + QUOTENAME(t.TABLE_NAME) + ' WHERE ' + QUOTENAME(c.COLUMN_NAME) + '='''''+ CAST(@searchValue AS NVARCHAR(36)) +''''''' query '
+ ' FROM ' + QUOTENAME(t.TABLE_SCHEMA) + '.' + QUOTENAME(t.TABLE_NAME)
@meziantou
meziantou / LazyLoad.ts
Created December 19, 2015 18:20
Lazy load images
module LazyLoader {
const attributeName = "data-src";
function throttle(wait: number, func: () => any, immediate = false) {
var context: any;
var args: any;
var timeoutHandle: number;
var result: any;
var previous: Date;
@meziantou
meziantou / OneDriveFilePicker.ts
Created April 23, 2017 09:05
OneDriveFilePicker.ts
document.getElementById("OpenOneDrive").addEventListener("click", e => {
e.preventDefault();
launchOneDrivePicker().then(result => {
if (result) {
for (const file of result.value) {
const name = file.name;
const url = file["@microsoft.graph.downloadUrl"];
console.log({ name: name, url: url });
fetch(url)
@meziantou
meziantou / program.cs
Last active December 18, 2017 02:05
Benchmark string concat
class Program
{
static void Main(string[] args)
{
BenchmarkRunner.Run<StringBenchmark>();
}
}
[OrderProvider(SummaryOrderPolicy.FastestToSlowest)]
[CoreJob]
@meziantou
meziantou / RemoteDataCache.cs
Created January 2, 2018 13:46
RemoteDataCache
using System;
using System.Threading;
using System.Threading.Tasks;
namespace ClassLibrary1
{
public abstract class RemoteDataCache<T> : IDisposable
{
private readonly SemaphoreSlim _semaphoreSlim = new SemaphoreSlim(1, 1);
private CacheValue<T> _value;
@meziantou
meziantou / main.cs
Created January 29, 2018 03:20
Paste images
private void OnPaste(object sender, DataObjectPastingEventArgs e)
{
HandleDataObject(e.DataObject);
e.Handled = true;
}
private void HandleDataObject(IDataObject data)
{
if (data == null) throw new ArgumentNullException(nameof(data));