Posts

ruby - Trying to change last to "x"s to 23 -

i have been playing around irb , have string looks this: irb(main):072:0> puts ["[\"4354 5432 5432 xxxxx\", \"6547 6547 8543 xxxxx\", \"2344 6543 6674 xxxxx\", \"2346 6236 7543 xxxxx\", \"1273 5585 5587 xxxxx\"]"] => nil irb(main):073:0> what want gsub last 2 "x" s of each 17 digit combination, 23 . what i've tried far (i've been using rubular): a.gsub(/\d[x]/,"23") <= grabs "x" s i'm close a.gsub(/\w[x{2}]/,"23") <= grabs "x" s grabs two digits each combination. is there easier way i'm not understanding? a.gsub(/\d{4} \d{4} \d{4} xxx\kxx/, '23') \d{4} = 4 digits what \k drop matched far. can use don't replace entire number, still able validate have in desired format.

jquery - Clone last and append item to closest class -

this bare-bones code on page: <div class="list-container"> <div class="single-list-item"> <button>remove</button> </div> <div class="single-list-item"> <button>remove</button> </div> <div class="single-list-item"> <button>remove</button> </div> </div> <p><button class="add-list-item">add</button></p> <div class="list-container"> <div class="single-list-item"> <button>remove</button> </div> <div class="single-list-item"> <button>remove</button> </div> <div class="single-list-item"> <button>remove</button> </div> </div> <p><button class="add-list-item">add</button></p> <di...

javascript - Jquery bind event on element fails -

