Posts

Formatting string according to pattern without regex in php -

how can format arbitrary string according flexible pattern? solution came using regular expressions, need 2 "patterns" (one search , 1 output). example: $str = '123abc5678"; desired output: 12.3ab-c5-67.8 i use pattern in variable (one user can define without knowledge of regular expressions) this: $pattern = '%%.%%%-%%-%%.%'; so user have use 2 different characters (% , .) a solution regex this: $str = '123abc5678'; $pattern_src = '@(.{2})(.{3})(.{2})(.{2})(.{1})@'; $pattern_rpl = "$1.$2-$3-$4.$5"; $res = preg_replace($pattern_src, $pattern_rpl, $str); //$res eq 12.3ab-c5-67.8 way complicated since user need define $pattern_src , $pattern_rpl. if string vary in length, more complex explain. yes, write function/parser builds required regular expressions based on simple user pattern %%.%%%-%%-%%.%. wonder if there "built in" way achieve php? thinking sprintf etc., doesn't seem trick. ideas? ...

vba - Copy Excel Data With Source Formatting -

i recorded macro this, , copied macro code , adapted how needed it. however, issue source formatting not kept when paste on new worksheet. step did miss? must selection.pastespecial right? below non-working syntax selection.autofilter activesheet.listobjects("db1.accdb").range.autofilter field:=1, criteria1:="pink" lastrow = 2 worksheets("sheet2").range("a65536").end(xlup).row next lastrow range("a1", "m" & lastrow).copy sheets.add after:=activesheet selection.pastespecial paste:=xlpasteallusingsourcetheme, operation:=xlnone, skipblanks:=false, transpose:=false range("a1").select activesheet.name = "pink" no need selection.pastespecial , normal copy method sufficient. sub copytest() '/ source destination '-------- ----------- sheet1.usedrange.copy sheet2.cells(1, 1) application.cutcopymode = false end sub << --this work c...

python - How can I feed keys in to a terminal for unittesting purposes -

i'm working on plug-in vim, , i'd test behaves correctly, under start-up, when users edit files e.t.c. to this, i'd start terminal, , feed keys in it. i'm thinking of doing python script. there way this? in pseudo-python might this: #start terminal. here konsole konsole = os.system('konsole --width=200 --height=150') #start vim in terminal konsole.feed_keys("vim\n") #run vim function tested konsole.feed_keys(":let my_list = myvimfunction()\n") #save return value file system konsole.feed_keys(":writefile(my_list, '/tmp/result')\n") #load result python open('/tmp/result', 'r') myfile: data = myfile.read() #validate result assertequal('expect result', data) i think should verify core functionality of plugin inside vim, using unit tests. there's wide variety of vim plugins, provide additional mappings or commands, invoked user, , leave behind side effects in buffer, or output...

ios - Align baselines with characters in large line heights with Text Kit -

