Skip to content

Instantly share code, notes, and snippets.

View goldshtn's full-sized avatar

Sasha Goldshtein goldshtn

View GitHub Profile
@goldshtn
goldshtn / bad-metadata.cs
Created January 20, 2014 14:11
An example of a WCF service that causes metadata publishing to fail such that "Add Service Reference" reports a cryptic failure.
[ServiceContract]
interface IChatClient
{
[OperationContract(IsOneWay = true)]
void Message(string message);
}
[ServiceContract(CallbackContract = typeof(IChatClient))]
interface IChatService
{
@goldshtn
goldshtn / primes-parallelization.cpp
Created October 23, 2013 15:18
Benchmark for parallelizing work unevenly across multiple threads.
#include <chrono>
#include <thread>
#include <iostream>
#include <cmath>
#include <vector>
#include <functional>
#include <algorithm>
template <typename Fn>
double avg_time_ms(Fn&& fn, unsigned int repetitions) {
@goldshtn
goldshtn / dp.asm
Created August 15, 2015 07:12
Dot product of shorts and floats: C# vs. C++
; C#, RyuJIT, release, x64
00007ffe`fc6808ec 4c63c8 movsxd r9,eax ; loop: r9 = i
00007ffe`fc6808ef 4e0fbf4c4910 movsx r9,word ptr [rcx+r9*2+10h] ; r9 = a[i]
00007ffe`fc6808f5 f3410f2ac9 cvtsi2ss xmm1,r9d ; xmm1 = (float)r9d
00007ffe`fc6808fa 4c63c8 movsxd r9,eax ; r9 = i
00007ffe`fc6808fd f3420f594c8a10 mulss xmm1,dword ptr [rdx+r9*4+10h] ; xmm1 *= b[i]
00007ffe`fc680904 f30f58c1 addss xmm0,xmm1 ; sum += xmm1
00007ffe`fc680908 ffc0 inc eax ; ++i
00007ffe`fc68090a 443bc0 cmp r8d,eax ; if i < a.Length
00007ffe`fc68090d 7fdd jg 00007ffe`fc6808ec ; goto loop
@goldshtn
goldshtn / typelist_sort.cpp
Last active August 29, 2015 14:13
Sort a typelist by size at compile-time, using quicksort.
template <typename Predicate, typename Head, typename... Tail>
struct typelist_sort_t<Predicate, typelist<Head, Tail...>>
{
using predicate = meta_partial_apply<Predicate, Head>;
using notpredicate = meta_negate<predicate>;
using smaller_than = typelist_filter<notpredicate, typelist<Tail...>>;
using greater_than = typelist_filter<predicate, typelist<Tail...>>;
using type = typelist_cat<
typelist_sort<Predicate, smaller_than>,
typelist<Head>,
@goldshtn
goldshtn / lab1.md
Last active August 29, 2015 14:09
iOS Lab 1

In this lab, you will experiment with Objective C fundamentals in a Mac terminal application that does not display any user interface. Everything you do in this lab is applicable to iOS as well – we will not use any API that is not available in iOS.

Begin by creating an Xcode project of type OS X > Application > Command Line Tool. (In the Type combo box, select “Foundation” if it isn’t selected.) Add classes as necessary per the instructions below using File > New > File, OS X > Cocoa > Objective C Class.

Implement a PlayingCard class that has the following methods, initializers, and properties:

  • NSString* suit property
  • NSUInteger rank property (valid values are 1-13, where 1 = “Ace”, …, 13 = “King”)
  • NSString* contents read-only property that returns the card name (e.g. “Jack of Spades”)
@goldshtn
goldshtn / installations.md
Last active August 29, 2015 14:08
BuildStuffLT 2014 - .NET Debugging Workshop Installation Requirements

.NET Debugging Workshop installation requirements

Please have the following software installed on your laptop prior to coming to the workshop. Downloading this software during the day might prove problematic because of the large file sizes and the network speed. Thank you!

Additionally, the labs we will use during the workshop are available here. Please download and extract the files before the workshop.

If you have any questions about the above installation instructions, please contact the instructor, Sasha Goldshtein.

@goldshtn
goldshtn / main.cpp
Created July 17, 2014 06:42
Demo app for experimenting with WinDbg. Compile with Visual C++ 2013.
#include <Windows.h>
#include <vector>
#include <iostream>
#include <thread>
#include <random>
class DynamicArray
{
char* data_;
unsigned len_;
@goldshtn
goldshtn / non-paged-pool-leak.cpp
Created February 16, 2014 11:04
Non-Paged Pool Leak
#include <Windows.h>
#include <Psapi.h>
#include <string>
#include <iostream>
void VERIFY(bool condition, std::string message)
{
if (!condition)
{