- 博客(277)
- 收藏
- 关注
原创 Filebeat configuration sample
###################### Filebeat Configuration Example ########################## This file is an example configuration file highlighting only the most common# options. The filebeat.reference.yml f...
2019-04-19 05:54:57 456
原创 Yield* in dart
import 'dart:async';main(List<String> args) async { await for (int i in numbersDownFrom(10)) { print('$i apples'); }}Stream numbersDownFrom(int n) async* { if (n >= 0) { a...
2019-03-30 07:13:50 1820
原创 Dart Stream Sample
import 'dart:async';Future<int> sumStream(Stream<int> stream) async{ var sum=0; await for(var value in stream){ sum += value; } return sum;}Stream<int> countStream(...
2019-03-30 06:24:31 259
原创 Dart named constructor
class Point { num x, y; Point(); // Named constructor Point.origin() { x = 1; y = 2; } @override String toString() { // TODO: implement toString return 'x=$x, y=$y';...
2019-03-28 07:15:21 315
原创 singleton
// dart singletonmain(List<String> args) { var helper = DBHelper(); helper = DBHelper(); helper = DBHelper(); helper = DBHelper(); helper = DBHelper(); helper = DBHelper(); hel...
2019-03-28 07:12:40 136
原创 Web Push Notification By GCM
https://developers.google.com/web/fundamentals/codelabs/push-notifications/server push:const webpush = require('web-push');webpush.setVapidDetails( 'mailto:example@hahaha.org', 'BPC_...
2019-03-27 06:46:22 534
原创 Dart mixin - multiple inheritance in dart class.
mixin Musical { bool canPlayPiano = false; bool canCompose = false; bool canConduct = false; void entertainMe() { if (canPlayPiano) { print('Playing piano'); } else if (canCond...
2019-03-06 00:47:51 133
转载 使用Docker快速搭建Kafka开发环境
创建 docker-compose.ymlversion: '2'services: zoo1: image: wurstmeister/zookeeper restart: unless-stopped hostname: zoo1 ports: - "2181:2181" container_name: zookeeper ...
2018-11-03 07:15:21 1341
原创 What you don't know about template string.
var a = 1, b = 2;var d = 'abc';function tag(strings, ...values) { console.log(strings); // "Hello " console.log(values); // 50 return "Bazinga!";}tag`Hello ${a} World ${b} 2.123 ${d...
2018-09-21 11:42:59 149
原创 Implemented Iterator in ES6
class Fruits { constructor() { this.items = []; } add(item) { this.items.push(item); } [Symbol.iterator]() { const elements = this.items; const t...
2018-09-21 11:40:12 122
原创 Service worker coding test
var version = '4.0';self.addEventListener('install', function (event) { event.waitUntil(caches.open(version));});self.addEventListener('activate', function (event) { event.waitUntil(new P...
2018-04-13 07:06:03 257
原创 自制ES6 Promise
Checked all Promise sample, none of them is in ES6 syntax, this is weird, which age are we now. Simplest verisonclass MyPromise { constructor(fn) { this.doneCallback = null; fn(t
2017-12-23 01:51:26 213
原创 Jquery PlugIn for lazy loading items.
//use it with slider control and lister onChange event(function($) { $.fn.sliderthumbs = function(options) { var myOptions = { listener: null }; var $this = $(
2017-08-15 16:50:14 333
原创 Share folder between windows and ubuntu linux vm from Virtual Box
1. Click“settings” on the toolbar of VM VirtualBox Manager2. Click“Shared Folders” from left side of settings page. Select a folder on Windows. e.g. D:\SharedFolder. and Add new share folder to “Mac
2015-07-24 16:52:12 537
原创 C# play with json in dynamic
var jsonString = @"{ 'id': '4', 'first_name': 'Mark', 'gender': 'male',
2014-12-09 15:03:59 699
转载 Diskpart 删除分区
管理员打开cmddiskpartsel disk 0list part看好分区号sel part 分区号del part override
2014-11-13 23:00:03 7765
原创 Working with promise and generators
var Q = require('q');function asyncSquare(n) { var defer = Q.defer(); setTimeout(function(){ if(n>5) defer.reject(888) defer.resolve(n*n); },2000) return defer.promise;}
2014-08-23 07:32:05 546
原创 Using HTTP Proxy in Node.js with request package
const request = require('request');request({'url':'http://example.com', 'proxy':'http://127.0.0.1:8888'}, function (error, response, body) { if (!error && response.statusCode == 200) {
2014-08-09 02:16:07 999
原创 通过Wiston创建log,一天一文件
/** * User access, app run and error log. * * @module Logger *///importvar fs = require('fs');var util = require('util');var winston = require('winston');var mkdirp = require('mkdirp');va
2014-03-24 11:18:24 2376
转载 Javascript format numbers
Round to a certain number of placesFor rounding decimals you can use the built-in JavaScript methods toFixed or toPrecision.var num = 10;var result = num.toFixed(2); // result will equal 10.00n
2013-07-10 13:13:41 620
原创 use nodemailer to send gmail
1. sudo npm install nodemailer2. Import the following class to your source codevar nodemailer = require("nodemailer");function MailPoster( to, subject, body){ this.from = 'XXXXXXX@gmail.com';
2013-06-07 14:07:11 1707
原创 示例:js使用正则表达式group来提取字符串中的数据
var linkStr = "/black-mountain/35-cotton-creek-cir-black-mountain-nc-421_537763.html";// 括号表示组。访问可以用group[index]来访问每组的信息var linkRegx = /\/([^\/]+)\/.+-(\d+)_(\d+).html/;var group = linkStr.match(li
2013-06-04 16:58:28 23964
原创 构造函数+原型混合方式实现js的继承
function ClassA(sColor){ this.color = sColor; }ClassA.prototype.sayColor = function(){ console.log(this.color);}function ClassB(sColor, sName){ ClassA.call(this, sColor); this.Name = sName;
2013-05-26 19:30:36 1688
原创 Hogan.js 使用pratial示例
var hogan = require("hogan.js");var template = hogan.compile('{{#list}}{{foo}}{{> par}}\n{{/list}}');var partial = hogan.compile('/*{{partialData.name}}-{{partialData.age}}*/');var result = templa
2013-05-24 15:40:48 3367
原创 Use command line arguments in Node.js
var args = process.argv.splice(2);if(!args || args.length ==0){ console.log("no params");}for(var i=0;i<args.length;i++) console.log(args[i]);commandline: node test1.js a b c doutput: a
2013-05-23 10:45:12 1559
原创 Adding timeout support for http request in Node.JS
This is HttpUtil Module, you need "require" it before using the module.var http= require("http");var HttpUtil = function(){ var namespace = { Get: function(options, timeout, callback){ v
2013-05-18 13:26:57 1146
原创 Silverlight中为Margin添加动画
因为在Silverlight中没有ThicknessAnimation,所以为Margin添加动画有点麻烦:1. 使用ObjectAnimationUsingKeyFrames来做,这个就是通过计算要显示的每一帧内容来设置动画,可能看起来不是那么平滑,如果需要平滑的话,那样就需要写代码来动态生成动画效果,看起来会平滑很多。使用XAML来进行描述就是这样:
2012-12-02 20:46:14 1759
原创 Visual Studio中的正则替换
现有strings 如下:/*China*//*Japan*/需要替换为:string s = "Hello " + "China" + ".Welcome to" + "China"string s = "Hello " + "Japan" + ".Welcome to" + "Japan"Ctrl + H打开替换窗口Find What
2012-11-28 17:10:04 906
转载 使用DBCC缩减数据库中log文件的大小
USE [master]GOALTER DATABASE CustomsAtom SET RECOVERY SIMPLE WITH NO_WAITGOALTER DATABASE CustomsAtom SET RECOVERY SIMPLE --简单模式GOUSE CustomsAtom GODBCC SHRINKFILE (N'CustomsNuke_log' , 11,
2012-09-04 07:43:10 1841
原创 Asp.net MVC 通过Attribute验证datamodel(二) ---使用IClientValidatable
上一篇文章实现的都是服务器端的验证,ASP.net MVC框架给我们提供了非常好的客户端验证机制。下面来修改一下上面的Attribute定义,使其实现IClientValidatable接口//验证逻辑就是判断专辑的Title是否包含某一个关键字 public class AlbumTitleValidateAttribute : ValidationAttribute,IClient
2012-08-08 22:17:17 2497 1
原创 Asp.net MVC 通过Attribute验证datamodel(一)
1. 除了可以使用Required, StringLength等Attribute,asp.net mvc中还可以自定义属于自己的验证Attribute。例如://验证逻辑就是判断专辑的Title是否包含某一个关键字 public class AlbumTitleValidateAttribute : ValidationAttribute { privat
2012-08-08 21:23:37 2045
原创 Ajax.ActionLink使用方法
1. 添加unobtrusive-ajax引用,2. 添加ActionLink@Ajax.ActionLink("Click here to see today's special", "DailyDeal", new AjaxOptions { UpdateTargetId = "testDiv", InsertionMode = InsertionMode.Replace, HttpM
2012-08-07 17:50:36 7465
原创 JS端调用Facebook API
1. 申请Facebook账号2.登陆http://developers.facebook.com/申请APPID3.一定要对你申请的APP设置Site URL 和Site Domain, 如果你需要调试,可以设置为http://localhost/和localhost4.在页面中引用JS, 5.现在就可以调用API了,在调用API之前,必须要进行初始化调用如下函数进行初始化:
2012-08-07 14:25:56 7397 1
原创 ASP.net MVC 属性验证
1. 建立Modelpublic class Order { [ScaffoldColumn(false)] public int OrderID { get; set; } [Required(ErrorMessage = "必须输入名字")] public string FirstName { get; set; }
2012-08-06 14:33:12 1193
原创 ASP.NET MVC3 学习笔记----HTML.Action()和HTML.RenderAction()
HTML.Action()和HTML.RenderAction()类似于HTML.Partial()和HTML.RenderPartial()辅助方法。Partial辅助方法通常在单独的文件中应用视图标记来帮助视图渲染视图模型的一部分。另一方面,Action是执行单独的控制器操作并显示结果。Action提供了更多的灵活性和重用性,因为控制器操作可以建立不同的模型,可以利用单独的控制器上下文。示
2012-07-25 13:44:01 14218 1
原创 Script to change gateway by command
@echo offrem eth //eth 为网卡名称,可在网络连接中查询,如"本地连接"set eth="本地连接"rem ip //ip 为你想更改的IPset ip=10.0.125.38rem gw //gw 为网关地址set gw=10.0.125.2rem netmasks //netmasks 为子网掩码set netmasks=255.255.255.0rem
2012-07-19 13:11:02 682
原创 获取Cassendra中某个ColumnFamly所有的值
项目中需要获取Cassendra中某个ColumnFamly所有的值,并且缓存起来。感谢Andy童鞋给了我很好的示例代码背景:这个ColumnFamly是Super的,SuperColumn是Year,Key是ID,每一个SuperColumn下面存放着不同的数据,比如MSR, Name,UpdateTime之类的。但我们这里只需要MSR,这个字段是整数,所以最终的示例代码如下:pub
2012-07-19 11:20:17 845
原创 Android判断是否有网络连接
1. 添加相应的权限 2. 判断方法public boolean isNetworkAvailable() { Context context = getApplicationContext(); ConnectivityManager connectivity = (ConnectivityManager) context.getSystemS
2012-07-11 17:08:43 627
原创 安卓本地存储
1.SharedPreferences类将数据保存在一个xml文件中,文件存放在/data/data//shared_prefs目录下// //创建异或获取一个已经存在的sharedPreferences对象SharedPreferences sharedPreferences = getSharedPreferences("mySP", Context.MODE_PRIVATE);
2012-07-11 16:39:25 721
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人