Posts

PHP: preg_match_all - anyway to capture offset and use the PREG_SET_ORDER flag? -

i need part out matches in more intuitive manner preg_set_order gives while still getting offset of each match. there anyways accomplish this? i need capture kind of tag , not want post process capture. lookbehind mess. this tags , there offset pops out 3-dim array excessive: preg_match_all('|(?<=<)[\/a-za-z]+|',$file,$matches,preg_offset_capture); this yields cleaner result dont know offset tags located: preg_match_all('|<(\/*)([a-za-z]+)[^>]*>|',$file,$matches,preg_set_order) so need combination of two: preg_match_all('|<(\/*)([a-za-z]+)[^>]*>|',$file,$matches,preg_set_order,preg_offset_capture) not sure you're looking for, appears you're trying use preg_set_order while still getting offsets? if so, pass both flags preg_match_all: preg_match_all($find, $string, $matches, preg_set_order|preg_offset_capture); var_dump($matches) numerical flags such these can combined using bit or operator | (vertic...

database - Django south datamigrations not running post saves -

i using django south data-migrations update data in new tables after schema-migrations create new tables. have written post-save methods on existing tables update data on newly created tables. this, using data-migrations , in forward method, saving existing table rows in post-saves, new tables data populated. however, post saves dont run after running data migrations. 1 way call post-save function directly forward method in datamigrations. south documentations recommends should use orm objects freeze state. in post-save methods, using these models normally. way copy same code in migration way, everytime make changes in post-save method, need update code in datamigration forward method. what best way achieve this? migration files python modules. can import code other parts of project hence reusing logic. that slippery slope because: lets have migration migrates database state x state y (and backwards). lets migration reuses code foo.py . after time need change db s...

c - Does there exist an LR(k) grammar with no LL(1) equivalent -

i haven't been able find answer yet. there grammars context free , non-ambiguous can't converted ll(1)? i found 1 production couldn't figure out how convert ll(1): parameter-type-list production in c99: parameter-type-list: parameter-list parameter-list , ... is example of lr(k) grammar doesn't have ll(1) equivalent or doing wrong? edit: copied wrong name, meant copy parameter-declaration: parameter-declaration: declaration-specifiers declarator declaration-specifiers abstract-declarator(opt) the problem declarator , abstract declarator both having ( in first set, being left recursive. in general, lr(k) grammars more powerful ll(k) . means there languages lr(k) parser, not ll(k) . one of examples language defined grammar: s -> s s -> p p -> p b p -> \epsilon or, in other words, string of a 's, followed same or less number of b 's. follows fact ll(k) parser must make decision every a encountered - p...

c# - VB.Net Inline comments -

being c# developer, surprised find couldn't create inline comments within array declaration. in test case want simulate 2 byte array packets coming through together: dim buffer byte() = { &hf5, &h5, &h53, ... many more bytes &h1, &h2, &hce, &hf5, 'new packet starts here... doesn't work :( &h5, &h53, ... many more bytes &h1, &h2, &h1a } surely i'm missing something, possible place inline comments within array declaration? if not, there decent work around? need split array 2 , join them together? thanks in advance. no not possible. but, found out yourself, in future version - visual basic 14 (visual studio 2015) possible new language features in visual basic 14 for current version can create named variable , use in array declaration dim newpacketstarts byte = &hf5 if have lot of hardcoded values - create constants describable names const star...

ios - Swift - NSPredicate -

is there cleaner way without having specify searchtext twice? or best way? let searchpredicate = nspredicate(format: "self.firstname contains[c] %@ or self.lastname contains[c] %@", argumentarray: [searchtext, searchtext]) in case, think va_arg prototype cleaner array one: let searchpredicate2 = nspredicate(format: "self.firstname contains[c] %@ or self.lastname contains[c] %@", searchtext, searchtext) but both case have same result, it's you. note have third way create predicate: using dictionary. take @ documentation .

python 3.x - returning a replaced field in a list of namedtuples in a namedtuple -

i have restaurant , dish type namedtuple defined below: restaurant = namedtuple('restaurant', 'name cuisine phone menu') dish = namedtuple('dish', 'name price calories') r1 = restaurant('thai dishes', 'thai', '334-4433', [dish('mee krob', 12.50, 500), dish('larb gai', 11.00, 450)]) i need change price of dish 2.50. have following code: def restaurant_raise_prices(rest): result = [] item in rest: dish in item.menu: dish = dish._replace(price = dish.price + 2.50) result.append(item) return result it replaces price field , returns dish namedtuple: [dish(name='mee krob', price=15.0, calories=500), dish(name='larb gai', price=13.5, calories=450)] how can change code add restaurant well? but returns dish. if wanted entire restaurant too? how can make change output is: restaurant('thai dishes', 'thai...

php - header('Location: '.$newurl) in not working in my Magento -

in magento have 2 store, want integrate example payment gateway in magento. in magento have logic if transaction status success go redirect success page else redirect failure page. but pg side don't have type of logic wants 1 url, when request site redirect url, decided this. just created 1 .php file in root folder (root folder/example/redirect.php). the pg redirecting customers url along pg posting response also. based on pg response written code in redirect.php please find code below. <?php header("pragma: no-cache"); header("cache-control: no-cache"); header("expires: 0"); $magefilename = '../app/mage.php'; require_once $magefilename; mage::app(); if (empty($_request['orderid'])) { $_order_orig = mage::getmodel('sales/order')->loadbyincrementid($_request['orderid']); $store_id = $_order_orig->getstoreid(); ...