This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <array> | |
#include <sstream> | |
#include <iostream> | |
#include <iomanip> | |
#include <functional> | |
#include <cassert> | |
#include "memory_content.hpp" | |
// opcode | instruction | operands (mod 0) | operands (mod 1) | |
// -------+-------------+------------------+----------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct handle_deleter_t | |
{ | |
void operator()(HANDLE handle) { | |
if(handle != INVALID_HANDLE_VALUE) | |
CloseHandle(handle); | |
} | |
}; | |
void foo() | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* RULES | |
* 1. Prefer using is_initialized() for checking the contents if the | |
* value is not assigned to a boost::optional right before | |
* 2. Prefer get() over 'operator ->', to make visible what's happening | |
* 3. Use get_value_or() if applicable, this makes the control flow less complex | |
* 4. Optionally prefix variable with 'opt' or postfix with 'Optional' | |
* | |
* DOCS http://www.boost.org/doc/libs/1_55_0/libs/optional/doc/html/index.html | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module LongestCommonSubstring | |
let get (strings:seq<string>) = | |
let first' = strings |> Seq.tryFind (fun _ -> true) | |
let isWhiteSpace = System.String.IsNullOrWhiteSpace | |
let mapper substringLength (first:string) currentStrings offset = | |
if substringLength + offset < first.Length then | |
let currentSubstring = first.Substring(offset, substringLength) | |
if not(isWhiteSpace(currentSubstring)) && |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// FSharp translation of the Cohen–Sutherland 2D line clipping algorithm | |
/// http://en.wikipedia.org/wiki/Cohen%E2%80%93Sutherland_algorithm | |
/// | |
/// Implemented in purely functional form which means there are no mutable variables. | |
/// No guarantees are given on the performance or reliability, it's not | |
/// thoroughly tested so feel free to submit unit tests. :-) | |
/// | |
/// Markus Lindqvist 07/2012 | |
module CohenSutherland |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Implementation for GCHQ Challenge stage 2 virtual machine, in F# | |
/// From: http://canyoucrackit.co.uk/codeexplained.asp?v=1 | |
/// This is a JavaScript programming challenge, with a cyber security angle. To solve | |
/// this stage an implementation of a simple virtual processor is required. Some notes | |
/// on the architecture are provided along with a block of data that can be analysed. | |
/// Solving this stage will reveal the final stage of the challenge. | |
/// The challenge originally suggested writing a virtual machine for the given instructions in JavaScript, but I decided to go with F# | |
/// See original 15b436de1f9107f3778aad525e5d0b20.js at http://pastebin.com/p5AHwPra | |
/// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Read more about EOQ from http://en.wikipedia.org/wiki/Economic_order_quantity | |
/// Using functional approach to handle user interface interaction using reactive programming style. | |
/// Any comments and improvements welcome :-) | |
/// -Markus L/2011 | |
#if INTERACTIVE | |
#r "PresentationCore" | |
#r "PresentationFramework" | |
#r "System.Xaml" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#load "FsharpChart.fsx" | |
open MSDN.FSharp.Charting | |
let castValue (value : 'TSource) :'TResult = | |
let an = new System.Reflection.AssemblyName("CastUtil") | |
let ab = System.AppDomain.CurrentDomain.DefineDynamicAssembly(an, System.Reflection.Emit.AssemblyBuilderAccess.RunAndSave) | |
let mb = ab.DefineDynamicModule(an.Name) | |
let tb = mb.DefineType("CastUtil", System.Reflection.TypeAttributes.Public ||| System.Reflection.TypeAttributes.Class) | |
let fb = tb.DefineMethod("Read", System.Reflection.MethodAttributes.Public ||| System.Reflection.MethodAttributes.Static, typeof<'TResult>, ([|typeof<'TSource>|])) | |
let ig = fb.GetILGenerator() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// FSharp (F#) interpreter for brainfuck programming language | |
// Read more from | |
// - http://www.muppetlabs.com/~breadbox/bf/ | |
// - http://fsharp.net | |
// (c) 2011 Markus Lindqvist | |
module brainfuck | |
open System | |
let brainfuckMemorySize = 30000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <fstream> | |
#include <vector> | |
#include <sstream> | |
#include <algorithm> | |
#include <iostream> | |
#include <stdexcept> | |
#include <array> | |
std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems) { |