Skip to content

Instantly share code, notes, and snippets.

View undeadcat's full-sized avatar

Maxim Kropotov undeadcat

View GitHub Profile
@undeadcat
undeadcat / gist:3916cc75cd3263ff37b8
Last active August 29, 2015 14:15
Units of measure magic
let inline retype (t : ^t) :^tm = (# "" t : ^tm #)
let inline (++) (w : ^W when ^W : (static member IsMeasureAbbrev : ^tm * ^t -> unit)) (t : ^t) = (# "" t : ^tm #)
open System
[<MeasureAnnotatedAbbreviation>]
type Guid<[<Measure>] 'Measure> = Guid
[<MeasureAnnotatedAbbreviation>]
type string<[<Measure>] 'Measure> = string
@undeadcat
undeadcat / gist:5548c729896f87da752c
Created February 28, 2015 15:21
FSharp.Data.SqlClient
open FSharp.Data
open Microsoft.FSharp.Data.TypeProviders
open Microsoft.FSharp.Linq
open System
open System.Data
module UserQueries =
[<Literal>]
//design time only
let connStr = @"Data Source=localhost\Sqlexpress;Initial Catalog=mskr;Integrated Security=True"
@undeadcat
undeadcat / streams.fs
Created August 17, 2015 20:07
Streams
open System
type Stream<'t> =
| Empty
| Stream of 't * (unit -> Stream<'t>)
let takeList count stream =
let rec inner remain remainCount tail =
match (remain, remainCount) with
| (Empty, _) -> tail
public static void Main(){
using(AcquireDistributedLock()){
DoSomethingThatRequiresLock();
}
}
@undeadcat
undeadcat / crash
Created August 20, 2015 15:36
crash
Incident Identifier: 11CF1940-CA86-4C1A-B8F0-7C50F6A5E984
CrashReporter Key: 2fedf6f90d0249b947565c96b61b0d4f438e7e7b
Hardware Model: iPhone4,1
Process: ElbaMobileiOS [3229]
Path: /private/var/mobile/Containers/Bundle/Application/D6405C43-60AE-47EA-8FBC-70AD165F5BCA/ElbaMobileiOS.app/ElbaMobileiOS
Identifier: com.kontur.elba.extend
Version: 2 (1.0)
Code Type: ARM (Native)
Parent Process: launchd [1]
@undeadcat
undeadcat / MonoGenericWeirdness.cs
Last active September 4, 2015 17:15
Mono Generic Constraint Bug?
public abstract class ThingWithOrganizationId
{
public Guid OrganizationId;
}
public class Thing : ThingWithOrganizationId
{
}
public abstract class BaseService<TConstraint>
@undeadcat
undeadcat / fatrequest
Created September 12, 2015 10:36
fatrequest
https://elba.kontur.ru/AccessControl/Login.aspx?promoButton=KonturHeadLink&promoPage=%2f&referer=http%3a%2f%2fwww.google.ru%2faclk%3fsa%3dl%26ai%3dCza-mwd_yVbCVO8iBzAPY-5-wBs3Us80F_fXN5qkB_6nRqpkBCAAQAWCExe6FgB6gAcOdhuADyAEBqQKdI4OYVIxPPqoELE_QRCuSjLpCxccUbZ0Ohqhbit9z1DRjd7hXA3SoQM_CRp5AMD1EEOSNxHOYgAel4vkfiAcBkAcCqAemvhvYBwE%26sig%3dAOD64_2q4mgtxSNIVHrEL4GgnSICdp5bBw%26clui%3d0%26rct%3dj%26q%3d%26ved%3d0CBkQ0QxqFQoTCPqok7aT78cCFQEQLAodSnIKcw%26adurl%3dhttp%3a%2f%2fe-kontur.ru%3futm_source%3dGoogleAdwords%26utm_medium%3dcpc%26utm_content%3dElbaRulez%26utm_campaign%3dskb-elba-google%26utm_term%3dhttp%252520%2525D1%25258D%2525D0%2525BB%2525D1%25258C%2525D0%2525B1%2525D0%2525B0%252520%2525D1%252581%2525D0%2525BA%2525D0%2525B1%2525D0%2525BA%2525D0%2525BE%2525D0%2525BD%2525D1%252582%2525D1%252583%2525D1%252580%252520%2525D1%252580%2525D1%252584%26p%3d5555123&yaDirectParamsLast=utm_source%3dGoogleAdwords%26utm_medium%3dcpc%26utm_content%3dElbaRulez%26utm_campaign%3dskb-elba-google%26utm_term%3dhttp%2520%25D1%258D%2
@undeadcat
undeadcat / cassandra.java
Created October 15, 2015 09:48
Cassandra code. Mutate all the things!
public List<InetAddress> filterForQuery(Keyspace keyspace, List<InetAddress> liveEndpoints, ReadRepairDecision readRepair)
{
/*
* Endpoints are expected to be restricted to live replicas, sorted by snitch preference.
* For LOCAL_QUORUM, move local-DC replicas in front first as we need them there whether
* we do read repair (since the first replica gets the data read) or not (since we'll take
* the blockFor first ones).
*/
if (isDCLocal)
Collections.sort(liveEndpoints, DatabaseDescriptor.getLocalComparator());
@undeadcat
undeadcat / AbstractReadExecutor.java
Created October 15, 2015 09:52
Beautiful Cassandra
public abstract class AbstractReadExecutor
{
protected void makeDataRequests(Iterable<InetAddress> endpoints)
protected void makeDigestRequests(Iterable<InetAddress> endpoints)
private void makeRequests(ReadCommand readCommand, Iterable<InetAddress> endpoints)
public abstract void maybeTryAdditionalReplicas();
public abstract Collection<InetAddress> getContactedReplicas();
public abstract void executeAsync();
public PartitionIterator get() throws ReadFailureException, ReadTimeoutException, DigestMismatchException
@undeadcat
undeadcat / Conflicts.java
Created October 15, 2015 10:15
Conflict Resolution
public abstract class ReadCommand extends MonitorableImpl implements ReadQuery
/**
* The time in seconds to use as "now" for this query.
* <p>
* We use the same time as "now" for the whole query to avoid considering different
* values as expired during the query, which would be buggy (would throw of counting amongst other
* things).
*
* @return the time (in seconds) to use as "now".
*/