This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static T Do (T obj, Action <T> f){f (obj); return obj;} | |
StopWatch sw = ... | |
sw.Do(x => x Stop()).ElapsedMillis; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Result<T> | |
{ | |
public bool HasException { get; } | |
public Exception Exception { get; } | |
public T Value { get; } | |
public Result(T value) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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]\+") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
NewerOlder