st

Why can't enum constructors be protected or public in Java?

匿名 (未验证) 提交于 2019-12-03 03:10:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: The whole question is in the title. For example: enum enumTest { TYPE1(4.5, "string1"), TYPE2(2.79, "string2"); double num; String st; enumTest(double num, String st) { this.num = num; this.st = st; } } The constructor is fine with the default or private modifier, but gives me a compiler error if given the public or protected modifiers. 回答1: Think of Enums as a class with a finite number of instances. There can never be any different instances beside the ones you initially declare. Thus, you cannot have a public or protected constructor,

runST with Hindley-Milner type system

匿名 (未验证) 提交于 2019-12-03 02:56:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: If I understand the ST monad in Haskell correctly, runST uses rank-2 types in a clever way to ensure that a computation does not reference any other thread when escaping the monad. I have a toy language with a Hindley-Milner type system, and my question is the following: is it possible to extend the HM type system with an ad-hoc rule for typing runST applications so that the ST monad is safely escapable, without introducing rank-2 types? More precisely, runST would have type forall s a. ST s a -> a (i.e. rank-1) and the typing rule would

Example of State and Free monad in Scalaz

匿名 (未验证) 提交于 2019-12-03 02:52:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Can somebody give an example how to use ScalaZ Free monad ? For example, if I have a simple State function and want to apply it 10,000 times, I'd get StackOverflowError: def setS(i: Int) :State[List[Int], Unit] = State { l => ( i::l, () ) } val state = (1 to 10000).foldLeft( put(Nil :List[Int]) ) { case (st, i) => st.flatMap(_ => setS(i)) } state(Nil) As I understand, Free monad can help avoid this. How would I re-write this piece of code using Free monad to not cause stack overflow ? 回答1: As I say in a comment above, lifting the State

用python模拟登录淘宝并获取所有订单

醉酒当歌 提交于 2019-12-03 02:42:21
经过多次尝试,模拟登录淘宝终于成功了,实在是不容易,淘宝的登录加密和验证太复杂了,煞费苦心,在此写出来和大家一起分享,希望大家支持。 温馨提示 现在淘宝换成了滑块验证了,比较难解决这个问题,以下的代码没法用了,仅作学习参考研究之用吧。 本篇内容 1. python模拟登录淘宝网页 2. 获取登录用户的所有订单详情 3. 学会应对出现验证码的情况 4. 体会一下复杂的模拟登录机制 探索部分成果 1. 淘宝的密码用了AES加密算法,最终将密码转化为256位,在POST时,传输的是256位长度的密码。 2. 淘宝在登录时必须要输入验证码,在经过几次尝试失败后最终获取了验证码图片让用户手动输入来验证。 3. 淘宝另外有复杂且每天在变的 ua 加密算法,在程序中我们需要提前获取某一 ua 码才可进行模拟登录。 4. 在获取最后的登录 st 码时,历经了多次请求和正则表达式提取,且 st 码只可使用一次。 整体思路梳理 1. 手动到浏览器获取 ua 码以及 加密后的密码,只获取一次即可,一劳永逸。 2. 向登录界面发送登录请求,POST 一系列参数,包括 ua 码以及密码等等,获得响应,提取验证码图像。 3. 用户输入手动验证码,重新加入验证码数据再次用 POST 方式发出请求,获得响应,提取 J_Htoken。 4. 利用 J_Htoken 向 alipay 发出请求,获得响应,提取 st

Compute a confidence interval from sample data

匿名 (未验证) 提交于 2019-12-03 02:29:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have sample data which I would like to compute a confidence interval for, assuming a normal distribution. I have found and installed the numpy and scipy packages and have gotten numpy to return a mean and standard deviation (numpy.mean(data) with data being a list). Any advice on getting a sample confidence interval would be much appreciated. 回答1: import numpy as np import scipy as sp import scipy.stats def mean_confidence_interval(data, confidence=0.95): a = 1.0*np.array(data) n = len(a) m, se = np.mean(a), scipy.stats.sem(a) h = se * sp

Change system date programmatically

匿名 (未验证) 提交于 2019-12-03 02:05:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: How can I change the local system's date & time programmatically with C#? 回答1: Here is where I found the answer. I have reposted it here to improve clarity. Define this structure: [ StructLayout ( LayoutKind . Sequential )] public struct SYSTEMTIME { public short wYear ; public short wMonth ; public short wDayOfWeek ; public short wDay ; public short wHour ; public short wMinute ; public short wSecond ; public short wMilliseconds ; } Add the following extern method to your class: [ DllImport ( "kernel32.dll" , SetLastError = true )

Probability to z-score and vice versa in python

匿名 (未验证) 提交于 2019-12-03 01:58:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have numpy, statsmodel, pandas, and scipy(I think) How do I calculate the z score of a p-value and vice versa? For example if I have a p value of 0.95 I should get 1.96 in return. I saw some functions in scipy but they only run a z-test on a array. 回答1: >>> import scipy.stats as st >>> st.norm.ppf(.95) 1.6448536269514722 >>> st.norm.cdf(1.64) 0.94949741652589625 As other users noted, Python calculates left/lower-tail probabilities by default. If you want to determine the density points where 95% of the distribution is included, you have to

Allocating memory for a Structure in C

匿名 (未验证) 提交于 2019-12-03 01:58:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm tasked to create a program which dynamically allocates memory for a structure. normally we would use x=malloc(sizeof(int)*y); However, what do I use for a structure variable? I don't think its possible to do struct st x = malloc(sizeof(struct)); Could someone help me out? Thanks! 回答1: My favorite: #include struct st *x = malloc(sizeof *x); Note that: x must be a pointer no cast is required include appropriate header 回答2: You're not quite doing that right. struct st x is a structure, not a pointer. It's fine if you want to allocate one on

request stalled for a long time occasionally in chrome

匿名 (未验证) 提交于 2019-12-03 01:52:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Ajax request occasionally stalled for a long time in chrome. I finally managed to reproduced it and save all related data necessary to post here if anyone could help me out. The timeline from Chrome Dev Tool shows the request stalled for 42.62s as the following screen capture shows: and within the chrome://net-internals/#events (for the events log please head to the end) page I found the most time is cost by two events: +HTTP_TRANSACTION_READ_HEADERS [dt=21301] +HTTP_TRANSACTION_READ_HEADERS [dt=21304] both get ERR_CONNECTION_RESET . I think