Skip to content

Instantly share code, notes, and snippets.

View mfukar's full-sized avatar

Michael Foukarakis mfukar

View GitHub Profile
@mfukar
mfukar / mach_msg_hook.c
Last active March 21, 2018 03:34
Hook mach_msg and print message contents
/*
* View the contents of messages sent/received via `mach_msg`.
*
* Compile with:
* clang -arch x86_64 -arch i386 -Wall -o mach_msg_hook.dylib -dynamiclib mach_msg_hook.c
*
* and run as:
* DYLD_FORCE_FLAT_NAMESPACE=1 DYLD_INSERT_LIBRARIES=mach_msg_hook.dylib [COMMAND]
*
* Have fun.
@mfukar
mfukar / memoizer.cpp
Created November 17, 2015 09:44
A generic memoizer class for C++14 functions
/**
* A memoizer (Y-combinator), with a cache on operator().
*
* The type of the function that can be memoized is (((Args...)->R), Args...) -> R, which
* makes the memoizer of type ( (((Args...) -> R), Args...) -> R ) -> ((Args...) -> R).
*
* WARNING: If the memoized function modifies its arguments, the results will not be
* cached correctly.
*/
@mfukar
mfukar / idontknow.c
Created May 13, 2015 09:54
Just some random interview question + solution, I don't even remember from where any more
/**
* The array contains a set of unsorted numbers. All numbers appear an even number of
* times. The exception is two numbers, call them M and N, which appear an odd number of
* times. Find M and N.
*
* This solution is O(n), where n is the size of the array. It requires two passes over
* the array.
*
* The generalised version of this problem (N elements, one number repeats K times) can
* be reduced to solving the linear system of equations:
@mfukar
mfukar / epic_fail_3.java
Created November 20, 2014 10:30
How not to filter untrusted input.
private InputFilter getCharactersLimited() {
// Limit characters input
InputFilter[] filters = new InputFilter[1];
filters[0] = new InputFilter(){
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
if (end > start) {
char[] acceptedChars = new char[]{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
#!/usr/bin/env python
# Useful common polynomials:
#POLY = 0x82F63B78 # CRC-32C (Castagnoli)
#POLY = 0xEB31D82E # CRC-32K (Koopman)
#POLY = 0xD5828281 # CRC-32Q
class CRCForger():
def __init__(self, *args, **kwargs):
function Send-NetworkData {
[CmdletBinding()]
param (
[Parameter(Mandatory)]
[string]
$Computer,
[Parameter(Mandatory)]
[ValidateRange(1, 65535)]
[Int16]
@mfukar
mfukar / lisp.cpp
Last active August 29, 2015 14:07
C++ generic lambdas turn it into Lisp!
/**
* Compile with GCC 4.9:
* g++ -std=c++1y lisp.cpp
*/
#include <iostream>
#include <stdio.h>
auto terminal = [] (auto stream) {
return [=] (auto func) {
return func (stream);
@mfukar
mfukar / epic_fail_2.cpp
Created March 1, 2014 18:25
This is how you don't code game rules.
#include <iostream>
enum stuff {
laugh,
strike,
slap,
};
struct true_ {};
struct false_ {};
@mfukar
mfukar / dotd.py
Last active December 30, 2016 08:22
Log analyser for Dawn of the Dragons raids. Overengineered as fuck.
#!/usr/bin/env python
# @file dotd.py
# @author Michael Foukarakis
# @version 0.6
# @date Created: Sun Aug 25, 2013 09:57 BST
# Last Update: Fri Dec 30, 2016 10:21 EET
#------------------------------------------------------------------------
# Description: Log analyser for Dawn of the Dragons raids.
#------------------------------------------------------------------------
# History: None yet
@mfukar
mfukar / ants.clj
Created February 13, 2014 12:22 — forked from michiakig/ants.clj
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Ant sim ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Copyright (c) Rich Hickey. All rights reserved.
; The use and distribution terms for this software are covered by the
; Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
; which can be found in the file CPL.TXT at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.
;dimensions of square world