we using jquery 2.1.4 , have written out own javascript class should take care of event. simple "application". taking care of submitting form. before that, processes data. our initial method call on rendering page: owebform.prototype.init = function(){ console.log("init method called"); ... $("#submit_message").on("click", this._submit); console.log($("#submit_message")); ... } owebform.prototype._submit = function(e){ e.preventdefault(); console.log("_submit method called"); ... } once button " #submit_message " clicked, supposed call _submit method of owebform class. when looking @ element within console can see not bound anything, when page loaded. hence code not executed once button clicked. in html have following code: <script type="text/javascript"> var _owebform = new owebform("0bcfwqx23xv02dfaqfujdqyafziic4b07uxkkg1y6lkof7x0px0vjm2tp...

java - What does the following program? -

this question has answer here: is java “pass-by-reference” or “pass-by-value”? 74 answers class ideone { int x; public static void main (string[] args) throws java.lang.exception { ideone i; = new ideone(); i.x = 25; system.out.println(i.x); f(i); system.out.println(i.x); g(i); system.out.println(i.x); } public static void f(ideone j){ j = new ideone(); j.x = 55; // changes new instance of j. not changing actual object } public static void j(ideone j){ j.x = 52; // modifies actual object } } i have doubt in this. in case of j function, modifies actual object. not pass reference? passing object , modifying inside j. but doing samein function f also. passing object , modifying it. not m...

Android SDK: Show one line at a time and proceed with onClick -

i'm new java , android sdk i'm willing learn. want build app take sentence, or generic string , displays 1 line of text, coded. want proceed "next" line clicking button called "proceed". in short offers read little amount of text @ time , proceed b clicking button. this how far i've got: activity_main.xml <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" tools:context=".displaymessageactivity" android:orientation="horizontal" > <textview...

css - Can I use the :after pseudo-element on an input field? -

i trying use :after css pseudo-element on input field, not work. if use span , works ok. <style type="text/css"> .mystyle:after {content:url(smiley.gif);} .mystyle {color:red;} </style> this works (puts smiley after "buu!" , before "some more") <span class="mystyle">buuu!</span>a more this not work - colors somevalue in red, there no smiley. <input class="mystyle" type="text" value="somevalue"> what doing wrong? should use pseudo-selector? note: cannot add span around input , because being generated third-party control. :after , :before not supported in internet explorer 7 , under, on elements. it's not meant used on replaced elements such form elements (inputs) , image elements . in other words it's impossible pure css. however if using jquery can use $(".mystyle").after("add smiley here"); api docs on .after to ...

javascript - How to change format of the phone number? -

at time, format next phone 123-123-1123 i want have next form: (123)456-7890 how can change format whatever shape want? <input class="" type="text" name="primary_phone" id="primary_phone" maxlength="10" placeholder="1234567890"> $("#primary_phone").blur(function() { text = $(this).val().replace(/(\d{3})(\d{3})(\d{4})/, "$1-$2-$3"); $(this).val(text); }); http://jsfiddle.net/xxk3f/2864/ var phone = "123-123-1123"; var newphone = "(" + phone.replace("-", ")"); alert(newphone);

Wpf ListBox – change default selected-item style *inside* the ContentPresenter -

Image
i have listbox in each item stackpanel. stackpanel consist of image , textblock below it: <listbox.itemtemplate> <datatemplate> <stackpanel margin="10"> <image> <image.source> <bitmapimage urisource="{binding path=imagefilepath}"/> </image.source> </image> <textblock text="title" textalignment="center"/> </stackpanel> </datatemplate> </listbox.itemtemplate> it looks this: when user select item, default blue rectangle surround stackpanel: now, want make different border selected-item, want surround image . i know how make control template , put custom border around contentpresenter, this, of course, surround whole stackpanel, not image. i don’t know if making changes contentpresenter possible, , if idea @ all. if there other way achieve want...

bar chart - How to set the width within axis label in highcharts -

do know setting in hightcharts can change width marked red arrow example? please take @ image below i want set width of red arrow example you using categories, axis divided evenly between existing categories. in other words, can remove unnecessary categories, example: http://jsfiddle.net/mwqto4n6/ $('#container').highcharts({ xaxis: { categories: ["2016", "2025"] }, series: [{ type: 'column', data: [200, 120] }] });

symfony - Fetcing dynamically added fields in forms - Symfony2 -

i have data added in hidden input fields inside form. now since i'm using symfony2 forms fields don't submitted. i.e. $form->getdata() not data fields. how data dynamically added (hidden) input fields well? fetch post values in context of form type: $postdata = $request->request->get('form_name'); $name_value = $postdata['title']; fetch post values not in context of form type (maybe need): $data = $request->request->all(); $name = $data['input_name'];

php - MySQL query between two dates as timestamps -

i have been trying select items database between 2 default dates: , 60 days ago. queries try not work. here have tried: $now = date("y-m-d"); $before = date("y-m-d", strtotime("-60 days"); // try1 $sql = "select * mytable mytimestamp between " . $before . " , " . $now; // try2 $sql = "select * mytable mytimestamp >= " . $before . " , mytimestamp <= " . $now; i out of guesses of how this. have looked @ other questions same one, none of solutions presented work. please note: these queries not give errors. don't retrieve anything. have used get_defined_vars() print dates onto page. show: [now] => 2016-01-07 [before] => 2015-11-08 "please note: these queries not give errors." - " . $before . " , " . $now; , you're using 2016-01-07 , 2015-11-08 being strings , not integers . same " . $before . " , mytimestamp <= " . $no...

C++ program gives different results in Debug and Release mode -

i'm doing algorithmic exercises , encountered strange problem. wrote code below solve problem http://main.edu.pl/en/archive/oi/21/pta . tested , looks works fine in debug mode, switch release (or submit site) gives wrong answers tests. eg 9e.in (i uploaded test here: https://www.dropbox.com/s/ki4vfk2p5140xwo/pta9e.in?dl=0 ) answer debug build correct: 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 however, in release (and after submitting site) get: 543 530 530 530 530 530 543 530 530 530 543 530 530 543 530 530 530 543 530 530 543 530 530 530 530 i have no idea can causing problem :/ code: #define _crt_secure_no_warnings #include <iostream> #include <cstdlib> #include <queue> #include <cmath> #include <stdio.h> using namespace std; int numoftrees = 0; int* trees = null; int numofbirds = 0; int computebird(int birdstamina) { int tired = 0; int position = 0; int lastt...

asp.net mvc - Need Port redirection pattern for IIS Windows -

i have application running under http://localhost/testapp inside i'm making ajax call node.js app running under port 3000 i.e. http://localhost:3000 now want configure iis whenever request comes http://localhost/node wanted redirect http://localhost:3000/ example: if make request url http://localhost/node/sample want handled server redirect request http://localhost:3000/sample i tried .net installer url rewrite , tried config pattern didn't work me. guys please me out? my index.cshtml @{ viewbag.title = "index"; } <h2>this index page</h2> <script> $(function () { $.ajax({ url: "/node/sample", success: function () { alert('done'); } }); }); </script> error i'm getting below.. url redirection not happening , throws resource not found exception try out: <rewrite> <rules> <rule name="redire...

Ruby on Rails with twitter APIs -

is possible in ruby on rails update blog posts on twitter account using twitter apis , omniauth. please suggest me. more: have blog, create new post on blog, update should go twitter account tweet , tweet should shown home of blog. please suggest me. how possible. regards, vieenay siingh when post website, expecting have done background search before. anyway, should find need on rubygems website

entity framework - Dynamic database connection using Asp.net MVC and Identity2 -

i'm developing web application in asp.net mvc. application uses multiple databases. database on working on depends logged user. manage login on 2 levels: level1 on "master" database have info login username/email , "specific" database use. level2 on "specific" database manage users , roles identity2. example: in "master" database have record in user table with: - username = user1 - databasetouse = "specificdb1" in "specific" database called specificdb1, same user, have record in user table need manage user authentication , more. what want achieve is: start website, click on login, insert username , password, click on login. search username in master database, if exist specific database name associated user. set here, dynamically, connection string "specific" database , perform identity 2 login operations. no problems points 1 , 2. problem in point 3. use entityframework 6 code first both (...

show two different series with different start intervals with the same xAxis highcharts -

http://jsbin.com/enotab/39/edit i want show data 2 different years on same xaxis without using 2 x axes. in case following result i want have overlay graph 2 series 2012 series becomes shadow graph. how possible? static code: var mychart = new highcharts.chart({ chart: { renderto: 'container', zoomtype: 'x' }, title: { text: 'chart title' }, xaxis: [{ type: 'datetime', minrange: 31 * 24 * 3600000, labels: { formatter: function () { return highcharts.dateformat('%e %b %y', this.value); } } }], yaxis: { title: { text: 'current values' }, gridlinecolor: 'transparent', plotlines: [{ value: 0, color: 'green', dashstyle: 'longdashdot', width: 1 }, { value: 30, color: 'orange', dashstyle: 'longdashdot...

Matlab: Count values if signal changed for 0.1 in the last 2 seconds -

i have continuous signal rising , falling. found peaks- maxima values , locations. i wondering how write code count in case signal changed in kind of rule: amplitude exceeded 0.1 , peak occurred less 2 seconds after beginning of increase. thanks lot. a general answer be: loop through peak vector , check appropriate part of value vector smallest element: for = 1:len(peaks) peak = peaks(i,:) peak_value = peak[1] peak_time = peak[2] cut_values = values(max(1,(peak_time-2)*f):peak_time*f) if min(cut_values) < peak_value - 0.1 peak_count += 1 % or edit - adding explanation: peaks matrix (nx2) of peak values , times values signal vector f sampling frequency (hz), considered uniform edited again accomodate peaks before 2s. matlab's 1-indexing bit tricky here: sample 1 @ time 0, sample 2 @ time f . correct thing signal starts @ 0 time is: cut_values = values(max(0,(peak_time-2)*f)+1:peak_time*f+1)

why use not operation in regex function salesforce -

could of pls explain following code. why not used for? not(regex(zip_postal_code__c, "[0-9]{5}")) it looks code in validation rule. validation rules show error if result of evaluating code true. regex(zip_postal_code__c, "[0-9]{5}") evaluate true if zip code in field valid , false if value not valid cause validation throw error if zip valid. since intention throw error when zip code not valid, not() function used invert or negate result of regex() function.

php - laravel firstOrCreate not working properly? -

i importing data foursquare api. database contains multiple foursquare_id duplicates. doing wrong code here? i thought way set check database column value of foursquare_id? bar::firstorcreate([ // not check these 2 below because mandatory 'foursquare_id' => $item['venue']['id'], 'name' => $item['venue']['name'], 'postalcode' => isset($item['venue']['location']['postalcode']) ? $item['venue']['location']['postalcode'] : '', 'city' => isset($item['venue']['location']['city']) ? $item['venue']['location']['city'] : '', ]); that's right. receive 'first' if all elements of passed array exist in row object. the alternative using firstornew: $foo = bar::firstornew(['foursquare_id' => $item['venue']['id']]); // find object foursq...

java - Read mp3 tags in android application -

i use jid3lib java. when i'm working library on file stored in computer works great, when try read mp3 tags of files on emulator's sdcard got exeption. i use following code: protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main_activity); file musicpath = environment.getexternalstoragepublicdirectory(environment.directory_music); file[] songs = musicpath.listfiles(); (int i=0; < songs.length; i++){ try { mp3file song = new mp3file(new file(songs[i].getpath())); log.d("test", song.getid3v1tag().getalbum() ); } catch (tagexception e) { log.d("test", "tag exception"); e.printstacktrace(); } catch (exception e) { log.d("test", "exception"); e.printstacktrace(); } } } i put 2 mp3 files in sdcard, still got exceptio...