Skip to content

Instantly share code, notes, and snippets.

View SamirTalwar's full-sized avatar
🦖
Hunting for bugs.

Samir Talwar SamirTalwar

🦖
Hunting for bugs.
View GitHub Profile
@SamirTalwar
SamirTalwar / fizzbuzz.fs
Created April 21, 2015 18:42
FizzBuzz in F# with NUnit
module FizzBuzz
module Prod =
let fizzBuzz input =
match (input % 3, input % 5) with
| (0, 0) -> "FizzBuzz"
| (0, _) -> "Fizz"
| (_, 0) -> "Buzz"
| (_, _) -> input.ToString()
@SamirTalwar
SamirTalwar / LambdasSnippet.java
Created October 6, 2014 11:44
Snippet of Lambdas.java from my FizzBuzz project.
public final class Lambdas {
public static final Lambda Identity = x -> x;
public static final Lambda True = x -> y -> x;
public static final Lambda False = x -> y -> y;
public static final Lambda Zero = f -> x -> x;
public static final Lambda Succ = n -> f -> x -> f.call(n.call(f).call(x));
public static final Lambda Pred = n -> f -> x -> n.call(g -> h -> h.call(g.call(f))).call(ignored -> x).call(u -> u);
public static final Lambda IsZero = f -> f.call(x -> False).call(True);
@SamirTalwar
SamirTalwar / musicbrainz-picard-file-name-format
Created March 8, 2014 13:31
MusicBrainz Picard file name format
$if2(%albumartist%,%artist%)/$if2($left(%date%,4),$if2($left(%originaldate%, 4), 0000)) - %album%/$if($gt(%totaldiscs%,1),%discnumber%-,)$num(%tracknumber%,2) - $if(%compilation%,%artist% -,) %title%
@SamirTalwar
SamirTalwar / subscribe.js
Last active January 13, 2025 21:50
"Subscribe" bookmarklet for NewsBlur. Copy and paste the code into the "Location" field of a new bookmark.
javascript: (function () {
/* change this for other services */
const SubscriptionUrlPrefix = "https://www.newsblur.com/?url=";
const FeedQuerySelector = [
'link[rel~="alternate"][type="application/atom+xml"]',
'link[rel~="alternate"][type="application/rss+xml"]',
].join(", ");
const YouTubeChannel = /^https:\/\/www.youtube.com\/channel\/([A-Za-z0-9_\-]+)$/;
@SamirTalwar
SamirTalwar / anagrams.hs
Created July 31, 2012 00:13
Detecting whether two strings are anagrams, in Haskell.
import Data.List
import Test.QuickCheck
anagrams :: String -> String -> Bool
anagrams x y = sort x == sort y
main = do
quickCheck (\(x, y) -> length x <= 8 ==> anagrams x y == (y `elem` permutations x))
-- tests `anagrams` using 100 sets of 2 random strings
-- uses an obvious but painfully slow algorithm
module Optional
def self.of value
Of.new value
end
def self.absent
Absent.new
end
private
@SamirTalwar
SamirTalwar / binary-solo.py
Created December 7, 2010 00:47
Binary Solo
#!/usr/bin/env python
from os import system
from sys import argv
BITS = [0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01]
def asciiToBin(ascii, bitSep=' ', byteSep='. '):
return byteSep.join(bitSep.join('1' if bit & ord(char) else '0'
for bit in BITS)