Skip to content

Instantly share code, notes, and snippets.

View sholfen's full-sized avatar

Peter Liang sholfen

View GitHub Profile
@sholfen
sholfen / answer1.cs
Last active January 10, 2023 06:41
answer1.cs
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace OurSkyTestConsoleApp
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(@"https://www.google.com.tw");
var response = await client.GetAsync(@"/");
response.Content.Headers.ContentType.CharSet = "utf-8";
//string result = await response.Content.ReadAsStringAsync(System.Text.Encoding.UTF8);
//string result = await response.Content.ReadAsStringAsync();
byte[] byteArray = await response.Content.ReadAsByteArrayAsync();
string result = System.Text.Encoding.UTF8.GetString(byteArray, 0, byteArray.Length);
result = System.Text.Encoding.GetEncoding("utf-8").GetString(byteArray);
@sholfen
sholfen / sqlbuilder.cs
Last active May 24, 2019 15:46
sql builder code for Dapper
public List<T> QueryBy(Dictionary<string, object> dic)
{
string command = $"SELECT * FROM [User]";
Dictionary<string, object> args = new Dictionary<string, object>
{
{"ID1",0 },
{"ID2",1 }
};
@sholfen
sholfen / Startup.cs
Last active May 12, 2019 07:47
DI in ASP.NET MVC Core
foreach (Type type in System.Reflection.Assembly.GetExecutingAssembly().ExportedTypes.Where(t => t.FullName.EndsWith("Service")))
{
if (!type.IsInterface)
{
services.AddTransient(type.GetInterfaces().First(), type);
}
}
@sholfen
sholfen / GetUniqueId.cs
Created July 22, 2018 15:06
create short string from long string
public static class UtilityFunction
{
public static string GetUniqueId(string input)
{
string result = string.Empty;
char[] chars = new char[]
{
'a','b','c','d','e','f','g','h',
'i','j','k','l','m','n','o','p',
'q','r','s','t','u','v','w','x',
@sholfen
sholfen / smallest_number.py
Created August 2, 2017 15:22
prove the smallest number
for i in range(1, 2525):
result = 0
for j in range(1, 11):
if(0 == i%j):
result += 1
if 10 == result:
print(i)
result = 0
@sholfen
sholfen / get_dmhy_infomation.py
Created April 5, 2016 11:37
to get magnet link from dmhy twitter
# -*- coding: utf8 -*-
import twitter
import requests
import re
def get_magnet_link(url):
response = requests.get(url)
source_string = response.content
pattern = re.compile(r'(?<=id="a_magnet" href=")(.*?)">')
@sholfen
sholfen / BaseCloudTableModel.cs
Last active February 14, 2016 07:39
base class for Azure cloud table
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Table;
using System;
namespace Models
{
public class BaseCloudTableModel
{
protected CloudTableClient cloudTableClient;
@sholfen
sholfen / CountDiv.cs
Created November 11, 2015 15:13
for Codility CountDiv
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CountDiv
{
class Program
{
@sholfen
sholfen / MaxCounters.cs
Created November 11, 2015 13:39
for Cordiality MaxCounters
using System;
namespace MaxCounters
{
class MainClass
{
public static void Main (string[] args)
{
int[] A = { 3, 4, 4, 6, 1, 4, 4 };
int n = 5;