Skip to content

Instantly share code, notes, and snippets.

View goldshtn's full-sized avatar

Sasha Goldshtein goldshtn

View GitHub Profile
@goldshtn
goldshtn / stackalloc-benchmark.cs
Created October 17, 2013 09:03
Benchmark for comparing stackalloc to heap allocations for small, medium, and large arrays.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StackAllocVsHeapAlloc
{
public static class Sandbox
@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 / cpp11.cpp
Last active May 8, 2018 01:24
A single function that uses a bunch of C++11/14 features and for "old-school" C++ developers will not even read like C++ anymore.Specifically, it uses:- lambda functions (C++11) with generalized capture semantics (C++14)- rvalue references (C++11)- auto variables (C++11)- decltype and trailing function return type syntax (C++11)- std::move and s…
#include <iostream>
#include <future>
using namespace std;
template <typename Fn, typename... Args>
auto do_async_with_log(ostream& os, Fn&& fn, Args&&... args) ->
future<decltype(fn(args...))>
{
os << "[TID=" << this_thread::get_id()
@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 / 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)
{
@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 / 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 / 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 / ioslab2.md
Last active February 22, 2017 13:27
iOS Lab #2

Download the course materials; this archive contains the presentations, demos, and lab solutions. Please do not distribute these materials outside of your group.

In this lab, you will create a simple tip calculator which you’d then be able to use to split the bill and tip across your friends. You should use the iOS > Application > Single View Application project template in Xcode, because you will only have one screen and one view controller.

Your UI should have the following components:

  • A title label that reads “Tip Calculator” – feel free to use a cute font here.
  • A text field for the bill amount, and a label that explains what it is.
  • A toggle switch that determines whether to round the bill to the nearest dollar, and a label that explains what it is.
  • A button that reads “Split Bill”, which, when tapped, calculates the bill amount and tip amount for each person in your party and displays it in a separate label underneath the button.
@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>,