由买买提看人间百态

topics

全部话题 - 话题: err
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
d****n
发帖数: 1637
1
来自主题: Programming版 - 如何快速处理大量网上xml文件?
http://play.golang.org/p/vS409gRveG
开20个worker,多用几个 电脑,当你 存xml时候注意一下duplicates就搞定了。指定
比你的 python快
// In this example we'll look at how to implement
// a _worker pool_ using goroutines and channels.
package main
import "fmt"
import "net/http"
import "log"
import "io/ioutil"
// Here's the worker, of which we'll run several
// concurrent instances. These workers will receive
// work on the `jobs` channel and send the corresponding
// results on `results`. We'll sleep a second per job to
// simulate... 阅读全帖
d****n
发帖数: 1637
2
来自主题: Programming版 - Be $#%!ing explicit
Example
Consider fetching a user id from a cookie. How much language knowledge do
you need to answer the following questions given the implementation?
What happens if the cookie is not present?
What happens if the cookie value is not a well formatted number?
What happens if the cookie value is a negative number?
Scala
import play.api.mvc.RequestHeader
def getUserId()(implicit request: RequestHeader) = {
request.cookies.get("uid").map(_.value.toLong).filter(_ > 0)
}
Go
import (
"fmt"
"http"... 阅读全帖
k*****y
发帖数: 744
3
It might be easier to look at it this way:
R^2 = 1 - err^2/var(Y)
Where err = Y - (A+BX), and err is perp to vec(1) and X.
Note that err is still perp to vec(1) and X', so after the transformation to
Y':
err' = a2*err.
And obviously var(Y') = a2^2 var(Y), therefore
(R^2)' = R^2.
k*****y
发帖数: 744
4
It might be easier to look at it this way:
R^2 = 1 - err^2/var(Y)
Where err = Y - (A+BX), and err is perp to vec(1) and X.
Note that err is still perp to vec(1) and X', so after the transformation to
Y':
err' = a2*err.
And obviously var(Y') = a2^2 var(Y), therefore
(R^2)' = R^2.
m******t
发帖数: 273
5
【 以下文字转载自 Quant 讨论区 】
发信人: myregmit (myregmit), 信区: Quant
标 题: solve integral eq. embeeded with another integral eq.
发信站: BBS 未名空间站 (Sun Mar 23 14:20:18 2014, 美东)
I need to solve an integral equation embedded with another integral equation
by python 3.2 in win7.
There are 2 integral equations.
The code is here:
import numpy as np
from scipy.optimize.minpack import fsolve
from numpy import exp
from scipy.integrate.quadpack import quad
import matplotlib.pyplot as plt
impor... 阅读全帖
L*****e
发帖数: 8347
6
来自主题: JobHunting版 - 新公司的Coding Review 真让人窝火
下面是苹果SSL连接验证的一段code,这个bug居然存在了几年才被发现。。。
static OSStatus
SSLVerifySignedServerKeyExchange(SSLContext *ctx, bool isRsa, SSLBuffer
signedParams, uint8_t *signature, UInt16 signatureLen)
{
OSStatus err;
...
if ((err = SSLHashSHA1.update(&hashCtx, &serverRandom)) != 0)
goto fail;
if ((err = SSLHashSHA1.update(&hashCtx, &signedParams)) != 0)
goto fail;
goto fail;
if ((err = SSLHashSHA1.final(&hashCtx, &hashOut)) != 0)
goto fail;
...
fail:
... 阅读全帖
b***i
发帖数: 10018
7
来自主题: Running版 - 终于征服了我的心魔
17miles long run, 也是本训练计划的最后一次long run。
这条路线是我的"心魔"路线,之前在她上面只跑过两次20miles,都很惨。
这次终于吸取教训,fuel belt带两瓶水,吃了两个gel,前慢后快。
终于暴力地征服了她!
Splits:
Distance Pace Avg HR Notes
1 Mi 8:45 140 HRM err, <130
1 Mi 8:22 140 HRM err, <130
1 Mi 8:38 155 HRM err, <130
1 Mi 8:43 146 HRM err, <130
1 Mi 8:46 141 HRM err, <130
1 Mi 8:47 130
1 Mi 8:21 136
1 Mi 8:07 139
1 Mi 8:00 143
1 Mi 8:10 142
1 Mi 7:55 145
1 Mi 7:55 145
1 Mi 7:23 157
1 Mi 7:10 162
1 Mi 7:01 168
1 Mi 6:42 172
1 Mi 6:26 176
m***i
发帖数: 213
8
机器:zotac zbox id 82 plus,
主板:Intel HM65 express,
硬盘 Samsung 250G SSD, seagate 250G SSD,
dmesg:
linux安装程序遇到这个错误,相信相关的输出是这几行:
WARNING kernel:ata1.00: link is slow to respond, please be patient (ready=-
19)
ERR kernel:ata1.00: SRST failed(errno=-16)
WARNING kernel:ata1.00: link is slow to respond, please be patient (ready=-
19)
ERR kernel:ata1.00: SRST failed(errno=-16)
WARNING kernel:ata1.00: link is slow to respond, please be patient (ready=-
19)
ERR kernel:ata1.00: SRST failed(errno=-16)
WARNING... 阅读全帖
w****w
发帖数: 521
9
来自主题: Programming版 - Python擂台:算24点
搞了两个礼拜,对python有点感觉了。
import math
_expr=lambda x,y,z:"(%s%s%s)"%(x,y,z)
_plus=lambda x,y: (x[0]+y[0],_expr(x[1],"+",y[1]))
_minus=lambda x,y: (x[0]-y[0],_expr(x[1],"-",y[1]))
_rminus=lambda x,y: _minus(y,x)
_mul=lambda x,y: (x[0]*y[0],_expr(x[1],"*",y[1]))
_div=lambda x,y: (y[0]==0 and (0,"err")) or (x[0]/y[0],_expr(x[1],"/",y[1]))
_rdiv=lambda x,y: _div(y,x)
_mod=lambda x,y: (y[0]==0 and (0,"err")) or (x[0]%y[0],"mod(%s,%s)"%(x[1],y[
1]))
_rmod=lambda x,y: _mod(y,x)
def _power(x,y):
try: ret... 阅读全帖
w****w
发帖数: 521
10
来自主题: Programming版 - Python擂台:算24点
搞了两个礼拜,对python有点感觉了。
import math
_expr=lambda x,y,z:"(%s%s%s)"%(x,y,z)
_plus=lambda x,y: (x[0]+y[0],_expr(x[1],"+",y[1]))
_minus=lambda x,y: (x[0]-y[0],_expr(x[1],"-",y[1]))
_rminus=lambda x,y: _minus(y,x)
_mul=lambda x,y: (x[0]*y[0],_expr(x[1],"*",y[1]))
_div=lambda x,y: (y[0]==0 and (0,"err")) or (x[0]/y[0],_expr(x[1],"/",y[1]))
_rdiv=lambda x,y: _div(y,x)
_mod=lambda x,y: (y[0]==0 and (0,"err")) or (x[0]%y[0],"mod(%s,%s)"%(x[1],y[
1]))
_rmod=lambda x,y: _mod(y,x)
def _power(x,y):
try: ret... 阅读全帖
i**p
发帖数: 902
11
来自主题: Programming版 - Micro-SD card 驱动程序 (转载)
这是一个root了的Android手机.
3 parts of dmesg here, insmod, remove sd card, insert sd card:
--------------------------------------
insmod mysdio.ko (sd card is in, trace is from my printk. no probe trace
though I add prink to my_sdio_probe)
<7>[ 263.716249] (pid:728, cmd:insmod) my_sdio_driver.drv.name:CRYPTRmicro_
sdio
<7>[ 263.716316] (pid:728, cmd:insmod) my_sdio_driver.drv.bus:0x8049be80
<7>[ 263.716373] (pid:728, cmd:insmod) my_sdio_driver.drv.bus->name:sdio
<7>[ 263.716429] (pid:728, cmd:insm... 阅读全帖
w*s
发帖数: 7227
12
i have a sqlite3 nested query case. Was hoping to push each query result to
a json array and return it back. But always get "Error: SQLITE_MISUSE:
Database handle is closed" for the 2nd select call. Seems the db.close()
gets called before the 2nd query.
Why is this, i thought serialize can take care of this. How to fix it please
?
var getMyDbInfo = function(callback) {
var db = new sqlite3.Database("MyDB.sqlite3");
db.serialize(function() {
var myJsonObj = {};
db.each("se... 阅读全帖
w*s
发帖数: 7227
13
i have a sqlite3 nested query case. Was hoping to push each query result to
a json array and return it back. But always get "Error: SQLITE_MISUSE:
Database handle is closed" for the 2nd select call. Seems the db.close()
gets called before the 2nd query.
Why is this, i thought serialize can take care of this. How to fix it please
?
var getMyDbInfo = function(callback) {
var db = new sqlite3.Database("MyDB.sqlite3");
db.serialize(function() {
var myJsonObj = {};
db.each("se... 阅读全帖
m******t
发帖数: 273
14
【 以下文字转载自 Quant 讨论区 】
发信人: myregmit (myregmit), 信区: Quant
标 题: solve integral eq. embeeded with another integral eq.
发信站: BBS 未名空间站 (Sun Mar 23 14:20:18 2014, 美东)
I need to solve an integral equation embedded with another integral equation
by python 3.2 in win7.
There are 2 integral equations.
The code is here:
import numpy as np
from scipy.optimize.minpack import fsolve
from numpy import exp
from scipy.integrate.quadpack import quad
import matplotlib.pyplot as plt
impor... 阅读全帖
m******t
发帖数: 273
15
I need to solve an integral equation embedded with another integral equation
by python 3.2 in win7.
There are 2 integral equations.
The code is here:
import numpy as np
from scipy.optimize.minpack import fsolve
from numpy import exp
from scipy.integrate.quadpack import quad
import matplotlib.pyplot as plt
import sympy as syp
lb = 0
def integrand2(x, a):
print("integrand2 called")
return x**(a-1) * exp(-x)
def integrand1(x, b, c):
print(... 阅读全帖
m******t
发帖数: 273
16
【 以下文字转载自 Quant 讨论区 】
发信人: myregmit (myregmit), 信区: Quant
标 题: solve integral eq. embeeded with another integral eq.
发信站: BBS 未名空间站 (Sun Mar 23 14:20:18 2014, 美东)
I need to solve an integral equation embedded with another integral equation
by python 3.2 in win7.
There are 2 integral equations.
The code is here:
import numpy as np
from scipy.optimize.minpack import fsolve
from numpy import exp
from scipy.integrate.quadpack import quad
import matplotlib.pyplot as plt
impor... 阅读全帖
b***i
发帖数: 10018
17
Tried to hold 7:17/mi after 4 miles of warm up. Heart rate was nice and low.
Looks like the recent VO2max sessions and time trials gave me better
running economy.
Distance: 15.11 miles
Duration: 1:50:46.32
Pace: 7:20 / mile
Heart Rate: Average: 153 / Max: 171
Distance Pace Avg HR Max HR
1 Mi 8:08 145 170 --HR err
1 Mi 7:46 151 168 --HR err
1 Mi 7:37 150 176 --HR err
1 Mi 7:23 157 185 --HR err, Restroom break
1 Mi 7:17 151 165
m*d
发帖数: 7658
18
来自主题: TVChinese版 - PPS限制升级了?
npm ERR! Error: No compatible version found: ub.uku.js
npm ERR! No valid targets found.
npm ERR! Perhaps not compatible with your version of node?
npm ERR! node -v v0.6.19
node版本太低,好像需要0.8以上
{"node":"0.8.x","npm":"1.1.x"}
还得自己make
N*n
发帖数: 456
19
来自主题: Java版 - a dump method in Java
谢谢。。找了点code在看。。
public class StackTraceExample
{
//private static final Logger logger = Logger.getLogger(StringReplace.class.
getName());
public static void main(String args[])
{
//calling a method to print stack trace further down
first();
}
public static void first()
{
second();
}
private static void second()
{
third();
}
private static void third()
{
//If you want to print stack trace on console than use dumpStack() method
System.err.println("Stack trace of current thread using dumpStack() ... 阅读全帖
p*****2
发帖数: 21240
20
来自主题: Programming版 - 怎样能把go写的稍微漂亮一点?

github
我看了,不就是我说的这样吗? 一个return。这就是你说的现代化C程序?
aeEventLoop *aeCreateEventLoop(int setsize) {
aeEventLoop *eventLoop;
int i;
if ((eventLoop = zmalloc(sizeof(*eventLoop))) == NULL) goto err;
eventLoop->events = zmalloc(sizeof(aeFileEvent)*setsize);
eventLoop->fired = zmalloc(sizeof(aeFiredEvent)*setsize);
if (eventLoop->events == NULL || eventLoop->fired == NULL) goto err;
eventLoop->setsize = setsize;
eventLoop->lastTime = time(NULL);
eventLoop->timeEventHead = ... 阅读全帖
d****n
发帖数: 1637
21
来自主题: Programming版 - 怎样能把go写的稍微漂亮一点?
myself- only deal with known error
limiting error types by handling each one specific.
func a(){
handle everything I know else return to caller
}
func b(){
err = a()
handle everything I knew, else send it to caller

}
func c(){
err = b()
handle everthing I knew, else, give to caller
}
V.S. most oop classic try...catch(I might be wrong on this)
func SuperGenericErrorHandleFunction(){

try:
a()
b()
c()
catch err:
switch err{
case a.shit:
case b.shit:
... 阅读全帖
d****n
发帖数: 1637
22
来自主题: Programming版 - 怎样能把go写的稍微漂亮一点?
type AggError struct{
cnt int
errorVals [] interface{}
}
func myFn () error{
var aggErr AggError
for {
go func(){
...
if err!=nil{
sync.Lock()
aggErr.cnt++
aggErr.errorVals = append(aggError.errorVals, err)
sync.Unlock()
}
}()
}
return aggErr
}
func Caller(){
err := myFn()
if err == aggErr{
//handle it
}
//anything else rather than AggError is what I dont know. submit to Caller

}
b***e
发帖数: 1419
23
/**
To use promise is unnecessary. More succinct syntax can be achieve with
other libs, such as "node-sync". This package also captures an emulation of
call stack when there are exceptions.
**/
/* use "node-sync" package */
var proc = require('node-sync');
var cb = function(err, res) {
if (err) {
console.log('cb ERROR', err.stack);
console.log(err.__generatorStack__);
} else {
console.log('OK', res);
}
};
var wait = function(n) {
return function(cb) {
... 阅读全帖
c*********e
发帖数: 16335
24
我本来也不信,上周debug出了这么一error message,改了之后error message就没了。
你说神奇不?
还好这有一证据
https://github.com/caolan/async
---------------
Multiple callbacks
Make sure to always return when calling a callback early, otherwise you will
cause multiple callbacks and unpredictable behavior in many cases.
async.waterfall([
function (callback) {
getSomething(options, function (err, result) {
if (err) {
callback(new Error("failed getting something:" + err.message));
// we shoul... 阅读全帖
r****y
发帖数: 1437
25
来自主题: Computation版 - [转载] 问个误差估计的问题
【 以下文字转载自 Mathematics 讨论区 】
【 原文由 rossby 所发表 】
假设测量一个物理量随时间变化的情况
y = y(t) t=1, 2, 3, 4, ...,
每一时刻测量的误差也是知道的,为err(t),每一次的误差都是独立随即变量
如果此物理量随时间的变化可以表示成
y0(t)= at + b + y1(t)
where y1(t+T)= y1(t)
如果先用线性拟合估计a, b及其error bar,
y1(t)的数值估计 mean{(y(t)-at-b)} for t=i, i+T, i+2T,..., i+NT
如果我想给出y1(t)的数值估计的error bar,该怎么给出呢?
如果没有线性函数at+b,误差err(t)=err=Costant, 那么y1(t)的
error bar 是 err/ sqrt(N). 加了这个线性项, 我就不知道怎么做了。

发帖数: 1
26
美媒:美F-35战斗机将到爱沙尼亚 向俄罗斯示威
美《防务新闻》4月24日刊发报道,爱沙尼亚ERR新闻报道称,美国空军多架F-35战斗机
将在周二(25日)抵达爱沙尼亚,并可能在该国停留数个星期,与北约国家进行共同训
练。美国空军方面对此拒绝评论,表示所有F-35战斗机在欧洲的部署行动只有在飞机着
陆后才会进行报道。
据悉美国空军34战斗机中队的8架F-35A战斗机上周抵达英国,当时美国空军曾宣布这些
飞机可能将飞到其他北约国家进行训练。《防务新闻》评论称,如果ERR的报道属实,
那么F-35的爱沙尼亚之行对于公众来说将是一个“惊喜”,或许对于俄罗斯来说也是一
样。
爱沙尼亚等波罗的海三国曾是苏联加盟共和国,在苏联解体后,波罗的海三国因为历史
激烈反俄,因此与俄罗斯关系一直紧张,目前北约在该国境内部署了多国联合军事力量
,俄罗斯方面一直将此视为对本国的安全威胁。
美国空军F-35A战斗机
报道称,爱沙尼亚ERR新闻网周一报道称,25日将有数架F-35A战斗机进驻爱沙尼亚阿玛
里空军基地,它们将在该国停留“数周”,期间将与美国及其盟友军队进行训练飞行。
美国空军发言人拒绝评论这一部署的消... 阅读全帖
I**********s
发帖数: 441
27
最喜欢 wwwyhx的解法: recursive descent.
我也写了个, 用的是建造AST, 再evaluate AST. 应该相当完整了: 数字之前可以有+-
号, 中间可以有一个小数点. 数字和运算符号之间可以有空格. 可以使用+,-,*,/,^,以
及括号. 可以检测错误输入并报出错误位置. 就是比较长, 不适合面试用. 供大家参考.
#include
#include // for pow()
using namespace std;
struct Node {
double val;
char op;
int op_prec; // precedence of operator
int type; // 0 - operand, 1 - operator
Node * left;
Node * right;
Node(double _val, char _op, int _type) : val(_val), op(_op),
type(_type), lef... 阅读全帖
I**********s
发帖数: 441
28
最喜欢 wwwyhx的解法: recursive descent.
我也写了个, 用的是建造AST, 再evaluate AST. 应该相当完整了: 数字之前可以有+-
号, 中间可以有一个小数点. 数字和运算符号之间可以有空格. 可以使用+,-,*,/,^,以
及括号. 可以检测错误输入并报出错误位置. 就是比较长, 不适合面试用. 供大家参考.
#include
#include // for pow()
using namespace std;
struct Node {
double val;
char op;
int op_prec; // precedence of operator
int type; // 0 - operand, 1 - operator
Node * left;
Node * right;
Node(double _val, char _op, int _type) : val(_val), op(_op),
type(_type), lef... 阅读全帖
w****a
发帖数: 710
29
举个例子,
比如你在写一个脚本解析器,你编译脚本过程中检查脚本是否有语法错误。但是你的检
查机制可能在很多初。如果你每次检查到语法错误的时候仅仅是打印下错误信息,这个
显然不行,因为你可能不需要打印信息而是要返回具体的错误描述,要写到日志里。如
果仅仅是return,这个也不行,你在你的解析器里return,外面也不知道。如果是传统
方法的话,一般可以写到一个全局的错误收集器里,可以通过GetLastError之类的函数
来获取上一次出错的错误编号和具体内容。这个是传统做法。
如果使用exception机制,查到错误时直接抛出异常。你抛出异常,可以由不同的地方
catch。catch后可以随意处理,可以跳过,也可以直接警告输出个消息,也可以崩溃。
比如上面的例子:
try{
script_parser.parse(script);
}catch(XXXScriptExcept& e){
printf(e.what());
}
传统做法的代码是:
int err = script_parser.parse(script);
if(err!=0){
printf(G... 阅读全帖
S*******C
发帖数: 822
30
package com.cdd.jdbc;
import java.sql.*;
public class CreateConnection {
public Connection conn=null;
public ResultSet rs=null;
public Statement stmt=null;
public CreateConnection() { //构造方法
}
//获取数据库连接方法
public Connection getConnection() {
try {
Class.forName("com.mysql.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:mysql://mydbinstance.XXXXXXX.
us-east-1.rds.amazonaws.com:3306/db_database05","root","11111");
//不管用上... 阅读全帖
J*****v
发帖数: 314
31
终于做出来了,这题用来刷掉三哥效果最好
public class Solution {
public boolean minSquaredSmallerThanMax(int[] nums) {
int min = Integer.MAX_VALUE, max = Integer.MIN_VALUE;
for (int num : nums) {
min = Math.min(min, num);
max = Math.max(max, num);
}
return (long) min * min < max;
}
public int minDelectionFromFront(int[] nums) {
if(minSquaredSmallerThanMax(nums)) {
return 0;
}
int len = nums.length;
do... 阅读全帖
b*****p
发帖数: 2670
32
☆─────────────────────────────────────☆
pinkmartinit (~水瓶) 于 (Fri Dec 17 22:53:14 2010, 美东) 提到:
今天放晴,中午心情很好,来版上说了几句话,被人挖苦,很是郁闷
星版上,大家互相吹捧,是很平常的事。 娱乐而已。 没有目的,也不需要目的。我愿
意提到谁就提到谁。请淡定。。。
骂俺是马屁精,我听着很别扭。不舒服。
上次我赞你是美女的时候,你可没这么说。
我很喜欢星版这块地方的,可以就星相这些玄幻的东西随意发点声音。 也可以灌水。
请不要随意评价别人。破坏灌水的气氛。
☆─────────────────────────────────────☆
chihiro (千寻) 于 (Fri Dec 17 23:04:50 2010, 美东) 提到:
cft

☆─────────────────────────────────────☆
doko (硬板床) 于 (Fri Dec 17 23:13:44 2010, 美东) 提到:
dude, mpj is a super c... 阅读全帖
i*****t
发帖数: 2435
33
来自主题: PhotoForum版 - Nikon FM3a有人用吗
胶片机没用过。不过应该不是光圈的问题。Mount上去后肩屏显示Err,用手按按镜头,
Err消失。关机再开机,Err又出来了。这样一来再加上卖像一般就Pass了.
a****3
发帖数: 70
34
来自主题: WaterWorld版 - 我所知道的香港和香港人
會說標準英音/美音英語的大陸人太太太罕見了吧. 網上看很多大陸人都覺得自己英文
特溜, 怎麼我在英國待過兩年, 美國生活十幾年東岸西岸都住過就沒見過幾個大陸人講
英文講得好的呢?
大陸人的英文口語我以前就講過, 口音是一個問題, 文法造句之類的又是另一個問題,
但是讓人難懂主要是沒有flow, err err err 半天都想不出個單詞,intonation特差,
尤其是講電話的時候是非常非常難懂的.
當然, 絕大部份香港人英文也是相當差的, 基層服務業的當然是更差.
我覺得更多的情況是香港人聽不懂大陸腔英語, 就只好花更多時間慢慢問和慢慢招呼大
陸人了.
i****e
发帖数: 913
35
来自主题: Apple版 - 大家快升级7.0.6吧
就这一行Bug, 任何钓鱼网站都可以通过证书欺骗, 伪装成正牌网站, 而不被Safari察
觉.
if ((err = SSLHashSHA1.update(&hashCtx, &signedParams)) != 0)
goto fail;
goto fail; <---- Apple码农手一抖, 多Paste了一行
if ((err = SSLHashSHA1.final(&hashCtx, &hashOut)) != 0)
goto fail;
fail:
SSLFreeBuffer(&signedHashes);
SSLFreeBuffer(&hashCtx);
return err;
}
Cydia上已经有Patch了,不用update iOS
http://appadvice.com/appnn/2014/02/cydia-store-how-to-install-i
t********5
发帖数: 274
36
来自主题: DotNet版 - 求救一个小问题
我也认为是button的事件里写的
可是我找不到那个button相关的任何代码
是flash,整个页面主要都是flash的,我以前没接触过flash方面的编程,不知道您有
没有什么猜想,我顺着路子去找一找
table.aspx页面,就是有聊天窗口,有send按钮的这个页面
<%@ Page Title="" Language="VB" MasterPageFile="~/Shared/xxxx.master"
AutoEventWireup="false"
CodeFile="table.aspx.vb" Inherits="VNT_table" %>
"Server">

阅读全帖
e******t
发帖数: 157
37
来自主题: Java版 - 新手问题
LZ看的是ORACLE网站上的教学材料. 在package部分有个例子. LZ吭吃吭吃该了
CLASSPATH什么的终于编译通过了, 试着运行了一下, SERVER可以运行, CLIENT说没有
MAIN什么的, 牛牛们帮忙看一下, 这程序能运行吗?
1)server.java
package mygame.server;
import java.io.*;
import java.net.*;
import mygame.client.Client;
import mygame.shared.Utilities;
public class Server {
public static void main(String args[]) {
ServerSocket serverSocket = null;
Utilities.printMsg("creating server socket");

try {
serverSocket = new ServerSocket(4444);
} catch (IOExceptio... 阅读全帖
S*******C
发帖数: 822
38
package com.cdd.jdbc;
import java.sql.*;
public class CreateConnection {
public Connection conn=null;
public ResultSet rs=null;
public Statement stmt=null;
public CreateConnection() { //构造方法
}
//获取数据库连接方法
public Connection getConnection() {
try {
Class.forName("com.mysql.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:mysql://mydbinstance.XXXXXXX.
us-east-1.rds.amazonaws.com:3306/db_database05","root","11111");
//不管用上... 阅读全帖
P********l
发帖数: 452
39
来自主题: Programming版 - Node做大系统better than Java, .NET
能展开说说吗?
我没觉得nodejs有actor的概念.比如: http://nodejs.org/api/fs.html
var fs = require('fs');
fs.unlink('/tmp/hello', function (err) {
if (err) throw err;
console.log('successfully deleted /tmp/hello');
});
另外能总结一下你给的那篇文章吗? 我真没觉得有什么. 我还以为他是new grad呢.
p*****2
发帖数: 21240
40
来自主题: Programming版 - 为什么大家不喜欢golang的switch?
同样docker的code, break, continue 都用到了。
func (z *Tokenizer) readRawOrRCDATA() {
if z.rawTag == "script" {
z.readScript()
z.textIsRaw = true
z.rawTag = ""
return
}
loop:
for {
c := z.readByte()
if z.err != nil {
break loop
}
if c != '<' {
continue loop
}
c = z.readByte()
if z.err != nil {
break loop
}
if c != '/' {
continue loop
}... 阅读全帖
p*****2
发帖数: 21240
41
来自主题: Programming版 - 为什么大家不喜欢golang的switch?

看看这个。用switch来处理error的。
https://code.google.com/p/go-wiki/wiki/Errors
switch err := err.(type) {
case ParseError:
PrintParseError(err)
}
p*****2
发帖数: 21240
42
来自主题: Programming版 - 为什么大家不喜欢golang的switch?
又一段code, http://www.goinggo.net/2014/10/error-handling-in-go-part-i.html
data, err := b.Peek(1)
if err != nil {
switch err {
case bufio.ErrNegativeCount:
// Do something specific.
return
case bufio.ErrBufferFull:
// Do something specific.
return
default:
// Do something generic.
return
}
}
f*****w
发帖数: 2602
43
来自主题: Programming版 - node.js错误求指点
代码如下
var DatabaseCleaner = require('database-cleaner');
beforeEach(function(done){
var databaseCleaner = new DatabaseCleaner('postgresql');
pg.connect(process.env.DATABASE_URL, function(err, client, done) {
databaseCleaner.clean(client, function() {
console.log('Done cleaning up');
client.query("INSERT XX XX XX", function(err, result) {
console.log('Done new record.' + err);
});
});
done();
});
});
怎么搞还是有这样的错... 阅读全帖
b***e
发帖数: 1419
44
来自主题: Programming版 - node.js错误求指点
/* This is what I guess you want. */
var DatabaseCleaner = require('database-cleaner');
beforeEach(function (done) {
var databaseCleaner = new DatabaseCleaner('postgresql');
pg.connect(process.env.DATABASE_URL, function (err, client, release) {
databaseCleaner.clean(client, function () {
console.log('Done cleaning up');
client.query("INSERT XX XX XX", function (err, result) {
release();
console.log('Done new record.' + err);... 阅读全帖
W***o
发帖数: 6519
45
来自主题: Programming版 - node 求算法
以前写过一个类似的,就是先找儿子,再给每个儿子找儿子:
var async = require('async');
var parentLaoWang = "Lao Wang"
if (parentLaoWang) {
var laoWangFamily = {"laoWang": []};
var findKidByParent = function(parent, callback) {
//findKidsByParent is a custom function on Kids collection
Kids.findKidsByParent(parent, function (err, foundKids) {
//foundKids is Array
if (foundKids) {
var currParentAndKids = {"parent" : parent, "kids" :
foundKids};
la... 阅读全帖
B****g
发帖数: 83
46
// ================================================
var spawn = require('child_process').spawn;
var async = require('async');
function spawnFunc(options, cb) {
var child = spawn(options.cmd, options.args, function);
var result = '';
child.stdout.on('data', function (data) {
// do some stuff with stdout data
result += data;
});
child.stderr.on('data', function (data) {
// do some stuff with stderr data
});
child.on('close', function (code) {
// error
if (code !==... 阅读全帖
d****n
发帖数: 1637
47
来自主题: Programming版 - Be $#%!ing explicit
Golang 的写法决定了很少需要用break point, 虽然我不认为不许要debugger,
但是实际coding过程中很少很少要用到。
就是因为这个成也萧何败也萧何的feature
if _, err:=MyFuction();err!=nil{
return nil, err
}
写起来好累,但是维护成本大大降低了。
w*s
发帖数: 7227
48
来自主题: Programming版 - Passport isAuthenticated() always returns TRUE
简化版的程序,logout, 按了back key后
isAuthenticated() 还说 "you are logged in".
var express = require('express');
var passport = require('passport');
var net = require('net');
var bodyParser = require('body-parser');
var http = require('http');
var multer = require('multer');
var cp = require('child_process');
var exec = require('child_process').exec;
var sys = require('sys');
var path = require('path');
var util = require('util');
var session = req... 阅读全帖
h******b
发帖数: 6055
49
来自主题: Programming版 - 十个包子求助:NodeJS多线程?
var directory = require('fs');
function processFile(filename) {
// dependencies
var fs = require('fs');
var zlib = require('zlib');
var csv = require('csv');
// filenames
var sourceFileName = filename;
mainFileName = 'main_' + filename;
// streams
var reader = fs.createReadStream(__dirname + '/original/' + sourceFileName),
writer = fs.createWriteStream(__dirname + '/transformed/' + mainFileName),
gunzip = zlib.createGunzip(),
gzip = zlib.createGzip();
//Main File
csv()
.from.stream(reader.pipe(g... 阅读全帖
w*s
发帖数: 7227
50
大牛,this is the best i can get,
How to improve it please, basically i'm lost in the callback for the 2nd one.
Also the db.close() is always called before the 2nd query finishes, even i
have serialize().
var getInfo1Db = function(callback) {
var db = new sqlite3.Database("DB.sqlite3");

var cnt = 0;
var info1JsonObj = [];
db.all("select * from Info1DB",
function(err, rows) {
db.serialize(function() {
for(var ii=0, len=rows.length; ii阅读全帖
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)