Posts

Showing posts from July, 2012

python - Ineq and eq constraints with scipy.optimize.minimize() -

i attempting understand behavior of constraints in scipy.optimize.minimize : first, create 4 assets , 100 scenarios of returns. average returning funds in order best worse d > b > > c #seed first np.random.seed(1) df_returns = pd.dataframe(np.random.rand(100,4) - 0.25, columns =list('abcd')) df_returns.head() b c d 0 0.167022 0.470324 -0.249886 0.052333 1 -0.103244 -0.157661 -0.063740 0.095561 2 0.146767 0.288817 0.169195 0.435220 3 -0.045548 0.628117 -0.222612 0.420468 4 0.167305 0.308690 -0.109613 -0.051899 and set of weights weights = pd.series([0.25, 0.25, 0.25, 0.25], index=list('abcd')) 0 0.25 b 0.25 c 0.25 d 0.25 we create objective function: def returns_objective_function(weights, df_returns): result = -1. * (df_returns * weights).mean().sum() return result and constraints , bounds cons = ({'type': 'eq', 'fun&

httprequest - Get referrer URL with parameters in Rails -

i have site basic rails scaffold, when user deletes record default action redirect home page. return list user looking at. right i'm using request.referrer technically getting referral url parameters not included... in rails logs can see "started /books/book_preview?name=hunger+games" request.referrer shows " https://x.x.x.x/books " have tried .original_url , .original_fullpath return path of current page record "/books/hungergames". tried uri(request.referrer).query @ least parameters threw error. previous path parameters like: /books/books_preview?name=hunger+games also list remote partial rendered through js. can't see url in browser url bar when highlight on or in rails logs. doesn't show in request when looked through using request.inspect . thanks in advance help! have been stuck on day! you're not getting query string url, according this answer (& docs ), need: request.fullpath #-> book_preview?na

android - Cannot find method onClick in the Activity even though it is there -

i have made button: <button android:id="@+id/btn_dialog" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/showdig" android:onclick="onclick" /> and onclick method in main activity public void onclick(view v){ log.d("click test", "log"); this.showdialog(0); } but when click button get: 03-12 16:37:24.995: e/androidruntime(755): fatal exception: main 03-12 16:37:24.995: e/androidruntime(755): java.lang.illegalstateexception: not find method onclick(view) in activity class com.example.telefon.mainactivity onclick handler on view class android.widget.button id 'btn_dialog' 03-12 16:37:24.995: e/androidruntime(755): @ android.view.view$1.onclick(view.java:2670) 03-12 16:37:24.995: e/androidruntime(755): @ android.view.view.performclick(view.java:3110) 03-12 16:37:24.995: e/a

php - Implement secure login in Codeigniter test with Wireshark -