Image
when draw attributed string fixed line height text kit, characters aligned bottom of line fragment. while make sense on 1 line characters varying in size, breaks flow of text multiple lines. baselines appear decided largest descender each line. i've found article people behind sketch explaining exact problem in bit more detail , showing solution does, not explaining how achieved this. this want basically: when showing 2 lines large line height, result far ideal: the code i'm using: let smallfont = uifont.systemfont(ofsize: 15) let bigfont = uifont.systemfont(ofsize: 25) let paragraphstyle = nsmutableparagraphstyle() paragraphstyle.minimumlineheight = 22 paragraphstyle.maximumlineheight = 22 var attributes = [ nsfontattributename: smallfont, nsparagraphstyleattributename: paragraphstyle ] let textstorage = nstextstorage() let textcontainer = nstextcontainer(size: cgsize(width: 250, height: 500)) let layoutmanager = nslayoutmanager() textstorage.append(n...

java - .class files under target/classes folder Maven -

i have maven project once run maven build mvn clean install target/classes folder generated suspicious .class file. can see .class file under folder. how can identify .class file being pulled from. i searched in source code , can't find results string search. this class, rmiinvocationwrapper_stub.class

xcode - CocoaPod Storyboard error: -

i made cocoapod include in main project, splash screen animations used while app loading page go to. builds fine in cocoapod project, when include local copy in other projects local folder, following error on storyboard... error: not enough arguments provided; input document operate on? any idea on going on here? it ended being issue .podspec file. had .source_files spec including not swift file, storyboard.. apparently xcode not cool (shown below).. spec.source_files = 'cocoapodprojectfolder/source/*.{swift, storyboard}' to fix had move storyboard file correct spec: resource_bundle... spec.source_files = 'cocoapodprojectfolder/source/*.{swift}' spec.resource_bundle = {'cocoapodproject' => 'cocoapodprojectfolder/source/*.{storyboard}'}

php - WooCommerce dashboard. Edit order page - Product display -

Image
i need sort order - products different displaying woocommerce. need sort products in order variantion (i know how). problem don't find how can edit page. know can't edit woocommerce core files, woocommerce updates code disapears. i know can done function somehow so how can edit order page product display ? image want edit (order products display. display variantion):

jQuery UI dialog buttons click once -

i have jquery dialog buttons. when user clicks on button, take time, make ajax call , stuff. during time, user able click again , again. want avoid behaviour. i know, jquery has method one() . want. how achieve on dialog buttons? my current code is: $d.dialog({ buttons: [ { text: "potrdi", click: function() { // stuff } } ] }); you can set button disabled using jquery-ui button's disabled option: button( "option", "disabled", true ); here example of how set correctly on clicked button (the button enabled again after 2 secons): $( function() { $( "#dialog-confirm" ).dialog({ resizable: false, height: "auto", width: 400, modal: true, buttons: { "delete items": function(e) { btn = $(e.toelement).button( "option", "disabled", true ); settimeout(functio...

Capitalizing certain chars in a string in C -

i'm looking way convert upper case letters lower case letters user inputted string. problem conditional ignored, , every character changed, not upper case ones. record tried converting chars ints using atoi encountered same issue above. #include <stdio.h> #include <stdlib.h> #include <string.h> int main() { char letter[100]; scanf("%s", letter); int i; for(i=0; letter[i]!='\0'; i++){ if((letter[i]>='a')||(letter[i]<='z')){ letter[i]=letter[i]+32; } } printf("%s", letter); return 0; } i suggest using library functions, islower() , isupper() , toupper() , tolower() this. in case, this: for(i = 0; < strlen(letter); i++) { letter[i] = tolower(letter[i]); }

php - Trouble with inarray -

so i'm trying create check date , produce different variable result depending on date today. this current code: <?php for($i = 0; $i <= 25; $i++) $dates[] = date("d", strtotime( "+$i days")); foreach ($dates $today) { if (in_array($today, array('01', '05', '09', '14', '19', '24'), true)) { $tweet = "one"; } if (in_array($today, array('02', '06', '10', '15', '20', '25'), true)) { $tweet = "two"; } if (in_array($today, array('03', '07', '11', '16', '21'), true)) { $tweet = "three"; } if (in_array($today, array('04', '08', '12', '17', '22'), true)) { $tweet = "four"; } } echo $tweet; ?> problem if date ...

mysql - uknown column in field list trigger -

what issue here? i'm using workbench. when try insert table staff error. i'm trying insert table values ;staff' depending if on input 1 of columns. error code: 1054. unknown column 'position' in 'field list' 0.046 sec create trigger your_trigger_name after insert on staff each row begin if position = 'senior instructor' insert new.senior_instructor values (new.employee_name, new.date_of_birth); end if; end; delimiter || create trigger your_trigger_name after insert on staff each row begin if new.position = 'senior instructor' insert senior_instructor values (new.employee_name, new.date_of_birth); end if; end || delimiter ;

javascript - DataTables: json is undefined in initComplete() -

Image
jquery.datatables.min.js: datatables 1.10.12 i need access table rows after data has been loaded ( deferred ). , can't because json undefined me inside initcomplete function. despite table loaded , see data. also, there settings data inside function. why that? did forget option? my code: var data_table = task_submit_table.datatable({ "initcomplete": function (settings, json) { console.log(json); }, "processing": true, "serverside": true, "deferrender": true, "deferloading": 0, "ordering": true, "order": [[ 0, "desc" ]], "ajax": { "url": "get_task_list/", "type": "post", "datatype": "json" }, "columns": [ {"title": "id", "data": "id"}, {"title": "date", "data": ...

vb.net - What is the best way to read an XML file from Embedded resources? -

dim xmldoc new xmldocument() dim xmlnode xmlnodelist dim integer dim str string xmldoc.loadxml("countybyregion.xml") this throws an exception of type 'system.xml.xmlexception' occurred in system.xml.dll not handled in user code. additional information: data @ root level invalid. line 1, position 1. i dim fsxml new filestream("countybyregion.xml", filemode.open, fileaccess.read) and use xmldoc.load(fsxml)

tidyverse - gather and spread function in R -

i have created data frame using below code: stocks <- data.frame(time = as.date('2009-01-01') + 0:9, x = rnorm(50, 20, 1), y= rnorm(50, 20, 2),= rnorm(50, 20, 2), z=rnorm(50,20,4)) ) i have applied gather function data frame: res<-stocks%<%gather(company, value,-time) while trying spread res getting error: spread(data=res, key=company , value = value) error: duplicate identifiers rows we need sequence column avoid error duplicate identifiers... stocks %>% gather(company, value,-time) %>% group_by(company) %>% mutate(i = row_number()) %>% spread(company, value)

php - Redirect to route without get params with Laravel -

i have legacy urls params want redirect route without these parameters. in web.php have: route::get('/', ['as' => 'welcome', 'uses' => 'pagecontroller@welcome']); urls http://example.com/?page_id=5 should redirect (302) http://example.com/ . in controller tried following: public function welcome(request $request) { if($request->has('page_id')) { redirect()->to('welcome', 302); } return view('welcome'); } it reaches redirect the url still has ?page_id=5 in it. like: redirect()->to('welcome', 302)->with('page_id', null); made no difference well. best way in laravel 5.3 redirect page parameters after ? 1 without parameters? you should use return in front of redirect() method make work: public function welcome(request $request) { if($request->has('page_id')) { return redirect()->route('welcome'); } ...

rust - How to pass `Option<&mut ...>` to multiple function calls without causing move errors? -

since it's possible pass mutable reference vector around (without causing moves), how can option<reference> passed functions multiple times without causing borrow checking errors? this simple example shows happens when option<&mut vec<usize>> passed multiple times function: fn maybe_push(mut v_option: option<&mut vec<usize>>) -> usize { let mut c = 0; if let some(ref mut v) = v_option.as_mut() { in 0..10 { v.push(i); c += i; } } return c; } fn maybe_push_multi(v_option: option<&mut vec<usize>>) -> usize { let mut c = 0; c += maybe_push(v_option); c += maybe_push(v_option); c += maybe_push(none); return c; } fn main() { let mut v: vec<usize> = vec![]; let v_option = some(&mut v); println!("{}", maybe_push_multi(v_option)); } ( playground ) gives error: error[e0382]: use of moved value: `v_option` ...

java - Validating model - received from JSON (spring mvc) - good practices -

i have simple pojo class (models) created json format (received frontend). what approach validate these values ? example if number not null, if number (nor string), etc. you can use validate attributes annotation @valid in restcontroller , put @notnull or @notempty in model. exemple: @restcontroller @requestmapping(value="/book") public class bookcontroller { @requestmapping(method=requestmethod.post) public responseentity<void> save(@valid @requestbody book book){ //save book } } @entity public class book{ @notempty(message="msg") private string name; }

xaml - Exchange default ControlTemplate for control -

i want modify controltemplate appbarbutton items. possible in onlaunched() or somewhere else? windows.ui.xaml.controls.appbarbutton.templateproperty = windows.ui.xaml.application.current.resources["defaultappbarbuttoncontroltemplate"] windows.ui.xaml.controls.controltemplate; the code above doesn't work (read property), should demonstrate, i'm trying do. overwriting complete style work, overwriting controltemplate too? can't use custom control in case. if want apply style controls in app of same type, create style without x:key attribute , place in application.resources or in resourcedictionary referenced there. as sample, i've taken default style appbarbutton , changed place of label , icon. did remove other property setters , changed template . xaml style properties overwritten in order loaded: first system defaults , application resources, followed page/control resources , inline styles. since i'm defining template property, o...

PHP oAuth POST requests -

having little trouble getting oauth post requests return workable response. thoughts appreciated. $request = $provider->getauthenticatedrequest( 'post', 'https://graph.microsoft.com/v1.0/me/calendar/events', $_session['access_token'], ['body' => json_encode([ 'id' => null, 'subject' => 'test 54575', 'start' => [ 'datetime' => '2016-11-17t02:00:00', 'timezone' => 'w. europe standard time' ], 'end' => [ 'datetime' => '2016-11-17t04:00:00', 'timezone' => 'w. europe standard time' ], 'body' => [ 'contenttype' => 'text', 'content' => 'estruyf' ], ...

ember.js - Emberjs 1.13.0—Call Action of Component -

i have such component: app.mynicecomponent = ember.component.extend({ actions: { save: function () { … } } }); the template it: <h1>my nice component</h1> {{ yield }} anywhere in template: {{#my-nice |mn| }} … <a onclick={{ action 'save' }}>save</save> {{/my-nice}} clicking on link make ember try trigger action in routes controller. guess because version using here old, there way make ember call components action, or hand on function reference link, called? in component, designed have child components, manage so: app.achildcomponent = ember.component.extend({ targetobject: em.computed.alias('parentview'), task: '', action: 'onchildclick', //present action in parent compoent click: function(){ this.sendaction('action', this.get('task')); } }) in hbs that: {{#my-nice}} {{#a-child task="do this"}} {{/my-nice}} in case love make ember trigger compoents ac...