Skip to content

Instantly share code, notes, and snippets.

View fredeil's full-sized avatar
🤔

Fredrik Eilertsen fredeil

🤔
View GitHub Profile
public class ChickenCodec
{
static readonly char[] feed = { 'C', 'H', 'I', 'C', 'K', 'E', 'N', '.' };
private static Lazy<byte[]> charFeed = new Lazy<byte[]>(() =>
{
byte[] feed = new byte[256 * 8];
unsafe
{
fixed (byte* feedptr = feed)
{
// https://github.com/GoogleChrome/puppeteer
const signIn = async (username) => {
let currentPasswordIndex = 0;
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://www.reddit.com/login');
namespace ConsoleTester
{
class Program
{
static void Main(string[] args)
{
int n_machines = 3;
double[] probs = new double[n_machines];
double[] means = new double[] { 0.3, 0.5, 0.7 };
[<Class>]
type 'a BinaryTree =
member hd : 'a
member left : 'a BinaryTree
member right : 'a BinaryTree
member exists : 'a -> bool
member insert : 'a -> 'a BinaryTree
member print : unit -> unit
static member empty : 'a BinaryTree
@fredeil
fredeil / introrx.md
Created May 7, 2018 05:37 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
public static class RegexHelper
{
// Match IPv4-Address like 192.168.178.1
private const string IPv4AddressValues = @"(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)";
public const string IPv4AddressRegex = "^" + IPv4AddressValues + "$";
// Match IPv6-Address
public const string IPv6AddressRegex = @"(?:^|(?<=\s))(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{

I've worked with AngularJS for many years now and still use it in production today. Even though you can't call it ideal, given its historically-formed architecture, nobody would argue that it became quite a milestone not only for evolution of JS frameworks, but for the whole web.

It's 2017 and every new product/project has to choose a framework for development. For a long time I was sure that new Angular 2/4 (just Angular below) will become the main trend for enterprise development for years to come. I wasn't even thinking of working with something else.

Today I refuse to use it in my next project myself.

@fredeil
fredeil / ComputeHash.cs
Created July 19, 2018 07:01
The unmanaged constraint in C# 7.3
public unsafe static byte[] ComputeHash<T>(T data) where T : unmanaged
{
byte* bytes = (byte*)(&data);
using (var sha1 = SHA1.Create())
{
var size = sizeof(T);
using (var ms = new UnmanagedMemoryStream(bytes, size))
{
return sha1.ComputeHash(ms);
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<LangVersion>7.3</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Octokit" Version="0.32.0" />
@fredeil
fredeil / JsonTransformation.cs
Last active November 13, 2018 14:14
Transform json objects in .NET using JSON.NET
using System;
using Newtonsoft.Json.Linq;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
var original = JObject.Parse(@"{