Skip to content

Instantly share code, notes, and snippets.

View gsscoder's full-sized avatar
💭
obsessive coding disorder

coder (π³) gsscoder

💭
obsessive coding disorder
View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / 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.scala
Created December 29, 2019 05:41
Scala program to calculate factorial of a number
// $ sbt
// sbt:factorial> ~run 10
// [info] running sample.Sample 10
// 3628800
package sample
object Sample extends App {
println(factorial(args(0).toLong).toString)
def factorial (num: Long) : Long = {
@gsscoder
gsscoder / factorial.hs
Last active December 28, 2019 20:39
Haskell program to calculate factorial of a number
-- $ ./factorial 10
-- 3628800
import System.Environment
main = do
args <- getArgs
let n = args !! 0
putStrLn (show (factorial (read n)))
factorial :: (Integral a) => a -> a
@gsscoder
gsscoder / factorial.csx
Last active December 29, 2019 06:19
C# script to calculate factorial of a number
// $ dotnet script factorial.csx 10
// 3628800
var n = long.Parse(Args.ElementAt(0));
Console.WriteLine($"{factorial(n)}");
long factorial(long n)
{
if (n == 0) {