Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@iscgar
iscgar / Timer.cpp
Last active August 29, 2015 14:18
A simple timer wrapper for Linux intended to be consumed by a single thread with timed wait.
/**
* @file Timer.cpp
*
* A simple timer wrapper implementation for Linux (can be adjusted for other OSs easily).
*
* @author Isaac Garzon
* @since 05/04/2015
*/
#if !defined(__linux__)
@iscgar
iscgar / AbsoluteTimer.cpp
Created April 11, 2015 21:09
A simple absolute timer wrapper for Linux intended to be consumed by a single thread with timed wait.
/**
* @file AbsoluteTimer.cpp
*
* A simple absolute timer wrapper implementation for Linux (can be adjusted for other OSs easily).
*
* @author Isaac Garzon
* @since 11/04/2015
*/
#if !defined(__linux__)
@iscgar
iscgar / enum-inherit.cpp
Created August 2, 2015 20:20
"Inheritable" enums
#include <iostream>
struct BaseEnum
{
public:
operator int() const { return this->type_; }
protected:
inline BaseEnum(int type) : type_(type) {}
@iscgar
iscgar / typelist-abuse.cpp
Last active February 15, 2016 22:17
Abusing type lists for easier generic development
#include <stdio.h>
#include <string.h>
#include <ctype.h>
namespace detail
{
template<typename T>
bool detail_echo(const T *obj, const char *arg)
{
if (!obj)
@iscgar
iscgar / HyperV-off.cmd
Created August 12, 2016 10:39
Turns Hyper-V off
@echo off
if "%1" == "" (set "BCDREC={current}") else (set "BCDREC=%1")
echo Setting Hyper-V off for %BCDREC%...
bcdedit /set %BCDREC% hypervisorlaunchtype off
if errorlevel 1 (goto fail)
echo.
echo Rebooting into No Hyper-V Mode
echo ==============================
echo Press any key to restart or CTRL-C to restart manually
pause
#!/usr/bin/sudo ruby
#
# revealer.rb -- Deobfuscate GHE .rb files.
#
# This is simple:
# Every obfuscated file in the GHE VM contains the following code:
#
# > require "ruby_concealer.so"
# > __ruby_concealer__ "..."
@iscgar
iscgar / offset_of.rs
Last active October 17, 2017 04:52
Rust `offsetof` prototype (`offset_of` and `span_of`)
pub use std::mem
#[macro_export]
macro_rules! offset_of {
($sty:ty, $($field:tt)+) => ({
unsafe {
let root: $sty = $crate::mem::uninitialized();
let base = &root as *const _ as usize;
let end = &root.$($field)* as *const _ as usize;
end - base
@iscgar
iscgar / is_compatible.hpp
Created February 10, 2018 19:14
C++ Version of __builtin_types_compatible_p
#include <stddef.h>
namespace detail
{
template<class, class> struct is_compatible { enum { value = 0 }; };
template<class T> struct is_compatible<T, T> { enum { value = 1 }; };
template<class T, size_t N> struct is_compatible<T[], T[N]> { enum { value = 1 }; };
template<class T, size_t N> struct is_compatible<T[N], T[]> { enum { value = 1 }; };
@iscgar
iscgar / rustup-mirror.py
Created June 22, 2018 18:21
Quick and dirty Rust ditribution (rustup) mirror script (prints are now messed up due to added parallelism)
from __future__ import print_function
import os
import sys
import re
from datetime import datetime, timedelta
import pickle
from multiprocessing import cpu_count
from multiprocessing.dummy import Pool as ThreadPool
import toml
import requests
@iscgar
iscgar / murmur_hash3_constexpr.cpp
Created July 6, 2018 12:18
A C++11 constexpr implementation of 32-bit MurmurHash3
#include <stddef.h>
#include <stdint.h>
#include <limits>
#include <type_traits>
namespace detail
{
template<size_t R, class T>
static inline constexpr T rotl(const T v)
{