Skip to content

Instantly share code, notes, and snippets.

View sebfia's full-sized avatar
🎯
Focusing

Sebastian Fialka sebfia

🎯
Focusing
View GitHub Profile
@sebfia
sebfia / Async.fs
Last active April 6, 2018 04:17
Extensions for Async
module Async
open System.Threading.Tasks
let ForEach<'T> (computations: Async<'T> list) =
let rec forEach l r =
async {
match l with
| f::t ->
let! x = f
return! x::r |> forEach t
| [] -> return r |> List.rev
//package Microsoft.WindowsAzure.Storage
open Microsoft.WindowsAzure.Storage
let getBlobsInDirectory storageKey containerName =
let acct = CloudStorageAccount.Parse(storageKey)
let client = acct.CreateCloudBlobClient()
let container = client.GetContainerReference(containerName)
let rec getBlobs (d: string) t blobs =
async {
let! response = container.ListBlobsSegmentedAsync(d,true,BlobListingDetails.None,Nullable<int>(20),t,null,null) |> Async.AwaitTask
let result = response.Results |> Seq.map (fun i -> i :?> CloudBlockBlob) |> Seq.fold (fun s y -> y::s) blobs
@sebfia
sebfia / ConfigureFunctionApp.fs
Created March 8, 2018 22:49
New ASP.NET way of configuring Azure Function apps with beta runtime.
//package Microsoft.Extensions.Configuration
open Microsoft.Extensions.Configuration
let config =
ConfigurationBuilder()
.SetBasePath(context.FunctionAppDirectory)
.AddJsonFile("local.settings.json", true, true)
.AddEnvironmentVariables()
.Build()
let storageKey = config.["AzureWebJobsStorage"]
@sebfia
sebfia / JsonWebToken.fs
Created January 18, 2017 20:23
Creating and validating JWTs in just 35 lines of F# code.
module JsonWebToken =
open System
open System.Text
open System.Text.RegularExpressions
open System.Security.Cryptography
let replace (oldVal: string) (newVal: string) = fun (s: string) -> s.Replace(oldVal, newVal)
let minify =
let regex = Regex("(\"(?:[^\"\\\\]|\\\\.)*\")|\\s+", RegexOptions.Compiled|||RegexOptions.CultureInvariant)
fun s ->
regex.Replace(s, "$1")
@sebfia
sebfia / sha1PasswordHash.js
Created January 5, 2017 11:18
Creates a sha1 hash from a password or any string in javascript.
function sha1(msg)
{
function rotl(n,s) { return n<<s|n>>>32-s; };
function tohex(i) { for(var h="", s=28;;s-=4) { h+=(i>>>s&0xf).toString(16); if(!s) return h; } };
var H0=0x67452301, H1=0xEFCDAB89, H2=0x98BADCFE, H3=0x10325476, H4=0xC3D2E1F0, M=0x0ffffffff;
var i, t, W=new Array(80), ml=msg.length, wa=new Array();
msg += fcc(0x80);
while(msg.length%4) msg+=fcc(0);
for(i=0;i<msg.length;i+=4) wa.push(msg.cca(i)<<24|msg.cca(i+1)<<16|msg.cca(i+2)<<8|msg.cca(i+3));
while(wa.length%16!=14) wa.push(0);
@sebfia
sebfia / createCertificates.sh
Created September 10, 2015 17:23
Bash script to create certificates for securing and authenticating docker on a remote machine with tls.
#/bin/bash
domain="sebfia.net"
ipAddress=""
years=1
days=365
printip="127.0.0.1"
writeip="IP:127.0.0.1"
pwd=""
read -p "Enter the domain for your server certificate: [$domain] >" response
if [[ $response != "" ]]; then
let (|Int|_|) str =
match Int32.TryParse(str) with
| (true,int) -> Some int
| _ -> None
let (|Bool|_|) str =
match Boolean.TryParse(str) with
| (true,bool) -> Some bool
| _ -> None
@sebfia
sebfia / keybase.md
Created April 29, 2014 07:36
Identity proof

Keybase proof

I hereby claim:

  • I am sebfia on github.
  • I am sebfia (https://keybase.io/sebfia) on keybase.
  • I have a public key whose fingerprint is 2085 D96D 53C4 AACB 0017 A34C ED7A C095 7459 87B2

To claim this, I am signing this object:

@sebfia
sebfia / ExtendedWebClient.cs
Created June 20, 2012 09:41
A web client implementation that extends the System.Net.WebClient by storing cookies for recurring requests.
/// <summary>
/// A web client implementation that extends the System.Net.WebClient by storing cookies for recurring requests.
/// </summary>
public sealed class ExtendedWebClient : WebClient
{
public CookieContainer CookieContainer { get; set; }
protected override WebRequest GetWebRequest(Uri address)
{
var webRequest = base.GetWebRequest(address);