Skip to content

Instantly share code, notes, and snippets.

View imzjy's full-sized avatar

Jerry Chou imzjy

View GitHub Profile
@imzjy
imzjy / pollurl.js
Created April 14, 2022 11:46 — forked from bit4bit/pollurl.js
polling jquery
function pollUrl(url, renderer) {
return function(render){
if(render == undefined) { render = renderer; }
$.getJSON(url, function(data){
render(data);
}).always(function(){
setTimeout(pollUrl(url, render), 5000);
});
};
@imzjy
imzjy / gist:ebd66a0b806b047c14dbf774c98cccf0
Created April 6, 2022 01:22 — forked from ReitenSchnell/gist:5998938
BlockingCollection with priorities
public class PriorityCollection
{
private readonly BlockingCollection<Item> low = new BlockingCollection<Item>();
private readonly BlockingCollection<Item> middle = new BlockingCollection<Item>();
private readonly BlockingCollection<Item> high = new BlockingCollection<Item>();
private readonly BlockingCollection<Guid> main = new BlockingCollection<Guid>();
private readonly BlockingCollection<Item>[] queue;
private readonly Dictionary<Priority, BlockingCollection<Item>> priorityMap = new Dictionary<Priority, BlockingCollection<Item>>();
public List<Priority> TestList { get; private set; }
using System;
namespace Zjy.Utils
{
public class Car {
public string Make {get; set;}
public string Model {get; set;}
public string Year {get; set;}
public int Mileage {get; set;}
public decimal Price {get; set;}
@imzjy
imzjy / DynamicOrderRuleLoader.cs
Created May 13, 2019 08:36
dynamic load the DLL that implements the IOrderRule interfaces. http://www.jeremybytes.com/Demos.aspx#PR
using OrderRules.Interface;
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
namespace OrderRules.RuleChecker
{
public static class DynamicOrderRuleLoader
{
@imzjy
imzjy / AsyncExplain.cs
Created May 13, 2019 07:28
async and await in C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace AsyncExplain
{
class Program
@imzjy
imzjy / CacheHelper.cs
Created April 2, 2019 10:02
Few lines code for boost the performance by in-memory cache
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Runtime.Caching;
namespace Dev.Lib
{
public class CacheHelper
{
@imzjy
imzjy / Performance.cs
Created April 2, 2019 07:34
One file (few lines) implement for performance check. for C# / .NET
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Web;
namespace Dev.Lib
{
public static class Performance
{
static class IoC {
static readonly IDictionary<Type, Type> types = new Dictionary<Type, Type>();
public static void Register<TContract, TImplementation>() {
types[typeof(TContract)] = typeof(TImplementation);
}
public static T Resolve<T>() {
return (T)Resolve(typeof(T));
}
@imzjy
imzjy / README.md
Created March 4, 2019 02:19 — forked from JaimeStill/README.md
Active Directory Authorization Workflow
@imzjy
imzjy / slash_middleware.py
Created May 11, 2018 11:34 — forked from Sepero/slash_middleware.py
Remove slashs in django - like APPEND_SLASH but opposite.
""" Author contact: sepero 111 @ gmail . com """
from django import http
from django.utils.http import urlquote
from django.core import urlresolvers
class RemoveSlashMiddleware(object):
"""
This middleware works like django's built in APPEND_SLASH, but in reverse. Eg