Skip to content

Instantly share code, notes, and snippets.

View c4tachan's full-sized avatar

Michael Patrick Tkacik c4tachan

View GitHub Profile
@c4tachan
c4tachan / AsyncAwaitDemo.cs
Last active September 19, 2019 20:31
Example program to demonstrate/experiment with how async/await works and what happens if you make mistakes. There are intentionally compiler warnings in this code.
using System;
using System.Threading;
using System.Threading.Tasks;
using System.Reflection;
namespace AsyncAwaitExperimentation
{
class Program
{
static async Task Main(string[] args)
using System;
using System.Collections.Generic;
using System.Linq;
namespace testFirstOrDefault
{
class Program
{
static void Main(string[] args)
{
@c4tachan
c4tachan / NewAlg
Created June 12, 2015 18:39
New Algorithm
const vector<CaseItem> vCases = ((eLoginMode == LoginContinueCase) ? GetContinuableCases()
/*else if*/ : ((eLoginMode == LoginNewCase) ? LoginDialog::GetCaseManager().GetPreOpCases()
/*else if*/ : ((eLoginMode == LoginReviewCase) ? GetReviewableCases()
/*else if*/ : ((eLoginMode == LoginAmendCase) ? GetAmendableCases()
/*else*/ : vector<CaseItem>()))));
if (Row < vCases.size())
{
if (LoginDialog::GetSelectedCase() == vCases[Row].strCaseName)
{
@c4tachan
c4tachan / Original
Created June 12, 2015 18:38
Original Algorithm
if (eLoginMode == LoginContinueCase)
const vector<CaseItem> vCases = GetContinuableCases();
if (Row < vCases.size())
{
if (LoginDialog::GetSelectedCase() == vCases[Row].strCaseName)
{
LoginDialog::SelectCase(EMPTY_STRING);
}
else
{
typedef struct hasSmrtPtr
{
vector<unique_pointer<int>> unq;
} hsSmrtPtr;
hsSmrtPtr g;
void smrtPtrScope(int len)
{
for(int i = 0; i < len; ++i)
@c4tachan
c4tachan / TestLanguageGenerator.cpp
Created October 9, 2014 13:04
Get a string from the console, convert the characters to "funny" characters, and return the "translated" string. This will help test the language translation system I use at work.
// TestLanguageGenerator.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <string>
#include <cwctype>
#include <clocale>
std::wstring translatedString;
@c4tachan
c4tachan / DeviceOrientationReader.js
Last active November 20, 2019 19:08
Implementation of reading the orientation of a device using JavaScript. Eventually, this will also include code to open a web socket and transmit that information to a server. This script was shamelessly stolen and modified from the source code of http://www.html5rocks.com/en/tutorials/device/orientation/deviceorientationsample.html
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript">
init();
var count = 0;
function init()
{
@c4tachan
c4tachan / Why we use goto
Created September 9, 2014 16:57
This Gist demonstrates why my new employer has chosen to permit the use of goto statements in the code they produce. I won't claim that everything in this gist is correct syntactically or logically, but hopefully it is accurate enough to demonstrate the (admittedly special case) benefit to debugging and reading of this code provided by the use o…
// Make a note of how many return statements there are!
// Also note that there is a memory leak generated because I don't always delete myObj
void lotsoReturns(int randomlyGennerated)
{
someObject * myObj = new someObject();
switch(randomlyGennerated / 100)
{
case 1:
switch((randomlyGennerated % 100) / 10)
{
@c4tachan
c4tachan / ValvRef
Created December 6, 2013 21:05
I'm trying to figure out pass by reference in C#.
class foo
{
int a;
int b;
int c;
GenericLargeExistingClass glec = new GenericLargeExistingClass();
foo()
{
@c4tachan
c4tachan / nestedForeachContinue
Last active December 30, 2015 03:59
I recently saw this algorithm in a coworker's code, and I was confused by how he used the continue statement on line 18. It seems to me that the continue will only cause the inner foreach loop to continue and not the outer loop which is what I believe was the intention.
foo[5] a = { 1, 2, 3, 4, 5 }; //foo is a type
foo[3] b = { 1, 2, 3 };
List<foo> unMatched = new List<foo>();
foreach (foo c in a)
{
bool wasMatched = false;