Skip to content

Instantly share code, notes, and snippets.

View yicone's full-sized avatar

yicone

View GitHub Profile
@yicone
yicone / gulpfile.js
Created January 12, 2015 09:22
My first gulpfile
var gulp = require('gulp');
var shell = require('gulp-shell');
var preprocess = require('gulp-preprocess');
var template = require('gulp-template');
var os = require('os');
var _ = require('underscore');
//var replace = require('gulp-replace');
//var inject = require('gulp-inject');
gulp.task('redis', shell.task('redis-server > /dev/null &'))
@yicone
yicone / cardPayView.js
Last active August 29, 2015 14:12
async waterfall sample
async.waterfall([
function (cb) {
app.service.pay(this.data, {
headers: {
"Session-Id": app.sessionId
},
success: function (data, textStatus, jqXHR) {
console.log('pay resp textStatus:' + textStatus);
console.log('pay resp data', data);
cb(null, data);
@yicone
yicone / zrx-1-GenericTypeSpecialization.cs
Last active August 29, 2015 14:04
泛型特化时,一般会遭遇无法用集合法来消除针对类型参数的 if 语句。通过使用匿名委托(需要静态泛型类作为 Holder),可以避免。其效果可以形容为作用于类型参数的模式匹配。如此也避免了可能存在的类型转换所带来的装箱/拆箱操作。
void Main()
{
IRecord record = new Record1();
Console.WriteLine (record.Get<int>("aaa"));
}
public interface IRecord {
string GetString(string field);
int GetInt(string field);
long GetLong(string field);
@yicone
yicone / 0:log4net_most_simple_sample.md
Last active August 29, 2015 14:00
使用log4net 历经纠结, 却也**从没有享受过纠结的好处**!
We couldn’t find that file to show.
@yicone
yicone / cal.css
Last active December 20, 2015 20:49
hhCal.js
/*==== calendar ==== */
.calendar_box {width:1168px;margin-bottom:20px;zoom:1;}
.calendar_box table {position:relative;float:left;width:554px;margin:0 30px 5px 0;overflow:hidden;zoom:1 ;}
.calendar_box caption {font:20px/42px "microsoft yahei";color:#24747b;}
.calendar_box caption a {display:block;height:42px;zoom:1;color:#24747b;}
.calendar_box table caption .pre,.calendar_box table caption .next {float:left;*display:inline;margin-right:-34px;width:34px;font:bold 26px/42px simsun;text-align:center;}
.calendar_box table caption .next {float:right;margin:0 0 0 -34px;}
.calendar_box table caption a:hover {background-color:#32c6c6;color:#fff;text-decoration:none;}
.calendar_box thead {border:1px solid #eee;}
.calendar_box th {width:78px;font:14px/34px "microsoft yahei";color:#999;}
@yicone
yicone / autoSetFrameHeight.js
Created July 24, 2013 07:24
Old Old autoSetFrameHeight
function autoSetFrameHeight(name) {
try {
var iframe;
if (!name) return;
iframe = document.getElementById(name);
if (iframe.contentDocument)
$("#" + name).height(iframe.contentDocument.height + "px");
else
$("#" + name).height(document.frames[name].document.body.scrollHeight + "px");
} catch (e) {
@yicone
yicone / AsyncActionManager.cs
Last active December 20, 2015 03:09
AsyncActionManager (internal supply buffering)
using System;
using System.Collections.Concurrent;
using System.Threading;
using System.Threading.Tasks;
namespace BufferingWorker
{
public class AsyncActionManager<TActionParam> where TActionParam : class
{
private BlockingCollection<ActionBag<TActionParam>> _q1 = new BlockingCollection<ActionBag<TActionParam>>(5000);
public static class CheckBoxExtensions
{
public static MvcHtmlString CheckBoxFor<TModel>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, int>> expression, int value)
{
if (expression == null)
{
throw new ArgumentNullException("expression");
}
ModelMetadata modelMetadata = ModelMetadata.FromLambdaExpression<TModel, int>(expression, htmlHelper.ViewData);
string modelName = ExpressionHelper.GetExpressionText(expression);
@yicone
yicone / AllWrapperedProducts.cs
Last active December 17, 2015 19:29
EF优化第一弹
internal override IQueryable<Entity.ProductWrapper> AllWrapperedProducts()
{
DateTime today = DateTime.Now.Date;
var query = (from p in ProductDbContext.Product
where p.ResourceType == (int)ProductResourceType.产品
&& p.PkgId.HasValue && p.PkgId.Value != 0
&& p.ExpireDate.HasValue
&& p.EffectDate.HasValue
&& p.IsValid.HasValue && p.IsValid.Value
@yicone
yicone / immutable-atomic-value-types.cs
Created May 25, 2013 10:36
http://www.tracefact.net/csharp-programming/immutable-atomic-value-types.aspx 1、当创建类型的目的是为了存储一组相关的数据,且数据量不是很大的时候,将它声明为Struct比Class会获得更高的效率;2、将类型声明为具有原子性和常量性,可以避免可能出现的数据不一致问题;3、通过在构造函数和Get访问器中,对对象的字段进行深度复制,可以避免在类型的外部修改类型内部数据的问题。
void Main()
{
string [] phones = { "18616386880", "18621168732" };
Foo foo = new Foo(phones);
Console.WriteLine(foo.Phones[0]);
phones[0] = "xxx";
Console.WriteLine(foo.Phones[0]);