Skip to content

Instantly share code, notes, and snippets.

View mollyporph's full-sized avatar

Otto Remse mollyporph

  • Forefront Consulting
  • Sweden
View GitHub Profile
@mollyporph
mollyporph / base62.ts
Created July 13, 2018 12:25
Base62.ts
import BitStream from './bit-stream'
const Base62CharSet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
function encodeBase62ByteArrayToString(original: Array<number>) {
var sb = [];
var stream = new BitStream(original);
var read = [];
read.push(0);
void Main()
{
var rng = RNGCryptoServiceProvider.Create();
var servers = new int[] { 1, 2, 3, 4, 5};
//generate 10 codes
var codes = Enumerable.Range(1, 10).Select(x => {
var server = servers.Random();
var bytes = new Byte[3];
using System;
using System.Text.RegularExpressions;
public class Program
{
public static Regex dateRegex = new Regex(@"(\d+)([smhd])",RegexOptions.Compiled | RegexOptions.IgnoreCase);
public static void Main()
{
Console.WriteLine(DateTime.Now.Add(TS("1d")));
public static T Do (T obj, Action <T> f){f (obj); return obj;}
StopWatch sw = ...
sw.Do(x => x Stop()).ElapsedMillis;
public class Result<T>
{
public bool HasException { get; }
public Exception Exception { get; }
public T Value { get; }
public Result(T value)
{
@mollyporph
mollyporph / bitgeo.cs
Last active September 22, 2016 22:12
void Main()
{
int id = 0;
id |= 1 << 11;
id |= 1 << 5;
id |= 1 << 2;
int id2 = 0;
id2 |= 1 << 1;
id2 |= 1 << 5;
id2 |= 1 << 10;
public static T Tap<T>(this T self, Action<T> f)
{
f(self);
return self;
}
public static T2 Pipe<T, T2>(this T self, Func<T, T2> f)
=> f(self);
#!/bin/bash
PATHTOLOG="/root/factorio/factorio-current.log"
OLDPLAYERCOUNT=0
PLAYERCOUNT=0
NUMBEROFLINESOLD=0
while :; do
#get the current nuber of log entries
NUMBEROFLINES=$(wc -l /root/factorio/factorio-current.log | grep -o "[0-9]\+")
public class User
{
public string Name {get;set;}
public string Email{get;set;}
public string PhoneNumber{get;set;}
}
public class Program
{
public static void Main(string[] args){
User user = new User{Name ="Otto", Email="[email protected]", PhoneNumber ="+4613371337"
private string GetSasToken(string sasKeyName, string sasKeyValue)
{
var fromEpochStart = DateTime.UtcNow - new DateTime(1970, 1, 1);
var expiry = Convert.ToString((int)fromEpochStart.TotalSeconds + 3600);
var stringToSign = WebUtility.UrlEncode(_baseAddress) + "\n" + expiry;
var hmac = new HMACSHA256(Encoding.UTF8.GetBytes(sasKeyValue));
var signature = Convert.ToBase64String(hmac.ComputeHash(Encoding.UTF8.GetBytes(stringToSign)));
var sasToken = string.Format(CultureInfo.InvariantCulture, "SharedAccessSignature sr={0}&sig={1}&se={2}&skn={3}",
WebUtility.UrlEncode(_baseAddress), WebUtility.UrlEncode(signature), expiry, sasKeyName);