Skip to content

Instantly share code, notes, and snippets.

View dirocco's full-sized avatar

Steven Di Rocco dirocco

View GitHub Profile
@dirocco
dirocco / oldman_reflections.cpp
Created April 20, 2023 22:31
An example of how to draw reflection in OpenGL from 16 years ago
void Viewer::do_reflections()
{
if (Settings::reflections)
{
Settings::cel_reflection = true;
glColorMask(0, 0, 0, 0);
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_ALWAYS, 1, 1);
#!/bin/bash
BACKUP_BUCKET=s3backupbucketname
pushd /mnt/backup/gphotos
/home/ubuntu/.local/bin/gphotos-sync/gphotos-sync .
tar cf - . | aws s3 cp --storage-class=DEEP_ARCHIVE - s3://$BACKUP_BUCKET/gphoto.tar
popd
template<typename E>
constexpr typename std::underlying_type<E>::type toBase(E e) noexcept
{
return static_cast<typename std::underlying_type<E>::type>(e);
}
#include <x86intrin.h>
#include <stdint.h>
constexpr bool is_powerof2(int v) {
return v && ((v & (v - 1)) == 0);
}
template<typename Key, size_t NumElements>
struct aesHash
{
#pragma once
/* Let's you map a non-contiguous enum class to a contiguously packed array for better performance
ie:
enum class ABC { A = 'A', B = 'B', C = 'C', D = 'D' };
typedef PackedEnum<ABC::B, ABC::A, ABC::C> PackedABC;
At compile time:
PackedABC::list wil be { ABC::B, ABC::A, ABC::C }
#!/usr/bin/env python3
print('''
#pragma once
#include <type_traits>
#include <tuple>
// Converts POD struct to std::tuple
// Autogenerated by totuple.py
@dirocco
dirocco / gist:5778966
Created June 14, 2013 02:08
Fixed-size and almost wait-free lockless queue implementation that is simple enough to debug quickly. (Uses OS X atomic/malloc primitives)
/*
Fixed-size, nearly wait-free lockless queue implementation that is simple enough to debug quickly.
Similar to the Array-based Queue-lock on p150 of The Art of Multiprocessor Programming but with pointers
in the queue instead of flags.
Implementation:
Before doing anything, both reader and writer claim their index using atomic add/subtract. This
allows multiple readers and writers to not clobber eachother.
@dirocco
dirocco / gist:5778948
Created June 14, 2013 02:04
Quickly gives you the weather for the next hour and day using hardcoded Lat/Long and DarkSkies API key.
<html>
<head>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
var latAndLong = '40.736901,-73.990692'
function getJSONP(url, success) {
var ud = '_' + +new Date,
script = document.createElement('script'),
@dirocco
dirocco / gist:5677464
Created May 30, 2013 12:23
Awful snippet for calling awful PogoAutoSweep while still being thread safe with every other function in the program.
#include <pgobootrun.h>
#include <TlHelp32.h>
#pragma comment(lib, "pgobootrun.lib")
//static int threadcount = 0;
inline void sweep()
{
if( getenv("PGOSWEEP") ) // can't #define this or it will undo PGO update