today try test website build codeigniter. try check using wireshark (for network administrator). in traffic, still see username , password login. maybe ideas solve problem. maybe else have problem too. here controller public function val() { $this->form(); if($this->form_validation->run()==false) { $this->load->view('form_login_val'); }else { $username = $this->input->post('username'); $password = $this->input->post('password'); $cek = $this->m_login->takevalidator($username, $password ); if($cek <> 0) { $this->session->set_userdata('validator_status', true); redirect('home/validate'); } else { $this->session->set_flashdata('gagal_login', "username atau password yang anda masukkan salah

Do-while loop to erase cells with certain values in Excel -

i want delete cells have '+' , '-' in d column. i've tried following macro, thought work, nothing happens. sub dowhile4() 'replace blank spaces underscores in range of cells, using vba loops; or 'remove blank spaces in range of cells, using vba loops. dim icell range dim textstring string dim n integer 'icell cell in specified range contains textstring 'textstring text in cell in blank spaces replaced 'underscores. n position of blank space(s) occurring in textstring each icell in activesheet.range("d2:d34") textstring = icell n = instr(textstring, "+") 'the vba instr function returns position of first occurrence of string within 'another string. using determine position of first blank space in 'textstring. while n > 0 textstring = left(textstring, n - 1) & right(textstring, len(textstring) - n) 'this line of code remove blank spaces in

hibernate - onetomany unidirectional with jointable setup using jpa -

i have 2 entities namely customer , order in onetomany relationship. 1 customer can have multiple orders. since needed relationship unidirectional, using jointable. i able add entries customer entity using jpa. able add entries order entity using jpa. i wondering how connect 2 data. let's have 1 entry in customer table , 2 entries in order table. associate these 2 entries in order table 1 entry in customer table. currently, don't see entries in jointable customer_order. how make association? guess while adding orders order table, have mention customer id number somehow. not sure how that. there criteria query in jpa? thanks. customer class - @entity public class customer implements serializable { @id @generatedvalue(strategy = generationtype.table, generator = "generatorcustomer") @tablegenerator(name = "generatorcustomer", allocationsize = 1) @column(name="customer_id") private long id; public long getid() {

r - Color mismatch using rgl -

i using rgl create scatterplot of points imported .csv dataset. colors i'd points set in dataset. works fine, except when scatterplot displayed colors of points not match colors defined in data. e.g., points designated "blue" might green, , points designated "yellow" might show red. data=read.csv("explayout.csv", header = true) x=data$x y=data$y z=data$z color=data$color plot3d(x=x, y=y, z=z, type="s", col=color) this due read.csv converting strings factors see difference in reproducible example library(rgl) x<-1:5 y=1:5 z <- 1:5 colors <- c('red','green','blue','orange','purple') plot3d(x=x,y=y,z=z,col=colors, type = 's') colorsf <- factor(c('red','green','blue','orange','purple')) plot3d(x=x,y=y,z=z,col=colorsf, type = 's') so, either read in color character column using stringsasfactors=false or coerce char

android - "Layout or its parent is useless". How to avoid this? -

Image
i have 2 bordered textviews center vertically , horizontally, side side shown in following image: on top of each of these 2 textviews, have add 't' textview on bottom left , unit on bottom right ('uv/m'). end following layout xml code: <linearlayout android:id="@+id/layout_small_rectancle" android:layout_width="match_parent" android:layout_height="@dimen/drv3lite_small_rectangle_height" android:baselinealigned="false" android:layout_centervertical="true" android:orientation="horizontal" > <!-- small rectangles. defines whole width --> <relativelayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:orientation="vertical" > <!-- small rectangle (left) --> <relati

xamarin - Mvvmcross Android - Error Inflating Class: ClassNotFoundException -

i getting error in onviewmodelset() function when trying inflate xml file. when calling layoutinflater inflater = layoutinflater.from(this); view mainview = inflater.inflate(resource.layout.main, null); i getting "java.lang.classnotfoundexception: mvx.mvxbindablelistview" here whole exception: android.views.inflateexception: binary xml file line #1: error inflating class mvx.mvxbindablelistview @ android.runtime.jnienv.callobjectmethod (intptr,intptr,android.runtime.jvalue[]) [0x00024] in /users/builder/data/lanes/monodroid-lion-bigsplash/0e0e51f9/source/monodroid/src/mono.android/src/runtime/jnienv.g.cs:145 @ android.views.layoutinflater.inflate (int,android.views.viewgroup) [0x0003e] in /users/builder/data/lanes/monodroid-lion-bigsplash/0e0e51f9/source/monodroid/src/mono.android/platforms/android-12/src/generated/android.views.layoutinflater.cs:543 @ androidcornerstonemobile.mainview.onviewmodelset () [0x00010] in c:\users\david\documents\work\androidxamar

Website Loading Problems -

so have website, tildetictac.atwebpages.com gives me unable connect error when access pc on mediacom wifi, can access fine phone, on verizon 4g lte. able access site last night. i error message: connection has timed out the server @ tildetictac.atwebpages.com taking long respond. the site temporarily unavailable or busy. try again in few moments. if unable load pages, check computer's network connection. if computer or network protected firewall or proxy, make sure firefox permitted access web. and dashboard hosting provider says good, there no firewall on site , plain ole windows defender on pc. there no firewalls on phone. i'm not sure how diagnose problem. error message vague, every other website works fine both computer , phone. there unique problems websites using free subdomains? hosting company reputable , says site fine doubt problem on there side, have tried multiple browsers on pc , don't have besides default browser settings. , websites ge

postgresql - What's the "E" before a Postgres string? -

i reading postgres/postgis statement this: select st_asbinary( st_geomfromwkb( e'\\001\\001\\000\\000\\000\\321\\256b\\312o\\304q\\300\\347\\030\\220\\275\\336%e@', 4326 ) ); the above creates known binary (wkb). haven't seen specific way of quoting here string single quoted e preceding beginning quote. what format called? , formatting rules this? e.g. 336%e@ @ end special or binary value? this postgres9.3/9.4; postgis 2.1. as per postgresql documentation http://www.postgresql.org/docs/9.0/static/sql-syntax-lexical.html (emphasis mine) postgresql accepts "escape" string constants, extension sql standard. an escape string constant specified writing letter e (upper or lower case) before opening single quote , e.g., e'foo'. (when continuing escape string constant across lines, write e before first opening quote.) within escape string, backslash character () begins c-like backslash escape sequence, in combination of backslash

java - Running Threads on a File Method -

hi try run thread on "threadedsort", can not use traditional void run method because returns void. tried using synchronised method don't think made difference...same reentrant method, don't know i'm doing wrong. private static string[] getdatathread(file file) throws ioexception { arraylist<string> data = new arraylist<string>(); bufferedreader in = new bufferedreader(new filereader(file)); // read data file until end of file reached while (true) { string line = in.readline(); if (line == null) { // end of file reached break; } else { //synchronized(line){ lock.lock(); try{ data.add(line); }finally{ lock.unlock(); } //} } } //close

html - How to put two div boxes side by side -

Image
so i'm quite new writing codes(about few weeks) , i've hit wall while writing codes website. want have layout such this can't figure out how put 2 boxes side side(one box video explaining website, other box sign registration form.) want them next each other, inch separation between boxes. i need width of website? right looks header doesn't fit on page, causing horizontal scroll. kinda want entire website looks 1 big box, , want content inside box. can please me? appreciated. thank in advance. it's quite simple: http://jsfiddle.net/kkobold/qmql5/ <div id="header"></div> <div id="container"> <div id="first"></div> <div id="second"></div> <div id="clear"></div> </div> -- #header { width: 100%; background-color: red; height: 30px; } #container { width: 300px; background-color: #ffcc33; margin: aut

Explanation needed for this Ruby challenge -

i need understanding code: def simpleadding(num) sum = 0 (num + 1).times |x| sum = sum + x end return sum end simpleadding(12) #=> 78 simpleadding(140) #=> 9870 i not sure of method. why method written way is? why sum on first line set 0 ? , why sum = sum + x used on third line? in ruby, def keyword delimits start of method , in case named simpleadding . takes 1 argument (in parentheses) named num . in method body, variable sum given initial value of 0 . the line containing (num + 1).times |x| tells ruby execute code between do , end keywords set number of times (an iterator ), in case num + 1 . remember, num represents value received in form of argument when method called. on next line, variable sum (initialized 0 @ beginning of method) assigned value of plus x . next line, our iterator end s. finally, return value stored inside of variable sum . and, end of our method. enjoy learning ruby!

templates - C++ argument should be passed by value, but compiler sees it as reference -

so weird behaviour not understand. have: template <typename t> node node::apply() { return ptr->graph->derived_node(std::make_shared<t>(ptr->graph, this)); } template <typename t> node apply(node parent1, node parent2){ graphinptr graph = parent1.ptr->graph; return graph->derived_node(std::make_shared<t>(graph, parent1, parent2)); } template <typename t> node apply(nodevec parents){ graphinptr graph = parents[0].ptr->graph; return graph->derived_node(std::make_shared<t>(graph, parents)); } i have this: node gt(node node1, node node2){ return apply<greaterthan>(node1, node2); } however, here compiles error: node node::gt(node node) { return apply<greaterthan>(node(this), node); } the error is: error: no matching function call ‘metadiff::node::apply(metadiff::node, metadiff::node&)’ return apply<greaterthan>(node(this), node); note: candidate is: n

android - Skipping an activity in a sequence of activities (including a facebook activity) -

i creating android app action bar sherlock library. action bar has 3 tabs, 1 tab requires user login via facebook. there 3 activities in login process: step 1 - user clicks on image button (facebook) in 1 of action bar tabs, calls facebook login activity. step 2 - facebook login activity shows facebook web view, stores users details in shared preferences , calls final activity step 3 - final activity displays data belonging user , user can logout activity. question: is possible skip activity when going i.e if user in final step (3) when press button go step 1. step 2 not in sequence when user has logged in. and in addition possible skip step 1 - step 3 if user has logged in? i've thought of overriding button in step 3 wanted concrete thoughts on i'm still new android. if situation have overridden onbackpressed method or can try hoan nguyen's solution. if user has logged in can check access token in shared preferences(if have stored on successf

How to Count Children Nodes on Javascript Fancytree? -

Image
i created category tree using fancytree drag & drop functionality like now, want set limit child node. if parent node have 3 child node not able create new child not example category parent category child category allowed child category allowed child category not allowed move like create javascript this. dragdrop: function(node, data) { if( node.getlevel() >= 3 ){ return false; } console.log( node ); console.log( data ); var parentnodekey = node.key; var sourcenode = $(data.helper).data("ftsourcenode"); if( !data.othernode ){ var title = $(data.draggable.element).text() + " (" + (count)++ + ")"; node.addnode({title: title}, data.hitmode); return; } data.othernode.moveto(node, data.hitmode); } this working fine when move single category. not working when move "moved node" category because category have 2 child node , child node have 2 child nodes like i move "moved node" , workin

Using non-variable in file path -

i want make file path changeable user. far can tell has static in order so. here got. private string texturepath; more code... public string gettexturepath() { return (string)texturepath; } public void onupdate() { super.onupdate(); this.texture = "/adventure/" + this.gettexturepath() + ".png"; } there multiple objects, , when using static variable changed of theirs same, without being able change them individuality. you need send parameter method. public void onupdate(string path){ super.onupdate(); this.texture = path + this.gettexturepath() + ".png"; } static vars belong class, not instances.

android - Coordinator Layout with RecyclerView -

i using coordinatorlayout recyclerview .the app runs fine problem the view should scroll items in recyclerview .in case have 3 items cordinatorlayout scroll recyclerview till snap top because of getting below part white listsize 3. xml <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.design.widget.coordinatorlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.design.widget.appbarlayout android:id="@+id/app_bar_layout" android:layout_width="match_parent" andro

horizontal scrolling - How to swipe pdf pages horizontally in android using MuPDF library -

i have built mupdf source following these steps http://www.mupdf.com/docs/how-to-build-mupdf-for-android . have integrated in app , working fine. in page scroll vertically want scroll horizontally. please me possible or not , if possible give me hint or if other solution thanks. you can use mupdfpageview instead of mupdfreaderview , manage horizontal scroll manually.

mysql - select last record in each group for large database -

i want fetch last record in each group. have used following query small database , works - select * logs id in ( select max(id) logs id_search_option = 31 group items_id ) order id desc but when comes actual database having millions of rows ( 80,00000+ rows ), system gets hanged. i tried query, gives result in 6.6sec on average -- select p1.id, p1.itemtype, p1.items_id, p1.date_mod logs p1 inner join ( select max(id) max_id, itemtype, items_id, date_mod logs id_search_option = 31 group items_id) p2 on (p1.id = p2.max_id) order p1.items_id desc; please ! edit:: explain 2nd query id select_type table type possible_keys key key_len ref rows 1 primary <derived2> null null null null 1177 using temporary; using filesort 1 primary p1 eq_ref primary primary 4 p2.max_id 1 2 derived logs

Upload image path to server android json -

i have tried lot of examples , watched many videos , done stackoverflow, not getting want. 1] want upload image path server . 2] php query required image of type file, cant send string. need upload image file path. know how send string , decode image.but have no idea how send image file path , image. plz me this,i in big trouble. things have tried : private static final int pick_from_camera = 1; private static final int pick_from_file = 2; private string imgpath = null; private uri mimagecaptureuri; private string encodedimage; @override public void onclick(view v) { // onregisterbuttonclick(); imgpath = null; intent intent = new intent(); intent.settype("image/*"); intent.setaction(intent.action_pick); startactivityforresult( intent.createchooser(intent, "complete action using"), pick_from_f

string - What does strcmp() exactly return in C? -

i wrote code in c: #include <stdio.h> #include <stdlib.h> #include <math.h> #include <string.h> int main() { char string1[20]; char string2[20]; strcpy(string1, "heloooo"); strcpy(string2, "helloo"); printf("%d", strcmp(string1, string2)); return(0); } should console print value 1 or difference between ascii values of o , \0 character i.e. 111? on this website , written should give out put 111, when run on laptop, shows 1. why? from the cppreference.com documentation int strcmp( const char *lhs, const char *rhs ); return value negative value if lhs appears before rhs in lexicographical order. zero if lhs , rhs compare equal. positive value if lhs appears after rhs in lexicographical order. as can see says negative, 0 or positive. can't count on else. the site linked isn't incorrect. tells return value < 0 , == 0 or > 0 , gives example , show

c - Executing a Stopped Process in XV6 -

i wrote 2 new system calls , add them xv6 os kernel. using 1 system call can save process state , using other 1 can reload previous state , continue. problem in reloading section . is enough reload context of process ? (i mean struct context contains cpu register) no. the process may have open files , pipes in proc->ofile , need save/load. note time re-load process, parent may no longer exist. you'll want make sure process isn't floating around without real parent, or you'll in fun bugs.

virtualhost - What values are valid for use with ServerName when setting up Apache virtual hosts locally? -

i'm setting apache virtual hosts number of websites need develop on localhost. using following configuration (and after updating /etc/hosts file), can access content stored @ /var/www/example.com/public_html going example.com in web browser: <virtualhost *:80> servername example.com documentroot /var/www/example.com/public_html ... </virtualhost> my question: are there rules choosing values servername ? example, must value use domain name such servername example.com or can omit .com extension , use servername example ? must use lowercase characters, etc.? you can use whatever name want local domain. @ documentation . servername apache servername [scheme://]fully-qualified-domain-name[:port] servername directive sets request scheme, hostname , port thatthe server uses identify itself. used when creating redirection urls.

jquery - Javascript works before turned into a wordpress template -

so tested theme static html/css/js before turning wordpress theme , worked perfectly. it's on wordpress it's throwing error in js file (line 593): uncaught typeerror: cannot set property 'mynode' of undefined directly after line //add data mindmap var root = $('body>ul>li').get(0).mynode = $('body').addrootnode($('body>ul>li>a').text(), { here full js. haven't changed since uploading , making theme wordpress. it came here: https://github.com/kennethkufluk/js-mindmap any ideas? new js/jquery still :) thanks!!! (function ($) { 'use strict'; var timeout = 4, // movement timeout in seconds centre_force = 3, // strength of attraction centre active node node, line; // define node related functions. node = function (obj, name, parent, opts) { this.obj = obj; this.options = obj.options; this.name = name; this.href = opts.href;

database design - Django model relations how to make it optional -

models.py : class time(models.model): id = models.autofield(primary_key=true) who= models.textfield(db_column='who') class task(models.model): id = models.autofield(primary_key=true) when= models.foreignkey(time) i need record time , task problem there can be: 1) time without task, 2) task without time, 3) time multiple task i've tried adding foreignkey task null , blank = true django says "foreignkey can't null" are there other way make " optional " relation? when = models.foreignkey(time, default=none, blank=true, null=true) and make new migration change schema: python manage.py makemigrations python manage.py migrate you getting foreignkey can't null because schema doesnot allow fk null

How to judge whether two addresses are in same page or not in Windows? -

specifically, if @ different time, read addresses pointed esp register(containing stack top address), how judge 2 addresses in same page or not? believe these addresses physical addresses rather virtual addresses,right?the 2 readings might come different processes. how windows page allocation? added:maybe got it. if use 4kb page, mean addresses 0x....xxxx0000 0x....xxxx1000 in same page? you got right. idea sound, range 0x????0000 0x????0fff . if use dword_ptr or ulong_ptr mask out lower 12bit (ptr & 0xfff) , compare 2 pointer values got. ulong_ptr , dword_ptr should work both on x64 , x86. keep in mind system using huge pages. make sure use getnativesysteminfo and/or getsysteminfo respectively. looking value of dwallocationgranularity in system_info structure. all of true within same process memory space only . concerning question physical addresses: no , repeat no , user mode process gets see actual physical addresses unless driver or kernel screws

javascript - i am getting issue in changing inner html of div -

guys found problem in changing html of div please me document.getelementsbyclassname("lab")[0].setattribute("ng-bind-html", "binds"); $scope.binds="<h1>run</h1>"; i setting attribute ng-bind-html in java script because have have integrated plugin in code in div of class="lab" getting declared through javascript . attribute binds attached checked in inspect element. in fact when ever attached property of ng-bind-html in javascript ng-bind-html not work correct way it. ther no error in code. me please basically have added ng-bind-html attribute dynamically, add directive attribute dom ng-bind-html directive wouldn't evaluated html content. need recompile dom using $compile(document.getelementsbyclassname("lab")[0])($scope) to making sure should work need add ngsanitize module in angular app. demo plunkr the way doing not standard way of doing dom manipulation in angularjs. s