Skip to content

Instantly share code, notes, and snippets.

View zhuqling's full-sized avatar

zhuqling zhuqling

  • @xinsailei
  • Guangzhou
View GitHub Profile
@zhuqling
zhuqling / rabbit_init_close.cs
Created March 11, 2013 03:39
创建RabbitMQ连接和通道(包含publisher confirm), 关闭通道和连接
private readonly ConnectionFactory _connFactory = new ConnectionFactory();
private IConnection _conn;
private IModel _chan;
private const string Host = "192.168.1.200";
private const string UserName = "guest";
private const string Password = "guest";
private void InitRabbit()
{
// 生成匿名Queue
var resultQ = _chan.QueueDeclare(
queue: "",
durable: false,
exclusive: true,
autoDelete: true,
arguments: null
);
string qName = resultQ.QueueName; // 得到Queue名称
@zhuqling
zhuqling / rabbit_publish_message.cs
Created March 11, 2013 03:43
RabbitMQ发送消息
IBasicProperties msgProps = new BasicProperties();
msgProps.DeliveryMode = 2; // 1=临时,2=永久
msgProps.ContentType = "application/json"; // mime type
msgProps.ReplyTo = qName; // 设置ReplyTo为匿名Queue,用于返回结果
// 发送消息
_chan.BasicPublish(
exchange:ExchangeName,
routingKey: RoutingKeyName,
basicProperties: msgProps,
@zhuqling
zhuqling / rabbit_consumer_by_event.cs
Created March 11, 2013 03:49
使用EventingBasicConsumer监听RabbitMQ消息, 不要求应答信息, 更新UI
public delegate void UpdateMsgBodyDelegate(string aString);
// 使用Consumer监控匿名Queue
var evtConsumer = new EventingBasicConsumer(){ Model = _chan};
evtConsumer.Received += Notify;
_chan.BasicConsume(
queue: qName,
noAck: true, // 不要返回ACK
consumer: evtConsumer
);
@zhuqling
zhuqling / rabbit_bind_queue_exchange.cs
Created March 11, 2013 03:54
申请Queue、Exchange,并进行绑定
// 声明Exchange
_chan.ExchangeDeclare(
exchange: ExchangeName,
type: ExchangeType.Direct,
durable: true,
autoDelete: false,
arguments: null
);
// 声明Queue
@zhuqling
zhuqling / rabbit_rpc_server_callback.cs
Created March 11, 2013 03:57
RabbitMQ RPC服务器返回结果到客户端
private void Notify(IBasicConsumer sender, BasicDeliverEventArgs args)
{
IBasicProperties msgProps = args.BasicProperties;
sender.Model.BasicAck(args.DeliveryTag, false); // 返回ACK应答信息
// 得到公式,并进入计算
string msgBody = Encoding.ASCII.GetString(args.Body);
var calcMessage = JsonConvert.DeserializeObject<CalcMessage>(msgBody);
// 显示公式
@zhuqling
zhuqling / use_flee_expression.cs
Created March 11, 2013 04:00
使用FLEE库计算表达式的值
string result = "";
try
{
// 按输入公式文本计算结果
ExpressionContext context = new ExpressionContext();
context.Imports.AddType(typeof (Math));
// context.Variables["a"] = 100; 可以在表达式内使用变量,再使用Variables传递变量值进行计算
IDynamicExpression eDynamic = context.CompileDynamic(calcMessage.Formula); // "sqrt(a) + pi"
result = eDynamic.Evaluate().ToString();
@zhuqling
zhuqling / rabbit_basic_consumer_dequeue.cs
Created March 11, 2013 06:20
RabbitMQ使用QueueingBasicConsumer循环方式,Dequeue取得队列
/*
* 使用QueueingBasicConsumer循环方式,取得队列
*/
var consumer = new QueueingBasicConsumer(_chan);
string consumerTag = _chan.BasicConsume("hello-queue",
false, consumer);
while (true)
{
BasicDeliverEventArgs evtArgs = (BasicDeliverEventArgs) consumer.Queue.Dequeue();
@zhuqling
zhuqling / animations.css
Created March 14, 2013 04:08 — forked from Twipped/animations.css
CSS3 动画效果集合, 也可以直接使用Animate.css @ http://daneden.me/animate/
.animated {
-webkit-animation: 1s ease;
-moz-animation: 1s ease;
-ms-animation: 1s ease;
-o-animation: 1s ease;
animation: 1s ease;
-webkit-animation-fill-mode: both;
-moz-animation-fill-mode: both;
-ms-animation-fill-mode: both;
-o-animation-fill-mode: both;
@zhuqling
zhuqling / sensitive_keywords_matched.py
Created March 18, 2013 05:44
敏感关键字匹配在线产品查找
#!/usr/bin/env python3
import collections
# 敏感关键字匹配在线产品查找
title_width = 60
FIELD_ITEMID = 0
FIELD_SKU = 1
FIELD_TITLE = 2