Skip to content

Instantly share code, notes, and snippets.

View joshpeterson's full-sized avatar

Joshua Peterson joshpeterson

View GitHub Profile
@joshpeterson
joshpeterson / DistCheckConst.md
Last active September 13, 2019 12:53
C++ code generated by IL2CPP and assembly code generated by MSVC for the DistCheckConst method (https://twitter.com/FreyaHolmer/status/1172471972892164098?s=20)

Generated C++ code for C::DistCheckConst

// System.Boolean C::DistCheckConst()
IL2CPP_EXTERN_C IL2CPP_METHOD_ATTR bool C_DistCheckConst_mE028E74C6665A48D9D1B9C061F10109CD313210D (C_tFBD32447759BBF3C449FEE7F72BC83164EA8A0C1 * __this, const RuntimeMethod* method)
{
        {
                // return myVector.sqrMagnitude < DIST_THRESH * DIST_THRESH;
                Vector3_tC13D5D43F600A728C1B38EDB3380DD9C9CFB0EBA * L_0 = __this->get_myVector_0();
                NullCheck(L_0);
                float L_1 = Vector3_get_sqrMagnitude_m78EFA8AF97A15A392EA1950A9324AE58EC2D6149(L_0, /*hidden argument*/NULL);
@joshpeterson
joshpeterson / DistCheck.md
Last active September 13, 2019 12:53
C++ code generated by IL2CPP and assembly code generated by MSVC for the DistCheck method (https://twitter.com/FreyaHolmer/status/1172471972892164098?s=20)

Generated C++ code for C::DistCheck

// System.Boolean C::DistCheck()
IL2CPP_EXTERN_C IL2CPP_METHOD_ATTR bool C_DistCheck_mF7A77109E1F011D96B9565C83F91CE5A3521D8E8 (C_tFBD32447759BBF3C449FEE7F72BC83164EA8A0C1 * __this, const RuntimeMethod* method)
{
        float V_0 = 0.0f;
        {
                // float distThresh = 2;
                V_0 = (2.0f);
                // return myVector.sqrMagnitude < distThresh * distThresh;
@joshpeterson
joshpeterson / test.cpp
Created February 8, 2017 11:50
Example code using multi_span for argv with the GSL headers prepended
#ifndef GSL_MULTI_SPAN_H
#define GSL_MULTI_SPAN_H
#ifndef GSL_CONTRACTS_H
#define GSL_CONTRACTS_H
#include <exception>
#include <stdexcept>
#if !(defined(GSL_THROW_ON_CONTRACT_VIOLATION) ^ defined(GSL_TERMINATE_ON_CONTRACT_VIOLATION) ^ \
@joshpeterson
joshpeterson / newcs.rb
Last active December 13, 2015 12:48
A Ruby script to generate a new C# class and test based on a namespace and a class name
#!/usr/bin/env ruby
templateCs = %{namespace <namespace>
{
public class <class>
{
}
}
}
@joshpeterson
joshpeterson / NumericalTypesCheatSheet.cs
Last active August 29, 2015 14:05
A bit of code to print the names and sizes of all C# numeric types.
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SqlServer.Server;
namespace ScratchCSharpProject
{
class Program
{
struct TypeData
@joshpeterson
joshpeterson / LockingQueue.cpp
Created April 25, 2014 10:53
An example of a simple queue class with internal locking for a blog post.
#include <deque>
#include <mutex>
#include <cassert>
template<typename T, typename MutexType = std::mutex>
class queue
{
public:
void enqueue(T value) {
std::lock_guard<MutexType> guard(mutex_);
@joshpeterson
joshpeterson / disk_test_2.cpp
Created February 27, 2014 11:21
A small utility to test disk write performance
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <vector>
#include <unistd.h>
#include <fcntl.h>
int main(int argc, char* argv[])
{
@joshpeterson
joshpeterson / github.css
Last active January 3, 2016 16:29
This is a short Ruby script to format a markdown file with Github flavored markdown, render it to HTML, and dump it to standard output. It is useful for printing markdown files. The github.css file is copied from here: https://gist.github.com/andyferra/2554919
body {
font-family: Helvetica, arial, sans-serif;
font-size: 14px;
line-height: 1.6;
padding-top: 10px;
padding-bottom: 10px;
background-color: white;
padding: 30px; }
body > *:first-child {
@joshpeterson
joshpeterson / guard.cpp
Created January 1, 2014 03:28
This is a test of an RAII thread guard, as shown in Concurrency in Action, listing 2.6.
#include <iostream>
#include <thread>
#include <stdexcept>
class guard {
std::thread t_;
public:
explicit guard(std::thread t) :
t_(std::move(t)){
if (!t_.joinable())
@joshpeterson
joshpeterson / exit_condition.cpp
Last active December 28, 2015 12:19
This is test code to use an std::condition_variable to signal a thread to exit.
#include <iostream>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <chrono>
std::mutex m;
std::condition_variable exit_condition;
bool should_exit;