Skip to content

Instantly share code, notes, and snippets.

@gsscoder
gsscoder / factorial.fsx
Created December 29, 2019 06:19
F# script to calculate factorial of a number
// $ dotnet fsi factorial.fsx 10
// 3628800
let rec factorial n : int64 =
match n with
| 0L -> 1L
| n -> n * factorial(n - 1L)
printfn "%d" (factorial (fsi.CommandLineArgs.[1] |> int64))
@gsscoder
gsscoder / factorial.lfe
Last active December 29, 2019 17:17
LFE snippet to calculate factorial of a number
"Copy and paste to LFE REPL to get: 3628800"
(defun factorial
((0) 1)
((n) (* n (factorial (- n 1)))))
(factorial 10)
@gsscoder
gsscoder / PickAll-NLP_POS_tagger.fs
Created January 1, 2020 08:05
F# program that demonstrates the use of PickAll with Standford NLP POS Tagger
(*
Demonstrates the use of PickAll with Standford NLP POS Tagger
PickAll:
- https://github.com/gsscoder/pickall
Derived from:
- http://sergey-tihon.github.io/Stanford.NLP.NET/samples/POSTagger.Sample.html
TargetFramework:
- net452
References:
- netstandard
@gsscoder
gsscoder / GoogleScraper.cs
Created January 10, 2020 09:23
Easy C# program that scrapes Google with AngleSharp (part of a blog post)
using System;
using System.Threading.Tasks;
using AngleSharp;
using AngleSharp.Html.Dom;
using AngleSharp.Dom;
class Program
{
static async Task Main(string[] args)
{
@gsscoder
gsscoder / generic_find.go
Created January 15, 2020 10:31
Go generic function to find an array item
// "generic" function to find an array item
package main
import (
"fmt"
"reflect"
)
func main() {
ints := make([]int, 5)
@gsscoder
gsscoder / Caste_DynamicProxy_interceptor.cs
Created January 19, 2020 07:39
Simple C# program that uses Caste DynamicProxy intereception
// requires:
// dotnet add package Castle.Core --version 4.4.0
// output:
// IAdder::Sum invoked
// 3
using System.Runtime.CompilerServices;
using System;
using Castle.DynamicProxy;
@gsscoder
gsscoder / TypeExtensions_IsAnonymous.cs
Created January 20, 2020 07:01
Type extension method to check if an instance is of anonymous type
using System;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
static class TypeExtensions
{
public static Boolean IsAnonymous(this Type type)
{
if (!type.GetCustomAttributes(typeof(CompilerGeneratedAttribute), false).Any()) {
@gsscoder
gsscoder / EventHelper.cs
Last active January 21, 2020 13:44
C# helper class for raising events
using System;
using System.Runtime.CompilerServices;
static class EventHelper
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void RaiseEvent(object sender, EventHandler handler, EventArgs args, bool enabled)
{
if (enabled && handler != null) {
handler(sender, args);
@gsscoder
gsscoder / Guard.cs
Last active November 27, 2021 13:07
C# arguments validation guard class
using System;
using System.Linq;
using System.Runtime.CompilerServices;
static class Guard
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void AgainstNull(string argumentName, object value)
{
if (value == null) throw new ArgumentNullException(argumentName, $"{argumentName} cannot be null.");
@gsscoder
gsscoder / cleanzsh.sh
Created February 7, 2020 17:18
Script to speed ZSH startup (removing history files)
#!/bin/sh
sudo rm -rf /private/var/log/asl/*.asl