Skip to content

Instantly share code, notes, and snippets.

@heedley
heedley / cleanup-jruby-tmp.bat
Created May 18, 2015 22:39
Clean up after JRuby on Winblowz server ( don't ask me... 0_o )
del %USERPROFILE%\AppData\Local\Temp\sqlite*.dll
del %USERPROFILE%\AppData\Local\Temp\jffi*.tmp
for /f %%a IN ('dir /b %USERPROFILE%\AppData\Local\Temp\jruby*extract') do call superdeltree.bat %USERPROFILE%\AppData\Local\Temp\%%a
@heedley
heedley / superdeltree.bat
Created May 18, 2015 22:15
Winblowz: Delete directory structures that are super deep
@echo off
echo "Removing: %*"
move %* C:\TEMP\%~nx1
md C:\TEMP\new-%~nx1
robocopy "C:\TEMP\new-%~nx1" C:\TEMP\%~nx1 /MIR
echo "C:\TEMP\%~nx1"
rd /q C:\TEMP\%~nx1
echo "C:\TEMP\new-%~nx1"
rd /q C:\TEMP\new-%~nx1
@heedley
heedley / ruby-benchmarks.bat.sh
Created June 26, 2012 21:41
Ruby benchmarks
# benchmark code @ https://raw.github.com/jruby/jruby/master/bench/bench_red_black.rb
#ruby 1.9.3p125 (2012-02-16) [i386-mingw32]
=============================================================================================================================================
C:\Users\Hedley Robertson\Projects\NetsuiteQueue>J:\Ruby193\bin\ruby.exe "C:\Users\Hedley Robertson\Desktop\bench_red_black.rb"
4.978284
GC.count = 7
4.814275
GC.count = 9
5.117292
GC.count = 11
@heedley
heedley / ReaderWriterLock.cs
Created March 15, 2011 20:07
ReaderWriterLock.cs
// This example shows a ReaderWriterLock protecting a shared
// resource that is read concurrently and written exclusively
// by multiple threads.
// The complete code is located in the ReaderWriterLock
// class topic.
using System;
using System.Threading;
public class Test
@heedley
heedley / Map operation for schedule type.fs
Created August 11, 2010 20:21
Map operation for schedule type in F#
let mapSchedule f sch =
match sch with
| Never -> Never // Unscheduled events remain unscheduled
| Once(dt) -> Once(f(dt)) // Reschedule event occurring once
| Repeatedly(dt, ts) -> Repeatedly(f(dt), ts) // Reschedule repeated event
;;
val mapSchedule : (DateTime -> DateTime) -> Schedule -> Schedule
(*
If you look at the type, you can see that the first parameter is a function
@heedley
heedley / Higher order functions for working with tuples.fs
Created August 11, 2010 18:26
Higher order functions for working with tuples in F#
// Higher order functions for working with tuples
let mapFirst f (a, b) = (f(a), b)
(*
val mapFirst : ('a -> 'b) -> 'a * 'c -> 'b * 'c
- a generic function and it has three type parameters:
- It takes a function as the first parameter:
('a -> 'b)
(*
The pipelining operator (|>)
allows you to write the first argument for a function on the left
side; that is, before the function name itself.
*)
List.hd(List.rev [1 .. 5])
@heedley
heedley / Working with strings using extension methods.cs
Created August 11, 2010 17:47
Working with strings using extension methods in c#
/* Working with strings using extension methods (C#)
- 'this' keyword precedes the first parameter
- Using standard static method calls
*/
public static string AddLine(this string str, string next) {
return str + "\n>>" + next;
}
// Concatenate strings using extension method
@heedley
heedley / Working with strings using custom operator.fs
Created August 11, 2010 17:43
Working with strings using custom operator in f#
// Define Operator "+>" for concatenating strings in a special way
let (+>) a b = a + "\n>>" + b;;
// val ( +> ) : string -> string -> string
(* Test the function:
> printfn "%s" ("Hello world!" +>
"How are you today?" +>
"I'm fine!");;
@heedley
heedley / Generic Functions.fs
Created August 11, 2010 17:28
Generic Functions in f# notes
// val condPrint : 'a -> ('a -> bool) -> ('a -> string) -> unit
// function that takes three params and returns nothing.
// param1: 'a => a generic generalized (untyped) value
// param2: ('a -> bool) => a function taking 1 param as a generic generalized (untyped) value abd returning a bool
// param3: ('a -> string) => a function taking 1 param as a generic generalized (untyped) value and returning a string
let condPrint value test format =
if (test(value)) then printfn "%s" (format(value))
// Test the function: