Skip to content

Instantly share code, notes, and snippets.

@ldematte
ldematte / Ref.java
Created September 6, 2016 13:07
"Reference" class for manual closures in Java (useful in lamdbas)
private static class Ref<T> {
private T value;
public Ref(T value) {this.value = value;}
public static<U> Ref<U> of(U t) { return new Ref<U>(t); }
public T getValue() { return value; }
public void setValue(T value) { this.value = value; }
}
// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.33440
// Copyright (c) Microsoft Corporation. All rights reserved.
// Metadata version: v4.0.30319
.assembly extern mscorlib
{
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.33440
// Copyright (c) Microsoft Corporation. All rights reserved.
// Metadata version: v4.0.30319
.assembly extern mscorlib
{
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
@ldematte
ldematte / datepicker
Created April 6, 2015 14:39
Hacking datepicker to get notification of any change to the underlying date object
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Datepicker - Select on every date change</title>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/themes/smoothness/jquery-ui.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.js"></script>
<script>
$(function() {
@ldematte
ldematte / HatsController.cs
Last active August 29, 2015 14:07
Hats! :) With local caching in storage, click to select, drag to adjust it over your avatar and.. a couple of "face detection" ideas: HUE-based image partitioning and feature detection through edge filters (Sobel). HTML and CSS are non-existent, just the bare minimum to make it work, and the Controller is ... fake!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace SimpleHats.Controllers {
public class HomeController : Controller {
public ActionResult Index() {
return View();
@ldematte
ldematte / MyAsyncMonadTest.cs
Created March 22, 2013 20:42
Testing async (continuation) monads in C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Linq.Expressions;
namespace Dematte.Tests
{
class Program
@ldematte
ldematte / MyAsyncMonad.cs
Last active December 15, 2015 07:38
Testing different solutions for async (continuation) Monads in C#, including using LINQ Syntax
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Dematte.Tests
{
// Reproduce the Async/Workflow pattern from F#
// using C# classes, complete with a continuation monad.
// For learning purposes only
@ldematte
ldematte / Division.cpp
Created January 19, 2013 18:41
Sequential algorithm for integer subdivision, implemented at bit level. Part of the material for a course on Computer Architecture.
#include <bitset>
using std::bitset;
bitset<32> division(bitset<32> dividend, bitset<32> divisor)
{
bitset<32> result(0);
bitset<32> now(0);
@ldematte
ldematte / FloatMath.cpp
Created January 19, 2013 18:39
Floating-point emulation and mathematics in C++, using integers ant bitsets. Part of the material for an introductory course on Computer Architecture
#include <iostream>
#include <bitset>
#include <stdio.h>
#include <math.h>
using std::bitset;
using std::cout;
using std::endl;