Posts

generics - Java passing Comparator to constructor -

if want pass constructor comparator can compare on 2 different types, should parameter of constructor this?: public myclass(comparator<?> comp) { this.comp = comp; } then comparator class: public namecomparator implements comparator<string> { @override public int compare(string s1, string s2) { return s1.compareto(s2); } } then whenever instantiate class do: myclass myclass = new myclass(new namecomparator()); is correct way go doing this? thanks edit: here's relevant code: public class bst<t> { /* binary search tree */ ... private comparator<t> c; /* pass in comparator constructor*/ public bst(comparator<t> c) { this.c = c; } comparator: public class namecomparator implements comparator<string> { @override public int compare(string s1, string s2) { return s2.compareto(s1); } } when creating bst: bst bst = new bst(new namecomparator()); your requirements seem bi...

c++ - C++11 regex::icase inconsistent behavior -

coming perl-like regular expressions, expected below code match regex'es in 8 cases. doesn't. missing? #include <iostream> #include <regex> #include <string> using namespace std; void check(const string& s, regex re) { cout << s << " : " << (regex_match(s, re) ? "match" : "nope") << endl; } int main() { regex re1 = regex("[a-f]+", regex::icase); check("aaa", re1); check("aaa", re1); check("fff", re1); check("fff", re1); regex re2 = regex("[a-f]+", regex::icase); check("aaa", re2); check("aaa", re2); check("fff", re2); check("fff", re2); } running gcc 5.2: $ g++ -std=c++11 test.cc -o test && ./test aaa : match aaa : match fff : nope fff : match aaa : match aaa : match fff : match fff : nope

Text manipulation in Python -

i have following list in python : [{"coefficient": -1.0, "compartment": "c", "molecule": "a", "evidence": []}, {"coefficient": -1.0, "compartment": "c", "molecule": "b", "evidence": []}, {"coefficient": -1.0, "compartment": "c", "molecule": "c", "evidence": []}, {"coefficient": 1.0, "compartment": "c", "molecule": "d", "evidence": []}, {"coefficient": 1.0, "compartment": "c", "molecule": "e", "evidence": []}, {"coefficient": 1.0, "compartment": "c", "molecule": "f", "evidence": []}] i want convert : a + b + c --> d + e + f which easiest way in python? the rules are: if coefficient negative, want treat co...

python - Sha256 returning incorrect hash values? -

i'm trying hash bitcoin private key checksum, , 2 different libraries in python (hashlib + pycrypto) returning same incorrect result (after 1 hash). in linux terminal, correct hash result line: echo -n 8018ac3e7343f016890c510e93f935261169d9e3f565436429830faf0934f4f8e4 | xxd -r -p | sha256sum -b result: cd358f378809b3043ded3782d849fbad70f92a2dadefafd985d9aef443752e57 however, hashlib, pycrypto, , online sha2 hash tool return value: 5d6dce0f36a50abe51ee435ac11dac05f7879c1cd1ca5bc7aae706e5a3776d4a i'm not sure why returning different values. here 2 wif-keys generated them, top 1 using command line function, second using python; second 1 invalid (not accepted wallet softwares). 5j19pgytjzus7voaqjxdjuggwxsnqj18gwswvfvqjzqqgtxzf2v 5j19pgytjzus7voaqjxdjuggwxsnqj18gwswvfvqjzqqgvdc8hm import hashlib print( hashlib.sha256("8018ac3e7343f016890c510e93f935261169d9e3f565436429830faf0934f4f8e4").hexdigest() ) print( hashlib.sha256("8018ac3e7...

service - Spring Boot app with embedded init.d script not starting on reboot -

spring boot has handy feature embed init.d starup script executable jar if configure maven plugin so: http://docs.spring.io/spring-boot/docs/current/reference/html/deployment-install.html#deployment-install so "installing" spring boot app (executable fat jar) service in centos 6.6 using above method. so far good. create link jar , set permissions: sudo ln -s /path/to/myapp.jar /etc/init.d/my-service sudo chmod 0755 /etc/init.d/my-service and can start application: sudo service my-service start however, want app come on startup, use chkconfig utility: sudo chkconfig --add my-service sudo chkconfig my-service on no errors commands, when reboot centos service not auto-start. running: sudo service my-service status shows: not running running: chkconfig --list my-service shows: my-service 0:off 1:off 2:on 3:on 4:on 5:on 6:off everything looks good, it's not starting. @ point can manually start service "sudo servi...

machine learning - Python/Keras/Theano wrong dimensions for Deep Autoencoder -

i'm trying follow deep autoencoder keras example . i'm getting dimension mismatch exception, life of me, can't figure out why. works when use 1 encoded dimension, not when stack them. exception: input 0 incompatible layer dense_18: expected shape=(none, 128), found shape=(none, 32)* the error on line decoder = model(input=encoded_input, output=decoder_layer(encoded_input)) from keras.layers import dense,input keras.models import model import numpy np # size of encoded representations encoding_dim = 32 #nput layer input_img = input(shape=(784,)) #encode layer # "encoded" encoded representation of input encoded = dense(encoding_dim*4, activation='relu')(input_img) encoded = dense(encoding_dim*2, activation='relu')(encoded) encoded = dense(encoding_dim, activation='relu')(encoded) #decoded layer # "decoded" lossy reconstruction of input decoded = dense(encoding_dim*2, activation='relu')(encode...

scala - how to get ClassTag[Long] from 10L -

using following code: val clz = 10l.getclass val classtag(clz) only boxed type: java.lang.long is there better solution? or impossible in scala? what makes think boxed? not: scala> classtag(10l.getclass).runtimeclass.getname res15: string = long scala> classtag(10l.getclass).runtimeclass == java.lang.long.type res17: boolean = true scala> classtag(10l.getclass).runtimeclass == new java.lang.long(10).getclass res18: boolean = false