Posts

Showing posts from August, 2010

How do I write a shorthand for a datatype in Scala -

how write shorthand datatype? example. lets instead of list[integer] , rather type integers instead of this def processnumbers(input:list[integer]):list[integer] = ... to def processnumbers(input:integers):integers = ... is possible? thanks yes, can type alias . type integers = list[int] // scala.int preferred on java.lang.integer that being said, isn't use them. list[int] clear other scala developers, wheres type integers provides no information , detract readability of code on time. a use of type aliases improve code's readability though like type userid = int def processusers(ids: list[userid]): foo in case provides information reader vs def processusers(ids: list[int]): foo using kind of type alias allow gradually make code more type-safe on time changing definition type alias value class . case class userid(value: int) extends anyval you won't need change method signatures of having " userid ", let compiler assi

laravel - jQuery datatable with BelongsToMany relationship -

Image
i using https://github.com/yajra/laravel-datatables library integrate datatable laravel. so have query: public function query() { $query = auth::user()->cars_as_dispatcher()->wherein('status', [3, 4, 5])->orderby('missions.id', 'desc'); return $this->applyscopes($query); } with relation: public function cars_as_dispatcher() { return $this->belongstomany('app\car', 'dispatcher_cars', 'uid', 'car_id')->withtimestamps(); } the error is: column exists: 1060 duplicate column name 'id' because query return 2 id columns: how can solve this?

Android, Update app classes on the fly -

how can update classes in android (for example injecting classes want special port app)? or @ least make update patch user have not download whole app. you can not update app classes on fly. all application classes bundled in apk file, , can not apply patch in apk file. you need build separate new apk file if want provide patch or change class file.

How to suppress output to stderr in a clojure program -

