Skip to content

Instantly share code, notes, and snippets.

View jskripsky's full-sized avatar

Juraj Skripsky jskripsky

  • Zurich, Switzerland
View GitHub Profile
#r "WebDriver.dll"
open OpenQA.Selenium
open OpenQA.Selenium.Firefox
open OpenQA.Selenium.Chrome
use driver = new FirefoxDriver ()
let nav = driver.Navigate ()
nav.GoToUrl "http://www.hsr.ch/"
@jskripsky
jskripsky / ApacheLogExtraction.fs
Created February 22, 2011 13:48
Extract columns from Apache access logs
open System
open System.Text.RegularExpressions
let separator = Regex(@" (?=(?:[^\""]*\""[^\""]*\"")*(?![^\""]*\""))")
let split s = separator.Split s
let matches = Regex(@"([^\s""\[]\S*|"".*?""|\[.*?\])").Matches
let value (m: Match) = m.Value
let trim (separator: char) (s: string) = s.Trim separator;;
let split s = matches s |> Seq.cast |> Seq.map (value >> trim '"') |> Seq.toList
@jskripsky
jskripsky / webtracer.fs
Created February 22, 2011 22:38
Apache log web tracer
(* Apache log web tracer *)
type Hit = Time * Url * Url; // Url, UrlReferrer
type Visit = list of Hit
type Entry = IP * Agent * Visit
@jskripsky
jskripsky / sumOfSquares.fs
Created March 10, 2011 16:21
Sum of Squares in F#: imperative, pure functional, native
let sqr x = x * x
let sumOfSquaresI nums =
let mutable acc = 0.0
for x in nums do
acc <- acc + sqr x
acc
let rec sumOfSquaresF nums =
match nums with
@jskripsky
jskripsky / bluefish-replace-regex.txt
Created April 11, 2011 13:34
Replace with regex in Bluefish
^Funktion: (.*?)\n
<function>\1</function>\n
- Regex style: PERL
- Allow escaped chars
@jskripsky
jskripsky / clean-seo-history.sh
Created July 3, 2011 20:00
Git invocations to clean up SEO report history
#!/bin/bash
git filter-branch --force --prune-empty --tree-filter "sort pageranks.txt -o pageranks.txt || true {} \;"
git filter-branch --force --prune-empty --tree-filter "find -name "*.xml" -exec sed -i -e 's/us-ascii/utf-8/' {} \;"
#if [ -e pageranks.txtx ]; then echo "ok"; fi
@jskripsky
jskripsky / GetFields.cs
Created August 12, 2011 09:58
Get all fields (following inheritance chain) using Chain<T>(Func<T, T>) extension method.
using System;
using System.Reflection;
using System.Collections.Generic;
using System.Linq;
static class Helper {
public static IEnumerable<T> Chain<T>(this T first, Func<T, T> follow) where T : class {
for (T item = first; item != null; item = follow(item))
yield return item;
}
@jskripsky
jskripsky / static_copy.sh
Created August 31, 2011 00:08
Create static website copy
#!/bin/bash
wget \
--restrict-file-names=windows \
--html-extension \
--convert-links \
--page-requisites \
--recursive \
--no-host-directories \
--exclude-directories=UserData,UserData/generated \
@jskripsky
jskripsky / mono-bug.txt
Created September 18, 2011 22:02
Possible mono bug: IList.Contains does automatic/implcit conversion between enums (or casts to int).
using System;
using System.Collections;
using System.Collections.Generic;
namespace Test {
enum Set {
One = 1,
Two = 2,
Three = 3
}
@jskripsky
jskripsky / ilist-test.aspx
Created September 19, 2011 14:41
More tests as ASP.NET script.
<script runat="server">
enum Set {
One = 1,
Two = 2
}
enum ItemOne {
One = 1
}