Skip to content

Instantly share code, notes, and snippets.

@lnicola
lnicola / correl.py
Created June 20, 2014 15:42
numpy cross-correlation
import numpy
import sys
numpy.seterr(all='print')
original = numpy.fromfile(sys.argv[1], '<h').astype(int)
delayed = numpy.fromfile(sys.argv[2], '<h').astype(int)
original_len = len(original)
delayed_len = len(delayed)
@lnicola
lnicola / Makefile
Created June 20, 2014 15:44
small ARM Linux executable
all:
gcc -pipe -nostdlib -nostartfiles -Qn -Wl,--build-id=none -o tiny-hello tiny-hello.s
strip -R .ARM.attributes tiny-hello
! ./tiny-hello
ls -l tiny-hello
clean:
rm -f tiny-hello
@lnicola
lnicola / ComparerBuilder.cs
Created June 20, 2014 15:46
Runtime code generation with expression trees (object comparer)
using System;
using System.Linq;
using System.Linq.Expressions;
namespace ConsoleApplication1
{
public class Foo
{
public int A { get; set; }
public Bar Bar;
@lnicola
lnicola / GroupAdjacentBy.cs
Created June 20, 2014 15:48
Not really working LINQ GroupBy() implementation for sorted inputs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication4
{
public class EnumeratorBox<T>
{
@lnicola
lnicola / HttpClient.java
Created June 20, 2014 15:50
small Java HTTP client
package httpclient;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
public class HttpClient {
public static void main(String[] args) {
if (args.length != 1) {
System.err.println("Usage: httpclient <url>");
@lnicola
lnicola / list.sh
Created June 20, 2014 15:51
something with iconv and sed
#!/bin/bash
rm -f programe.csv
for i in *.txt;
do iconv -f UTF-16 -t UTF-8 $i | tail -n +2 | sort | sed 's/\s\{2,\}\([0-9.]\+\)/,\1/g' | sed "s/^/$i,/g" >> programe.csv;
done
@lnicola
lnicola / Mergesort.cpp
Created June 20, 2014 15:52
mergesort
#include <stdio.h>
int v[10];
void mergesort(int l, int r)
{
if (r > l)
{
int aux[10], m = (l + r) / 2, i = l, j = m + 1, k = 0;
mergesort(l, m);
@lnicola
lnicola / any.cpp
Created June 20, 2014 15:58
boost::any-like class
#include <iostream>
#include <memory>
#include <utility>
#ifndef _MSC_VER
namespace std
{
template<class _Ty,
class... _Types> inline
typename enable_if<!is_array<_Ty>::value,
@lnicola
lnicola / AuthorizationModule.cs
Created June 20, 2014 15:59
ASP .NET authorization module that removes inaccessible controls from the rendered page
using System;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace AuthorizationTest.HttpModules
{
public class AuthorizationModule : IHttpModule
{
@lnicola
lnicola / datapipe.c
Created June 20, 2014 16:00
datapipe.c version that saves the data to a file
/*
* Datapipe - Create a listen socket to pipe connections to another
* machine/port. 'localport' accepts connections on the machine running
* datapipe, which will connect to 'remoteport' on 'remotehost'.
* It will fork itself into the background on non-Windows machines.
*
* This implementation of the traditional "datapipe" does not depend on
* forking to handle multiple simultaneous clients, and instead is able
* to do all processing from within a single process, making it ideal
* for low-memory environments. The elimination of the fork also