i want produce command line version of clojure library using clojure/tools.cli , lein bin. works fine except getting output stderr when run script. particular library has functions override basic functions, naturally there warnings when clojure code compiled. know bad idea after careful consideration in case believe best way go. how stop these messages appearing every time run script? i added slf4j-nop dependencies recommended in monger documentation suppress unwanted messages monger, , works, has no effect on warnings clojure compiler. i have tried using slf4j-log detailed here: suppress output `clojure.tools.logging` without success. here of code: project.clj (defproject image-search "0.1.0-snapshot" :description "search images containing specific metadata" :url "http://github.com/soulflyer/image-search" :license {:name "eclipse public license" :url "http://www.eclipse.org/legal/epl-v10.html"} :dependenc

plugins - Gradle Configuration of pluginRepository -

i trying simple gradle project (the 1 created eclipse automatically) static code analysis made sonar run on our continuous integration. our ci server behind proxy , have access gradle plugin repository on internal nexus server. as described in userguide have added following settings.gradle pluginrepositories { maven { url 'http://link.to.my.nexus' } gradlepluginportal() } rootproject.name = 'gradletestproject' my build.gradle looks this: plugins { id "org.sonarqube" version "2.0.1" } apply plugin: 'java' repositories { mavenlocal() mavencentral() } dependencies { compile 'org.slf4j:slf4j-api:1.7.21' testcompile 'junit:junit:4.12' } when run on jenkins, following error message: failure: build failed exception. * where: settings file '/opt/hudson/jobs/gradletestproject/workspace/settings.gradle' line: 1 * went wrong: problem occurred evaluating settings 'workspace&#

angularjs - After element.replaceWith(contents) how can go back to the original code -

i have problem when replace element html don't know how go original code before replacement. here code. http://jsfiddle.net/mahmoudbay/o166xg0s/94/ here controller. angular.module('app', []) .controller('myctrl', function($scope) { $scope.checked = true; }) .directive('ngbatchif', function($compile) { return { restrict: 'a', scope: { check: '@' }, controller: function($scope) {}, link: { pre: function(scope, elm, attrs) { attrs.$observe('check', function() { // after flattening, angular still have first element // bound old scope, create temporary marker // store var contents = elm.contents(); if (scope.check === "true") { console.log(scope.check); } else { console.log(scope.check); elm.replacewith(contents); } }) } } } }); thank you.

algorithm - probabilty of a point inside a non-convex polygon such that all rays coming from that point combinedly hit all sides of the polygon -

like in image rays coming point p cannot hit side ae directly point p not satisfy condition probability of point inside non-convex polygon such rays coming point combinedly hits sides of polygon. if polygon convex think rays coming point inside polygon combinedly hit sides . interested in knowing concave polygon case. we given coordinates of vertex of polygon. the set of points reach edges of polygon called visibility kernel. the kernel intersection of half planes on left of edges. simple polygon, can computed in linear time o(n). if points drawn uniformly inside polygon, probability ratio of area of kernel of polygon. kernel can empty, hence probability zero. convex polygons one.

matlab - padding the 3D images for deformation -

i trying pad 3d image deformation process. want know if padding 3d images of dimension 256*256*150 , after applying padding dimension become 656*656*150 . should try pad third dimension i.e 150 before applying process on padded image? i using matlab padding mask_im=padarray(image_mask,[2*window_size_pad 2*window_size_pad],'both'); if necessary pad third dimension , should use pad ..i have seen matlab pad array dimension , doesn't third dimension. if apply rotation along third axis, no need pad third dimension... should pad every dimension wish apply frequency domain transform. best way pad them permute axis b = permute(a,[1,3,2]) pad, permute a = permute(b,[1,3,2])

Can`t create database in SQL Server 2012 Management Studio -

Image
havent used ssms in while, today tried make new database , got error: i tried running admin, tried security > logins > myaccount > server roles > checked : sysadmin, dbcreator , still getting error. edit: how im trying add new db: check server properties -- > database settings -- > database default locations --> data , log path. reason : data , log path pointed doesn't exist or full rights not given path. solution : specify correct data , log path or give full rights folder , try create database.it should work. below link :- https://support.microsoft.com/en-us/kb/836873

Tensorflow NN with specific custom cost function -

i'm trying make neural network in tensorflow doesn't belong in classification of regression categories. it's closer reinforcement learning. i've made network few relu hidden layers ends in 3-element softmax output layer. target vectors each sample rewards (can negative penalty or 0 neutral) making choice (of there 3). idea maximize summed reward on samples. given 1 sample input mapped model output m=[a,b,c] targets y=[d,e,f]; loss specific sample m*y', or -tf.matmul(model, y, transpose_b=true). when working batches resulting in matrices in stead of vectors, i'm @ loss (heh) how express cost-function in way tensorflow's optimizers can use. using example code above yield meaningless batchsize^2-sized matrix. how can this? let's have output of model mini-batch of n examples, call output . have shape [n, 1, 3] . (note : typically, output of softmax have shape [n, 3] , can use tf.reshape reshape [n, 1, 3] ). call rewards or targets target

android - ffmpeg hls with aes encryption -

i trying create encrypted hls stream using ffmpeg. i've seen other questions related this. i've created video.key file following content: 12345678901234567890123456789011 i've created key_info file following contents: http://10.10.102.223:59164/trial/video.key video.key i have mp4 file : jellies.mp4 , trying transcode , encrypt using ffmpeg -i jellies.mp4 -hls_time 5 -hls_key_info_file key_info playlist.m3u8 after done transcoding put folder on server , tried access on client android app. the app contains videoview url fed. , believe decryption done automatically. but app not working . shows following errors: e/mediaplayer: error (1, -1007) after tried transcoding again ,this time without encryption ,using: ffmpeg -i jellies.mp4 -hls_time 5 playlist.m3u8 this played on app. using packet capture i'm able see various packets sent , received . and key being received perfectly. then why stream not working. is because didn't encrypt ?

java - Hibernate JPA ManyToOne foreign key mapping with composite key via IdClass does not find columns -

i trying resolve issue database mapping in our application using hibernate. annotate classes using jpa , far successful. however, want introduce composite key unique string identifying customer string identifying database entry. set compound key, use idclass called mandtid.java . however, seems our mapping not work can not find column join on other side. here snippets of code show our annotations: mandtid.java @suppresswarnings("serial") @embeddable public class mandtid implements serializable { private string mandt; private string id; public mandtid() { } public mandtid(string mandt, string id) { this.mandt = mandt; this.id = id; } public string getid() { return id; } public string getmandt() { return mandt; } public void setid(string x) { id = x; } public void setmandt(string x) { mandt = x; } /* (non-javadoc) * @see java.lang.object#hashcode() */ @override public int hashcode() { int hashcode = 0; if (mandt != null)

javascript - Angular-Messages sometimes aren't shown when used with Angular-Material -

i using angular-messages angular-material v1.0.9. have md-dialog inside have form fields created ng-repeat : <form name="modal.dynamicform" flex="80" layout="column"> <md-input-container ng-repeat="field in modal.model.fields"> <ng-form name="innerform"> <label>{{ field.label }}*</label> <input type="text" ng-model="field.value" name="{{ field.name }}" ng-pattern="field.pattern" required /> <div ng-messages="innerform[field.name].$error"> <div ng-message="required">{{ 'fieldrequired' | translate }}</div> <div ng-message="pattern">{{ field.patternerror }}</div> </div> </ng-form> </md-input-container> </form> angular-messages used display form errors. problem whe

mysql - creating class active dynamically in php -

i creating menu dynamically based on categories registered on database, need is: when click in link, option should have css class 'active', showing in page user , pages created dynamically. have no idea how because php student , couldn't find information in google "dynamically menus" thank much. <nav class="menu"> <ul class="list"> <li class="line"><a id="item" href="index.php">home</a></li> <?php $categories = $db->select("select * tbl_category"); if($categories){ while ($result = $categories->fetch_assoc()){ echo <<<html <li id="line" ><a class="item" href="categories.php?category=$result[id]">$result[name]</a></li> html; } } ?> </ul> <nav> first of all, you're lo

javascript - Attribute selected option into a variable to show input field using SQL -

Image
i need attribute selected value dropdown list variable can use in sql query. i know have use ajax or jquery can't because don't learn yet picture 1 : picture 2 : <!-- début php catégories --> <?php $rescat=mysqli_query($conne,$reqcat); ?> <div class="form-group"> <label class="col-md-3 control-label">catégorie</label> <div class="col-md-9"> <select class="form-control select" name="categorie" id="categorie" "> <?php while ($rowcat= mysqli_fetch_row($rescat)) { ?> <option value="<?php echo $rowcat[1] ?>"><?php echo $rowcat[0] ?></option> <?php } $categorie = $_post['categorie']; ?> </select> </div> </div> <!-- fin php catégories --> thanks for case can use form , when va

windows - how to make my scripts portable vbs -

this noob question..but want make scripts more portable. lets say, have coded .vbs(or script in code of nature) in usb. want run vbs on current machine. usb assigned in f: drive however when unplugged usb , sticked machine..it going no longer f:..but e: g: or whatever i wanted know how overcome without changing directly on scripts script capable of reading directory pointing toward. im not sure how property/functionality called. but appreciate hints/tips there 2 main ways can make script more portable. the first, , appropriate use case, check drive executable running on using wscript.scriptfullname , getting first 3 characters find drive letter. alternatively chop script name ( wscript.scriptname ) off end find current working directory. assign variable, , use everywhere in code specify path. dim fullname : fullname = wscript.scriptfullname dim drive : drive = mid(fullname, 1, 3) dim path : path = mid(fullname, 1, len(fullname) - len(wscript.scriptname)) wscri

java - Change Button custom shape states color programatically -

there lot of answers on site regarding changing button colors, none have managed use in case. i want able dynamically change button's color, button still needs have visual feedback on press, , needs rounded corners. the rounded corners part decided upon recently, used : statelistdrawable states = new statelistdrawable(); states.addstate(new int[]{android.r.attr.state_pressed}, new colordrawable(hsvdarkencolor(theme.get_buttonsbgcolor()))); states.addstate(new int[]{android.r.attr.state_focused}, new colordrawable(hsvdarkencolor(theme.get_buttonsbgcolor()))); states.addstate(new int[]{}, new colordrawable(color.parsecolor(theme.get_buttonsbgcolor()))); ((button) button).setbackgrounddrawable(states); //this focused/pressed state of button private static int hsvdarkencolor(string originalcolor) { float[] hsv = new float[3]; int color = color.parsecolor(originalcolor); col

visual studio 2015 - "Changes are not allowed while code is running" -

i going , forth between code in visual studio 2015 , browser. when forget turn off debugger before trying make edits error: changes not allowed while code running. it comes annoying bleep sound , popup. there way make go away , have visual studio stop code automatically when sees trying make edits? it's fine, click ok, manually stop code , try edits again. problem when on stubborn piece of code doesn't want work , going , forth forget stop code. @ point frustrated because of code , stupid popup bleep sound enough send me rage of cursing.

xml - xsl:copy-of : could not compile select expression -

i trying transform xml file using xsl stylesheet. xml file <?xml version="1.0" encoding="utf-8"?> <msg> <ent key="key1"> <text>error: not find </text> <translation>another error similar previous one.</translation> </ent> </msg> xsl file <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="1.0"> <xsl:output method="text"/> <xsl:template match="msg"> <xsl:for-each select="ent"> <xsl:variable name="current_key" select="@key"/> <xsl:variable name="match" select="$translations/msg/ent[@key = $current_key]"/> <xsl:choose> <xsl:when test="$match , normalize-space($match/text) = normalize-space(.) , (not(@translate) or @t

actionscript 3 - Check boxes weird behavior in AS3 datagrid -

i have column checkbox .. if scroll down while having checked , unchecked , check boxes start check , unchecked randomly .. tried change them button labeled checked , unchecked still same issue. please. assuming you're using itemrenderer, due default itemrenderer behavior in flex. player calculates how many items display @ once on screen (say, 10), , creates number of instances plus buffer instance top , bottom of list. when scroll through list, player reuses existing instances, setting values on instance properties in data source. to fix this, have check box set boolean value in data source. in setter method in item renderer itself, check value , set checkbox accordingly. adobe developer connection has series of articles itemrenderers if want learn more.

sorting - Sort the first N elements of a vector in MATLAB -

i sort first n elements of vector has more elements. example: a = [3 2 5 1 8 9 2 1 9]; if n = 5 , output should be: b = [1 2 3 5 8 9 2 1 9]; i have vector of indices v , b = a(v) . how can this? [b, v] = sort(a(1:n)); b = [b, a(n+1:end)]; % sorted vector v = [v, n+1:numel(a)]; % index vector

Where is Couchbase Sync Gateway AdminUI? -

i have set "adminui": "0.0.0.0:4985/_admin/" in config. still 404 page not found when going endpoint (e.g. http://<host ip>:4985/_admin/ ). this description of config line adminui http://developer.couchbase.com/documentation/mobile/1.2/develop/guides/sync-gateway/configuring-sync-gateway/config-properties/index.html url of sync gateway admin console html page. default bundled sync gateway admin console @ localhost:4985/_admin/. i got hint https://github.com/couchbase/sync_gateway/blob/aba088a902b162bcaed745510f4d012b8908a303/rest/config.go#l64 adminui *string `json:",omitempty"` // path admin html page, if omitted uses bundled html i omitted line "adminui": "0.0.0.0:4985/_admin/" config file bundled couchbase sync gateway admin ui html page.

JavaScript: Can one use "Object.prototype.toString.call(obj)" for data-type detection? -

if 1 calls tostring-method of object call (for changing context) string returned. string contains data-type of value given call. var obj = {}; var field = []; var str = 'abc'; var num = 3; var reg = /.*/; var bool = true; var notanumber = nan; var undef = undefined; console.log(object.prototype.tostring.call(obj)); // [object object] console.log(object.prototype.tostring.call(field)); // [object array] console.log(object.prototype.tostring.call(str)); // [object string] console.log(object.prototype.tostring.call(num)); // [object number] console.log(object.prototype.tostring.call(reg)); // [object regexp] console.log(object.prototype.tostring.call(bool)); // [object boolean] console.log(object.prototype.tostring.call(notanumber)); // [object number] console.log(object.prototype.tostring.call(undefined)); // [object undefined] what can tinkering: beside usual javascript weirdness (nan number) seems work fine. now ask myself: if make function .split(/\s/) etc., retur

python - Set alternative pk in Django -

i make django generate 6+ digits number id's 1 model . don't want start 0 want id's clear , readable users. 1 example: 658975 how that? i've tried this: class myuuidmodel(models.model): id = models.uuidfield(primary_key=true, default=uuid.uuid4, editable=false) but uuid generates huge sequences not user-friendly. do have advices? maybe setting minimum number of autoincrement pk enough. can't use pk+random number show user , keeping rest of logic same ? else here go how make primary key start 1000? write 1 of migration this.

How to do multiple finds with Java 8 stream? -

given following data structure: class address contains: addressid primary key type can "mail" or "legal" address text field containing address personid foreign key person class scenario 1 pseudo code: list<address> addresses = new list<address>(); addresses.add(new address(1,"mail","123 main st",1)); addresses.add(new address(2,"legal","456 main st",1)); //in scenario want "mail" record returned addresses.stream().filter(e->e.gettype().equals("mail")).findfirst().orelse(...); scenario 2 pseudo code: list<address> addresses = new list<address>(); addresses.add(new address(1,"legal","891 main st",2)); //in scenario want "legal" record returned addresses.stream().filter(e->e.gettype().equals("mail")).findfirst().orelse(...); scenario 3 pseudo code: list<address> addresses =

properties - What is the correct way to create methods that change private fields in C#? -

i switched c# java , became familiar notion of property, seems common way of getting , setting field values. so should if need update field values pretty often, not setting them totally new values? like, there field in class list, , need append elements it, while keeping rest of list unchanged. should go ahead , create method like void append(point p) { } or there more elegant or civilized way of doing in c#? there no single "correct" way of setting private fields through api. answer depends on functionality present users. if let them access list<point> read-only collection can modify in way like, may present list read-only property: public ilist<point> points {get;} = new list<point>(); if think approach gives users freedom, , prefer have tighter control on points appear on list, may want expose property accessing list ienumerable<point> , bunch of methods adding / removing / modifying points on list. private ilist<poin

c# - How to get current physical path of a reflected assembly -

i have executable loads class library dll using reflection. within class library, want find out physical path of class library is. don't want executing assembly, original executable. eg exe might in c:\program\ , class library might c:\libraries\remote\assembly1.dll within method inside assembly1.dll need call returns me c:\libraries\remote\ i have tried var currentlocation = assembly.getassembly(gettype()).location; but doesn't seem work. how can this? i use way current class's assembly path: var dllpath = new uri(this.gettype().assembly.getname().codebase).localpath;

Unable to connect to SQL Server with PHP -

connection sqlsrv string not working. $login = new pdo("sqlsrv:server=mysqlserver\sqlexpress;database=db_name", "user", "passw"); and have error message: fatal error: invalid handle returned . i'm 101% sure login details ok. because works on other projects. problem php 7 ? looks connect ms-sql, need utilize odbc. reference: http://php.net/manual/en/pdo.construct.php#120705 $odbc="odbc:driver={sql server};server=$server;database=$database;"; $cnx = new pdo( $odbc , $user, $password);

php - How to keep Fix width in between two or more li in select option Dropdown? -

<select class="form-control selectpicker" data-live-search="true" id="dynamic-select" > <option value="" style="bold"> </option> <option value="" style="bold">code&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name </option> <?php include "config.php"; echo $sup_code="select * supplier status='active' order su_code asc"; $sel_sup_code = mysql_query($sup_code) or die(mysql_error()); while($row_sup_code=mysql_fetch_array($sel_sup_code)) { ?> <option value="supplier.php?selectedid=<?php echo $row_sup_code['id']; ?>" > <li>&nbsp;&nbsp; <?php echo $row_sup_code['su_code']; ?> </li>&nbsp;&nbsp;&nbsp;--&nbsp;&nbsp;&

rtsp - Locomote player gives this error: Object {code: 731, message: "Socket reported a security error: Error #2048."} -

i using red5pro rtsp streams , need flash player play live streams on rtsp. locomote giving error object {code: 731, message: "socket reported security error: error #2048."} i not familiar socket policy. can me out in this?

android - Unable to fetch facebook profile picture, to insert in ImageView -

i unable fetch facebook profile picture, in order display in fragment. name, birthday , link fetched successfully, application stops working when try fetch profile picture. how rid of situation? private facebookcallback<loginresult> callback=new facebookcallback<loginresult>() { @override public void onsuccess(loginresult loginresult) { accesstoken accesstoken=loginresult.getaccesstoken(); profile profile=profile.getcurrentprofile(); //displaymessage(profile); graphrequest request=graphrequest.newmerequest(accesstoken, new graphrequest.graphjsonobjectcallback() { @override public void oncompleted(jsonobject object, graphresponse response) { try{ tv1=(textview)getview().findviewbyid(r.id.name); tv1.settext("name : " + object.getstring("name")); tv2=(textview)getview().findviewbyid(r.id.birthday);

android - How to push firebase notification only when CheckBoxPreference is checked? -

i using firebase notifications in order notify users new data posted app. i'm following example given here: https://github.com/firebase/quickstart-android/tree/master/messaging although, providing preference user. should notified when chose notified checking checkboxpreference . i have set checkboxpreference , onpreferencechangelistener successfully. problem user getting notification when checkbox unchecked. here's have done in settingsactivity : public class settingsactivity extends preferenceactivity { private appcompatdelegate mdelegate; preference mypref; boolean ischecked = true; private static final string tag = "settingsactivity"; public static final string receive_notifs = "receivenotifications"; @override protected void oncreate(bundle savedinstancestate) { // todo auto-generated method stub getdelegate().installviewfactory(); getdelegate().oncreate(savedinstancestate);

Spark/Phoenix with Kerberos on YARN -

i have spark (1.4.1) application runs on non-kerberized cluster , copied instance has kerberos running. application takes data hdfs , puts phoenix. however, not work: error ipc.abstractrpcclient: sasl authentication failed. cause missing or invalid credentials. consider 'kinit'. javax.security.sasl.saslexception: gss initiate failed [caused gssexception: no valid credentials provided (mechanism level: failed find kerberos tgt)] @ com.sun.security.sasl.gsskerb.gsskrb5client.evaluatechallenge(gsskrb5client.java:211) @ org.apache.hadoop.hbase.security.hbasesaslrpcclient.saslconnect(hbasesaslrpcclient.java:179) @ org.apache.hadoop.hbase.ipc.rpcclientimpl$connection.setupsaslconnection(rpcclientimpl.java:611) @ org.apache.hadoop.hbase.ipc.rpcclientimpl$connection.access$600(rpcclientimpl.java:156) @ org.apache.hadoop.hbase.ipc.rpcclientimpl$connection$2.run(rpcclientimpl.java:737) @ org.apache.ha

java - LWJGL 3.0.0 does not produce a window after upgrading from 3.0.0-SNAPSHOT -

it seem lwjgl 3.0.0-snapshot available anymore, had go lwjgl 3.0.0. however, me looks mac binaries broken. i have downloaded natives using following script, have been working in past. line has changed is: <lwjgl.version>3.0.0snapshot</lwjgl.version> -> <lwjgl.version>3.0.0</lwjgl.version> pom.xml: <?xml version="1.0" encoding="utf-8"?> <project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelversion>4.0.0</modelversion> <groupid>meltdown</groupid> <artifactid>bitflip</artifactid> <version>1.0-snapshot</version> <packaging>jar</packaging> <name>bitflip</name> <properties> <lwjgl.version>3.0.0</lwjgl.version> <!--<