Skip to content

Instantly share code, notes, and snippets.

@kflu
kflu / LinqSlowerThanLoop.cs
Last active August 29, 2015 14:02
This test shows you that Linq to object is significantly slower than traditional for loop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
using System.Linq.Expressions;
using System.Reflection.Emit;
using System.IO;
using System.Diagnostics;
@kflu
kflu / spinlock.cs
Created July 9, 2014 21:21
Compares spinlock and regular lock to understand under which circumstances does spinlock provides perf benefit.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace ConsoleApplication27
{
@kflu
kflu / perf.cs
Created August 30, 2014 17:07
Performance comparison: Node, Python, C#
using System;
using System.Diagnostics;
namespace ConsoleApplication13
{
class Program
{
static void Main(string[] args)
{
int N = 10000000;
@kflu
kflu / p1.js
Created September 5, 2014 19:03
var i = 0;
while (true) {
i += 1;
process.stdout.write("" + i + " ");
}
@kflu
kflu / livestream
Last active August 29, 2015 14:06 — forked from deandob/livestream
// Live video stream management for HTML5 video. Uses FFMPEG to connect to H.264 camera stream,
// Camera stream is remuxed to a MP4 stream for HTML5 video compatibility and segments are recorded for later playback
var liveStream = function (req, resp) { // handle each client request by instantiating a new FFMPEG instance
// For live streaming, create a fragmented MP4 file with empty moov (no seeking possible).
var reqUrl = url.parse(req.url, true)
var cameraName = typeof reqUrl.pathname === "string" ? reqUrl.pathname.substring(1) : undefined;
if (cameraName) {
try {
cameraName = decodeURIComponent(cameraName);
@kflu
kflu / .ctags
Last active August 29, 2015 14:07 — forked from jesstelford/.ctags
--langdef=coffee
--langmap=coffee:.coffee
--regex-coffee=/(^|=[ \t])*class ([A-Za-z_][A-Za-z0-9_]+\.)*([A-Za-z_][A-Za-z0-9_]+)( extends .+)?$/\3/c,class/
--regex-coffee=/^[ \t]*(module\.)?(exports\.)?@?(([A-Za-z][A-Za-z0-9_.]*)+):.*[-=]>.*$/\3/m,method/
--regex-coffee=/^[ \t]*(module\.)?(exports\.)?(([A-Za-z][A-Za-z0-9_.]*)+)[ \t]*=.*[-=]>.*$/\3/f,function/
--regex-coffee=/^[ \t]*(([A-Za-z][A-Za-z0-9_.]*)+)[ \t]*=[^->\n]*$/\1/v,variable/
--regex-coffee=/^[ \t]*@(([A-Za-z][A-Za-z0-9_.]*)+)[ \t]*=[^->\n]*$/\1/f,field/
--regex-coffee=/^[ \t]*@(([A-Za-z][A-Za-z0-9_.]*)+):[^->\n]*$/\1/f,static field/
--regex-coffee=/^[ \t]*(([A-Za-z][A-Za-z0-9_.]*)+):[^->\n]*$/\1/f,field/
--regex-coffee=/((constructor|initialize):[ \t]*\()@(([A-Za-z][A-Za-z0-9_.]*)+)([ \t]*=[ \t]*[^,)]+)?/\3/f,field/
@kflu
kflu / EulerProb1.ls
Last active August 29, 2015 14:17
LiveScript implementation of Project Euler Problems
[0 to 1000]
|> filter (-> it % 3 == 0 or it % 5 == 0)
|> foldr1 (+)
@kflu
kflu / readme.md
Last active August 29, 2015 14:26

hello1

@kflu
kflu / wrapper.bat
Last active September 4, 2015 18:26 — forked from jpoehls/wrapper.bat
Batch file wrapper for a PowerShell script. Wraps execution of a PowerShell script inside a Windows batch file.
@echo off
:: Execute the PS1 file with the same name as this batch file.
set filename=%~d0%~p0%~n0.ps1
if exist "%filename%" (
PowerShell.exe -NoProfile -NonInteractive -NoLogo -ExecutionPolicy Unrestricted -Command "& '%filename%'"
:: Collect the exit code from the PowerShell script.
set err=%errorlevel%
@kflu
kflu / findmajority.py
Created March 8, 2012 06:34
This code implements the problem of "Selecting M from N elements that appear more than M/N times". For more details, see http://wp.me/pL72j-5E
import unittest
def FindMajority(array, M):
'''Find elements that occurs more than(>) N/M times in the array of size N
array: the array that is to be scanned through for elements returns a
dictionary with keys set to elements that occur more than(>) N/M times in
the array of size N. The key's values are their number of occurrences.
'''