Skip to content

Instantly share code, notes, and snippets.

View xbotter's full-sized avatar
:octocat:

xbotter xbotter

:octocat:
  • China , ShangHai
  • 23:33 (UTC +08:00)
View GitHub Profile
@xbotter
xbotter / round.js
Created November 10, 2016 09:21
Fload.Round
// define round
function round(float,precision) {
return Math.round(float/precision)/(1/precision);
}
// how to use
round(0.3-0.2, .001)
@xbotter
xbotter / MultiThread.cs
Created March 6, 2017 04:33
C#多线程处理示例
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace ConsoleApplication
{
public class Program
{
@xbotter
xbotter / CovarianceAndContravariance.cs
Created March 6, 2017 04:42
C#协变和逆变示例
using System;
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
Two the_two = new Two();
// 协变 逆变
@xbotter
xbotter / consul.sh
Last active September 8, 2018 20:43 — forked from ianunruh/consul.sh
Install Consul on Ubuntu 16.04
#!/bin/bash
apt-get install -y curl unzip
mkdir -p /var/lib/consul
mkdir -p /usr/share/consul
mkdir -p /etc/consul/conf.d
curl -OL https://releases.hashicorp.com/consul/0.7.5/consul_0.7.5_linux_amd64.zip
unzip consul_0.7.5_linux_amd64.zip
mv consul /usr/local/bin/consul
@xbotter
xbotter / Lazyload.cs
Created August 3, 2017 05:17
Lazy Load Class
public class LazyLoad<T>
{
private readonly Lazy<T> _lazy;
private T _value;
public LazyLoad(Func<T> valueFactory)
{
_lazy = new Lazy<T>(valueFactory);
}
@xbotter
xbotter / PartialFunction.cs
Created August 16, 2017 01:27
C# Partial Function
public static class PartialFunction
{
public static Func<T1,Func<T2,TResult>> Curry<T1,T2,TResult>(Func<T1,T2,TResult> func) => arg1 =>arg2=>func(arg1,arg2);
public static Func<T1,Func<T2,Func<T3,TResult>>> Curry<T1,T2,T3,TResult>(Func<T1,T2,T3,TResult> func) => arg1=>arg2=>arg3=>func(arg1,arg2,arg3);
public static Func<T1,Func<T2,Func<T3,Func<T4,TResult>>>> Curry<T1,T2,T3,T4,TResult>(Func<T1,T2,T3,T4,TResult> func) => arg1=>arg2=>arg3=>arg4=>func(arg1,arg2,arg3,arg4);
public static Func<T1,Func<T2,Func<T3,Func<T4,Func<T5,TResult>>>>> Curry<T1,T2,T3,T4,T5,TResult>(Func<T1,T2,T3,T4,T5,TResult> func) => arg1=>arg2=>arg3=>arg4=>arg5=>func(arg1,arg2,arg3,arg4,arg5);
public static Func<T1,Func<T2,Func<T3,Func<T4,Func<T5,Func<T6,TResult>>>>>> Curry<T1,T2,T3,T4,T5,T6,TResult>(Func<T1,T2,T3,T4,T5,T6,TResult> func) => arg1=>arg2=>arg3=>arg4=>arg5=>arg6=>func(arg1,arg2,arg3,arg4,arg5,arg6);
public static Func<T1,Func<T2,Func<T3,Func<T4,Func<T5,Func<T6,Func<T7,TResult>>>>>>> Curry<T1,T2,T3,T4,T5,
@xbotter
xbotter / index.js
Created March 16, 2020 05:58
create or update querystring
function paramReplace(uri, key, value) {
// Find the param with regex
// Grab the first character in the returned string (should be ? or &)
// Replace our href string with our new value, passing on the name and delimeter
var re = new RegExp("[\\?&]" + key + "=([^&#]*)");
var separator = uri.indexOf('?') !== -1 ? "&" : "?";
var matches = re.exec(uri);
var newUri;
if (matches === null) {
@xbotter
xbotter / md5.cs
Created May 11, 2020 05:31
C# MD5 String
public static string GetMd5String(string input)
{
using (MD5 md5Hash = MD5.Create())
{
// Convert the input string to a byte array and compute the hash.
byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(input));
// Create a new Stringbuilder to collect the bytes
// and create a string.
StringBuilder sBuilder = new StringBuilder();
public interface ITimerDataSource
{
TimerTask LastTask();
void RemoveTask(string taskid);
void Insert(TimerTask task);
}
@xbotter
xbotter / clear-none-images.ps1
Created March 10, 2021 02:40
docker scripts
docker images | findstr '<none>' | ForEach-Object{$_.Split(" ",[System.StringSplitOptions]::RemoveEmptyEntries)[2];}| ForEach-Object{docker rmi $_}