This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Compute the Levenshtein distance between `Array`-like sequences `a` and `b`; the minimum number of | |
// single-element insertions, deletions and substitutions necessary to transform `a` into `b`. | |
// Strict equality semantics are used by default to compare sequence elements; a function `equal` can | |
// optionally be provided to alter this behavior. | |
function levenshtein(a, b, equal) { | |
// `aii` and `bii` are used to track `ai - 1` and `bi - 1` more or less free of charge. | |
// `d0` and `d1` are used to store the 'previous' and 'current' rows respectively. | |
// `x`, `y` and `z` are used to permit the implementation of an optimized `min` using a ternary expression. | |
var ai, aii, ae, al, bi, bii, bl, d0, d1, dd, x, y, z; | |
if(a === b) return 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Web; | |
namespace SslRedirection { | |
public class SslRedirectionHttpHandler : IHttpHandler { | |
public bool IsReusable { get { return true; } } | |
public void ProcessRequest(HttpContext context) { | |
if ("GET".Equals(context.Request.HttpMethod, StringComparison.Ordinal)) { | |
context.Response.StatusCode = 301; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Text; | |
using System.Linq; | |
public static class StringLiteralEncoding { | |
private static readonly char[] HEX_DIGIT_LOWER = "0123456789abcdef".ToCharArray(); | |
private static readonly char[] LITERALENCODE_ESCAPE_CHARS; | |
static StringLiteralEncoding() { | |
// Per http://msdn.microsoft.com/en-us/library/h21280bw.aspx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static string RemoveDiacritics(this string str) { | |
var formD = str.Normalize(NormalizationForm.FormD); | |
var bp = 0; | |
var buffer = new char[formD.Length]; | |
for(var i = 0; i < formD.Length; i++) | |
if(UnicodeCategory.NonSpacingMark != CharUnicodeInfo.GetUnicodeCategory(formD[i])) | |
buffer[bp++] = formD[i]; | |
return new string(buffer, 0, bp); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object LiteralEncoding { | |
private val Hex = "0123456789abcdef".toArray | |
private val StringEscapes = { | |
val escapes = Map( | |
'\b' -> 'b', // backspace | |
'\t' -> 't', // tab | |
'\n' -> 'n', // linefeed | |
'\f' -> 'f', // formfeed | |
'\r' -> 'r', // carriage return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Animal | |
class Cat extends Animal | |
abstract class Whisperer[-A <: Animal] extends (A => Unit) | |
object Whisperer { | |
implicit def animalWhisperer: Whisperer[Animal] = | |
new Whisperer[Animal] { def apply(a: Animal): Unit = { println("animal") } } | |
implicit def catWhisperer: Whisperer[Cat] = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait JsonDialect { dialect => | |
import scala.language.implicitConversions | |
type JValue | |
type JArray <: JValue | |
type JBoolean <: JValue | |
type JNull <: JValue | |
type JNumber <: JValue | |
type JObject <: JValue | |
type JString <: JValue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#========== | |
# Uses the GIMP to set the specified DPI value on the specified image without | |
# changing the dimensions of the image. | |
# | |
# This is useful as Inkscape provides no means of changing the DPI of an exported | |
# image without altering its pixel count, and also defaults to 90dpi. | |
# | |
# Note that gimp-console must be in your $PATH. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
while true; do | |
ls /run/user/$UID/gvfs/* &> /dev/null | |
sleep 15 | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
ldapsearch "$@" | sed -n '1h; 1!H; ${ g; s/\r\?\n //g; p }' |
OlderNewer