Skip to content

Instantly share code, notes, and snippets.

@Ellyll
Ellyll / CreateDataTable.fs
Last active May 9, 2020
F# function that takes a sequence (e.g. List) and returns a DataTable (with support for the F# Option type)
View CreateDataTable.fs
open System
open System.Data
open System.ComponentModel
let createDataTable (data: seq<'T>) : DataTable =
let table = new DataTable()
let props = TypeDescriptor.GetProperties(typeof<'T>)
// Add columns
for prop in props do
@Ellyll
Ellyll / Program.fs
Last active Mar 16, 2020
F# console app to get Corona virus data for Wales by county
View Program.fs
open FSharp.Data
[<Literal>]
let SampleUrl = "file://" + __SOURCE_DIRECTORY__ + "/Sample.html"
[<Literal>]
let PageUrl = "https://phw.nhs.wales/news/public-health-wales-statement-on-novel-coronavirus-outbreak/"
type Page = HtmlProvider<SampleUrl>
@Ellyll
Ellyll / cymharydd.fsx
Created Jan 19, 2020
Cymharu ffolderi gyda sgript F# (heb gorffen)
View cymharydd.fsx
open System.IO
type MathLlwybr =
| File of Length: int64
| Directory
//let llwybr1 = fsi.CommandLineArgs.ElementAt(1)
let dirChars = [| Path.DirectorySeparatorChar ; Path.AltDirectorySeparatorChar |] |> Array.distinct
@Ellyll
Ellyll / text_replacer.rb
Last active Sep 11, 2018
Replace words in text files in a directory with replacements in csv file
View text_replacer.rb
require 'fileutils'
inputDirectory = "/home/ellyll/Dropbox/Arbrofion/TextReplacer"
outputDirectory = "/tmp/ReplacedFiles"
replacementsFile = "/home/ellyll/Dropbox/Arbrofion/TextReplacer/replacements.csv"
# Read replacements csv file
replacements = File.readlines(replacementsFile).collect {|line| line.chomp.split(",") }
replacements.each {|r| puts "replace \"#{r[0]}\" with \"#{r[1]}\"" }
@Ellyll
Ellyll / northwalestech.kt
Created Mar 12, 2017
North Wales Tech JVM Languages tasks
View northwalestech.kt
import com.eclipsesource.json.Json
import com.eclipsesource.json.JsonObject
import com.eclipsesource.json.JsonValue
// Recursively get JSON values for all properties in a JSON object with the given key name
fun getAllWithName(jsonObj : JsonObject, keyName : String) : ArrayList<JsonValue> {
val keys = jsonObj.names()
return keys.fold(ArrayList<JsonValue>()) { acc, key ->
val value = jsonObj.get(key)
if (key == keyName) {
@Ellyll
Ellyll / FizzBuzz.fsx
Created Nov 15, 2016
F# FizzBuzz attempt
View FizzBuzz.fsx
let fizzBuzz n =
if n % 3 = 0 && n % 5 = 0 then "FizzBuzz"
elif n % 3 = 0 then "Fizz"
elif n % 5 = 0 then "Buzz"
else (sprintf "%d" n)
let a = seq { 1 .. 20 }
a
|> Seq.iter (fun n -> printfn "%d: %s" n (fizzBuzz n))
@Ellyll
Ellyll / haveibeenpwned.rb
Created Feb 15, 2014
Check a list of addresses on https://haveibeenpwned.com to see if they've been compromised
View haveibeenpwned.rb
require 'net/http'
require 'json'
http = Net::HTTP.new('haveibeenpwned.com',443)
http.use_ssl = true
addresses = %w(foo@bar.com) # Add your addresses here separated by spaces
http.start
addresses.each do |email_address|
res = http.get("/api/v2/breachedaccount/#{email_address}")
View Sorter.cs
using System.IO;
using System.Linq;
namespace SortingExample
{
public class Sorter
{
static void Main(string[] args)
{
var lines = File.ReadAllLines(args[0]).OrderBy(a => a);