Skip to content

Instantly share code, notes, and snippets.

View jesuslpm's full-sized avatar

Jesús López jesuslpm

View GitHub Profile
@jesuslpm
jesuslpm / index.cs
Last active November 13, 2017 13:58
The world’s smallest indexing code
public class Index<TItem, TKey>
{
private readonly SortedSet<KeyValuePair<TKey, List<TItem>>> sortedSet;
public Index(IEnumerable<TItem> items, Func<TItem, TKey> keySelector, Comparer<TKey> keyComparer = null)
{
if (keyComparer == null) keyComparer = Comparer<TKey>.Default;
var keyPairComparer = Comparer<KeyValuePair<TKey, List<TItem>>>.Create((x, y) => keyComparer.Compare(x.Key, y.Key));
var keyPairs = items.GroupBy(keySelector).Select(x => new KeyValuePair<TKey, List<TItem>>(x.Key, x.ToList()));
sortedSet = new SortedSet<KeyValuePair<TKey, List<TItem>>>(keyPairs, keyPairComparer);
@jesuslpm
jesuslpm / posts.xml
Last active September 30, 2016 07:21
StackOverflow THAT
<?xml version="1.0" encoding="utf-8" ?>
<rows>
<row Id="4"
PostTypeId="1"
Body="This is the body of question 4"
Title="When setting a form's opacity should I use a decimal or double"
AnswerCount="5"
/>
<row Id="6"
@jesuslpm
jesuslpm / UserDataSearcher.cs
Created March 17, 2016 12:20
Ayende csv user data searcher 2
public class UserData
{
public int Id { get; set; }
public string Email { get; set; }
}
public class UserDataSearcher
{
private readonly List<UserData> userDataList;
@jesuslpm
jesuslpm / userdata.cs
Last active March 15, 2016 15:18
Ayende csv user data
public class UserData
{
public int Id { get; set; }
public string Email { get; set; }
}
public class UserDataSearcher
{
private readonly Dictionary<string, List<int>> userIdsByEmail;
using System;
using System.Collections.Generic;
using System.Threading;
namespace ConsoleApplication1
{
class Program
{
private static int count;
@jesuslpm
jesuslpm / script
Created September 11, 2014 08:39
RavenDB to SQL Server sql script sample
CREATE TABLE [dbo].[OrderLines]
(
[Id] int IDENTITY CONSTRAINT PK_OrderLines PRIMARY KEY NONCLUSTERED,
[OrderId] [nvarchar](50) NOT NULL,
[Qty] [int] NOT NULL,
[Product] [nvarchar](255) NOT NULL,
[Cost] [int] NOT NULL
);
CREATE CLUSTERED INDEX IX_OrderLines_OrderId
@jesuslpm
jesuslpm / Executing the procedure
Created April 9, 2014 10:58
First steps in EntityLite to support ORACLE ref cursors
using (var ds = new NorthwindDataService())
{
object cSubTree;
ds.EmployeeRepository.EmployeeSubtree(2, out cSubTree);
IDataReader reader = ((dynamic)cSubTree).GetDataReader();
foreach(var employee in reader.ToList<Employee>())
{
Console.WriteLine("{0}, {1}", employee.FirstName, employee.LastName);
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
unsigned char RandomByte(unsigned char maxValue)
{
return (unsigned char) ((unsigned long)rand() * maxValue / RAND_MAX);
}
// ConsoleApplication1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <stdlib.h>
#include <string.h>
#include <ctime>
struct INTEGER_LIST
{
@jesuslpm
jesuslpm / SessionStoreIgnoresEtag.cs
Created October 9, 2012 15:23
session.Store(entity, etag) ignores the etag if the entity is the session
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Raven.Client.Document;
using Raven.Client.Embedded;
using Raven.Client;
namespace Test
{