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... 阅读全帖
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"... 阅读全帖
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.
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.
【 以下文字转载自 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... 阅读全帖
这是一个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... 阅读全帖
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... 阅读全帖
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... 阅读全帖
【 以下文字转载自 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... 阅读全帖
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(... 阅读全帖
【 以下文字转载自 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... 阅读全帖
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
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
谢谢。。找了点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() ... 阅读全帖
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:
... 阅读全帖
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
/**
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) {
... 阅读全帖
我本来也不信,上周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... 阅读全帖
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");
//不管用上... 阅读全帖
终于做出来了,这题用来刷掉三哥效果最好
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... 阅读全帖
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");
//不管用上... 阅读全帖
/* 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);... 阅读全帖
以前写过一个类似的,就是先找儿子,再给每个儿子找儿子:
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... 阅读全帖
// ================================================
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 !==... 阅读全帖
简化版的程序,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... 阅读全帖
大牛,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阅读全帖