w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How to optimise a nested pattern match with multiple repeated cases?
That's a good application for pattern guards: case action1 of Right a -> a Left f | Failure1 a <- f -> a | Failure2 a <- f , Right b <- action2 a -> b _ -> error "Unexpected failure"

Categories : Haskell

Calling order of link function in nested and repeated angularjs directives
On a single element the order of the linking functions is determined by the order of the Compile Functions which in turn is ordered according to the priority property of the directive definition object. Source : http://docs.angularjs.org/guide/directive On multiple elements with transclusion : the inner directives are evaluated before outer directives. Reason: Nature of transclusion. On multiple elements with siblings : Executed in order top to bottom. Reason: Parsing logic of $compile.

Categories : Angularjs

if some parts of the html are repeated in several documents, is it more efficient to load it in the js?
In short, no. You're on a slippery path there… It might be more efficient for the person maintaining the page but you should really be doing this on the server-side as mohkhan suggested e.g. through a CMS or pre-processing if you're site is completely static. I assume that on your site, there isn't just an info box that's repeated — what about the navigational elements, the banner etc.? There's nothing wrong with loading elements through JavaScript (e.g. to show counters, data, etc.) but you shouldn't be doing it for core content. Remember too that you shouldn't assume that everyone will have JavaScript enabled.

Categories : Javascript

Array insert and excessive matches in nested for loops - ruby
The below part is not correcrt: (0..limit).each do |i| (0..limit2).each do |j| if ary1[i] == ary2[j] ary1.insert(i,ary2[j]) puts 'match!' end end end First pass: ary1 = ['a','b','c','d'] ary2 = ['e','f','g', 'a'] when limit=0 and limit2 = 3,there is a match.ary1.insert(0,ary2[j]) line makes your array ary1 as ary1 = ['a','a','b','c','d'] Second pass: ary1 = ['a','a',b','c','d'] ary2 = ['e','f','g', 'a'] when limit=1 and limit2 = 3,there is a match.ary1.insert(1,ary2[j]) line makes your array ary1 as ary1 = ['a','a','a','b','c','d']. And it Goes on.. So as your arr1is having size 4, 4 a s has been added to ary1. Finally it becomes - [ a,a,a,a,a,b,c,d]. Array#insert says :- Inserts the given values before the element with the given index.Negativ

Categories : Ruby

Emacs Org-Mode: Clear non-repeated SCHEDULED time when DEADLINE is repeated
Here's the patch, if you want to apply it yourself. I'll send another copy to the org-mode mailing list. --- a/lisp/org.el +++ b/lisp/org.el @@ -12835,7 +12835,8 @@ This function is run automatically after each state change to a DONE state." (setq type (if (match-end 1) org-scheduled-string (if (match-end 3) org-deadline-string "Plain:")) ts (match-string (if (match-end 2) 2 (if (match-end 4) 4 0)))) - (when (string-match "\([.+]\)?\(\+[0-9]+\)\([hdwmy]\)" ts) + (if (not (string-match "\([.+]\)?\(\+[0-9]+\)\([hdwmy]\)" ts)) + (org-remove-timestamp-with-keyword org-scheduled-string) (setq n (string-to-number (match-string 2 ts)) what (match-string 3 ts)) (if (equal what "w") (setq n (* n 7) what "d"))

Categories : Emacs

Access repeated item inside ng-repeated directive
You should pass item as attribute to directive created a sample directive http://plnkr.co/edit/l5r6zIc7ncT1XldRuB98?p=preview

Categories : Angularjs

Python: Split a list into nested list at points where item matches criteria
Something like this: li = [1,2,3,4000,5,6,7,8,9000,10,11,12,1300] r = [[]] # start with a list containing an empty sub-list for i in li: if i >= 2000: # start a new sub-list when we see a big value r.append([i]) else: # append to the last sub-list of r r[-1].append(i)

Categories : Python

Python: compare and find matches in a list of tuples and a nested list
Create an inverse mapping of data1 first: inverse_data1 = {v['code'][0]: k for k, v in data1} Now the rest is much simpler; you can look codes against that inverse mapping and find the corresponding name in O(1) time: data3 = [[inverse_data1[d[0]]] + d[1:] for d in data2 if d[0] in inverse_data1] Demo: >>> inverse_data1 = {v['code'][0]: k for k, v in data1} >>> [[inverse_data1[d[0]]] + d[1:] for d in data2 if d[0] in inverse_data1] [['Name1', '123456', 'name1'], ['Name2', '789012', 'name2']] Generally speaking, do not loop over range(len(somelist)) when you can just loop directly over that list. You can use the enumerate() function to add an index if you need one for other purposes. Your data1 and data2 lists are not of equal length, so you cannot just use indice

Categories : Python

Excel regular expression macro that will search one column for matches, paste the entire row of all matches in another worksheet
Without major changes to your existing sub. Replace: If Range("E" & CStr(LSearchRow)).Value = "Mail Box" Then with: v = Range("E" & CStr(LSearchRow)).Value If InStr(1, v, "red") > 0 Or InStr(1, v, "blue") > 0 Then

Categories : Regex

jquery img load and nested divs
You create the lis in the image load callback so then add the div to the li there. $('<img src="' + showpic(item[3]) + '" class="newsImage">') .load(function(){ $(this) .appendTo($('#theNews')) .wrap($('<li>', {"class": "newsItem"})) .wrap('<div class="st-col2">') .closest('li') .append($('<div>', {"class": "st-col1"})); }); });

Categories : Jquery

Wrap mode in nested load
The behavior of method Kernel#load is irrespective of the context it appears. Even if 2.rb is loaded from 3.rb under wrap mode, that has no effect on how 1.rb is loaded in 2.rb. 1.rb is loaded without wrap mode, and hence under the ordinary namespace, which means M::A is callable from 3.rb.

Categories : Ruby

Pattern only matches once, when multiple matches are in the string
My guess is you need to modify the .* to use a non-greedy quantifier, .*?, like this: [URL=("|)([sS]*?)("|)][img](https?://.*?.(?:png|jpg))[/img][/URL]

Categories : Regex

How do I load a nested web page in a
AJAX is what your assignment is looking for. Simple Example HTML: <button id="nav">load</button> <div id="page"></div> JS: document.getElementById('nav').onclick = function(){ var xhr = new XMLHttpRequest(); xhr.onreadystatechange=function() { if (xhr.readyState==4) { document.getElementById("page").innerHTML = xhr.response; } } xhr.open("GET", "http://www.codecademy.com/", false); xhr.send(); } fiddle: http://jsfiddle.net/DZmBG/3/

Categories : Javascript

How to load data into a FragmentActivity to be used by nested fragments?
You do this wrong. You should NOT pause anything. Instead, when parent activity load what is needed it should tell the fragments about that. In fact I'd make it differently - by using listeners - so my fragment would need to register on creation and the object that loads my data would then broadcast message back once loading task it done.

Categories : Java

SQLITE query, if last row matches criteria, check row preceding it matches different criteria (RESOLVED)
SQLite is (as far as I know) a bit low on efficient operators for this, so this is the best I can come up with for now :) SELECT Fruit FROM fruits WHERE ( SELECT COUNT(*) FROM fruits f WHERE f.fruit=fruits.fruit AND f.date > fruits.date ) = 1 AND fruits.value <> 'some_value_1' INTERSECT SELECT Fruit FROM fruits WHERE ( SELECT COUNT(*) FROM fruits f WHERE f.fruit=fruits.fruit AND f.date > fruits.date ) = 0 AND fruits.value = 'some_value_2' An SQLfiddle to test with.

Categories : Sqlite

Struts 1.1 nested and in combination
Use <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> and the code will look like <c:choose> <c:when test="${element.method1 == true}"> <c:choose> <c:when test="${element.method2 == true}"> <span style="color:green;"><c:out value="${element.prop1}/></span> </c:when> <c:otherwise> <span style="color:red;"><c:out value="${element.prop1}/></span> </c:otherwise> </c:choose> </c:when> <c:otherwise> <span style="color:black;"><c:out value="${element.prop1}/></span> </c:otherwise> </c:choose>

Categories : Java

python json.loads / json.load truncates nested json objects?
JSON doesn't care about the keys for objects, but the json.load and json.loads convert to a Python object using this conversion table. JSON objects are turned into python dict's, which means you can't have repeated keys.

Categories : Python

How can I bind data from nested List<> objects to nested ListView controls?
You can bind the datasource of your inner list view to a property of the items bound to your outer listview. However, to do that the inner listview as to be in the itemtemplate of the outer listview. See the code below and note the DataSource='<%# Eval("Labels_color") %>' attribute for the inner list view. <asp:ListView ID="ListView_Orp_Results" runat="server" ItemPlaceholderID="itemPlaceholder"> <LayoutTemplate> <div id="outer_result_container"> <div id="itemPlaceholder" /> </div> </LayoutTemplate> <ItemTemplate> <div id="result_photo">...</div> <div id="result_category">...</div> <div id="result_detector">...</div> <div id="inner_result_container" runat="server"

Categories : Asp Net

JQuery selector for finding a nested span within a nested class is not working
I don't see any problem with your code at the moment, let's reformat it a bit: var tabs = $('.collapse').not('.in'); console.log("tabs.length: " + tabs.length); tabs.each(function () { var $this = $(this), thisErrors = $this.find('.field-validation-error'), thisId = '#' + $this.attr('id'); console.log("current tab ID: " + thisId); console.log("number of errors: " + thisErrors.length); if (thisErrors.length) { $(thisId).collapse('show'); } }); Or working fiddle: http://jsfiddle.net/Rq8y7/ Does it work now? And what's the debug message in console after you run above code?

Categories : Jquery

Parsing a flattly-written nested text template into a usable nested data structure for N levels
Replaces each ">" with a tab. Output is pretty much exactly as your brute force output. (file.txt is your template file as above) test = open("file.txt", "r") for line in test: print line.replace(">", " ") #print line

Categories : Python

How Can I Convert Nested YAML to nested Arrays and OpenStructs in Ruby
There is the solution (https://github.com/jsuchal/hashugar) i often use. opts = Hashugar.new({:a => 1, 'b' => {:c => 2, :d => [3, 4, {:e => 5}]}}) But you also need to do: opts.b.d.last.e I do not understand how do you want to name array's getters. As Arup Rakshit sayed: give us yaml example and expected output or behavior.

Categories : Ruby

MySQL - Reference main query in nested select (need to be nested)
This cannot work. SELECT clause is always evaluated at the end of the execution chain, @teamg_id variable will always be 0 in the nested subquery. Try this query, it is not tested (I can't see your data, playing whith sample data always helps), but probably it gives desired results. I commented out some parts and add one join condition. /* SET @teamg_id := 0; */ SELECT /* @teamg_id := player.team_id, */ player.team_id AS player_team, event.local_team_id AS local_team, event.visitor_team_id AS visitor_team, action.unique_id AS action_id, action.player_id AS player_id, player.name AS player_name, playerindex.rank AS player_pos, playerindex.ses_var_nest AS ses_var_nest FROM er_players player

Categories : Mysql

Avoiding nested each loops when handling nested JSON data
JSON is "just" javascript object literals. You can skip the jQuery call, and just reference the objects and arrays directly after you parse it. obj.custom_sql_rule[0].something_else[0]; of course, your JSON is a bit oddly-formed. If at all possible, don't arbitrarily mix objects {} and arrays [] . Use the latter when you have lists of identical objects or primitive data, and the former when you have named properties. And once you have a valid javascript object, you can just iterate through its properties. for(var sqlProp in jsonObj) { if(jsonObj[sqlProp].error) { errorsContainer.append("<div>" + jsonObj[sqlProp].error + "</div>"); } }

Categories : Javascript

nested json with jQuery: create List of nested item
Your problem is that institut is an array containing a single object, so you can reference that single object using institut[0]. This will work: $.each(data.fakultaeten, function (key, value) { var mother = "<li id='first'>" + value.name + "<ul>"; $.each(value.institut[0], function (key1, value1) { alert(key1); }); }); Here is a working example

Categories : Jquery

How to insert nested lists (or nested block elements) into RichTextBlock?
Ok Ill start with silverlight. There was a TreeView Control in silverlight that would have exactly solved your problem. Link to tree view example But since we already know that winRt is a subset of API's these controls have been removed for metro app. More over microsofts design policy regarding the Type Of scenario you are mentioning has changed to : Semantic Zoom For Metro Apps So i advise if your app requirement is like that Either go with the richtextbox or use Grids with Rows and columns Which ever suits your coding best. One more way is to use third party library for tree structure . Syncfusion tree control Syncfusion has a tree control you can try out in the Demo. Even there are more third party tool but none are free not even he above one. Please Let me know if any more co

Categories : HTML

nested attributes, passing current_user.id to nested model
'current_user' is a devise helper method. it can be accessed in controllers n views directly. if i m not wrong, only the new answer should have the current_user.id Old answers should not be updated. u can do this as f.fields_for :answers, @question.answers.build do |a| a.hidden_field :user_id, :value => current_user.id a.submit

Categories : Ruby On Rails

Idiomatic Emberjs for nested routes but non-nested templates
You could define the parent template to just display the outlet and have an index route which will get displayed inside that. Then for the nested resource you can do the same thing. <script type="text/x-handlebars" data-template-name="user"> {{outlet}} </script> <script type="text/x-handlebars" data-template-name="user/index"> <h2>user/index</h2> </script> <script type="text/x-handlebars" data-template-name="posts"> {{outlet}} </script> <script type="text/x-handlebars" data-template-name="posts/index"> <h2>posts/index</h2> </script> That way it won't be a master/detail. The router would be: App.Router.map(function() { this.resource('user', function() { this.resource('posts', function() { }); });

Categories : Ember Js

C++ macro for repeated using std::xyz statements
Unfortunatley there is not a way to do what you want with the macro :( At best you probably could "reduce" your work very slightly with: USESTD(a) using std::a; But... not sure its worth it, and Chirs's point is quite a good one from my point of view :) - I like to see where things come from too!

Categories : C++

Order repeated values to the new row
Bash solution: read -a ar < input for ((i=0 ; i<${#ar[@]} ; i+=2)) ; do echo ${ar[i]} ${ar[i+1]} done It just reads the whole line into an array, then prints the pairs in a loop. Sed solution: sed -e 's/([^ ]+ [^ ]+) /1 /g' < input It replaves a space by a newline, if there is still one space before it. Perl one-liner: perl -ne 'print $_, ($ff = ! $ff) ? " " : " " for split' < input It uses $ff as a flip-flop.

Categories : Perl

Repeated field validation
I strongly doubt the "This value should not be blank" validation error is casued by your repeated field. You seem to have a NotBlank validation constraint set up as annotation/yml/xml for some field which does not validate. just dump $form->getErrorsAsString to get a field-name as key => error-messages array and inspect which field causes the NotBlank constraint to fail ... ... or just have a look at your validation constraints and find the properties with NotBlank constraints.

Categories : Symfony2

removal of repeated string
That should do it: String[] missingAdapters = ((textMissingAdapterList.item(0)).getNodeValue().trim().split(",")); String result = missingAdapters[0] + " " + missingAdapters[1].split(" ", 2)[1]; assuming there is no space in this double string you want to leave out.

Categories : Java

Getting repeated data - screenscraping using bs4
You are looping unnecessarily. What you need to do is following: from string import punctuation, whitespace import urllib2 import datetime import re from bs4 import BeautifulSoup as Soup today = datetime.date.today() html = urllib2.urlopen("http://www.99acres.com/property-in-velachery-chennai-south-ffid").read() soup = Soup(html) print "INSERT INTO Property (URL,Rooms, Place, Phonenumber1,Phonenumber2,Phonenumber3,Typeofperson, Name)" print "VALUES (" re_digit = re.compile('(d+)') properties = soup.findAll('a', title=re.compile('Bedroom')) for eachproperty in soup.findAll('div', {'class':'sT'}): a = eachproperty.find('a', title=re.compile('Bedroom')) pdate = eachproperty.find('i', {'class':'pdate'}) pdates = re.sub('(s{2,})', ' ', pdate.text) div = eachproperty.find('

Categories : Python

Delete XML repeated tags
Finally I found a way, I know it isn't the best and can be done better private static String replaceNodes(String simpleRegex, String xml) { String tagMultiple; String expresionRegular = "("+simpleRegex+")+"; Pattern pattern = Pattern.compile(expresionRegular); Matcher matcher = pattern.matcher(xml); while(matcher.find()) // Here we look for all the nodes that are repeated . EJ <cite id="asda"><cite id="asda"><cite id="asda"> { Pattern patternSimple = Pattern.compile(simpleRegex); Matcher matcherSimple = patternSimple.matcher(xml); String tagUnicoEnd =""; if (matcherSimple.find()) //Here we get only one node. <cite id="asda"> tagUnicoEnd = matcher.group(1); tagMultiple = mat

Categories : Java

SQL Looping for repeated value for next column?
It looks like you want values from both the current row and the row before it. In other words, you want to be able to pair up a row with the preceding row, and then select stuff from this pair. I don't think you need loops for this. Looping is generally pretty slow. The general idea is, like you did, number the rows. Then you can join the table to itself with the number. Below is an example of how you can do this pairing without using a loop. Schema: create table T (a int); insert into T values (1), (7), (20), (30), (500), (800), (1300), (2112); query: with tNumbered as ( select row_number() over (order by a) as rowID, a from T ) select tLeft.a as l, tRight.a as r from tNumbered tLeft left join tNumbered tRight on tLeft.rowID = tRight.rowID -1 Here's a fiddle showing it in ac

Categories : SQL

how to not add repeated data using jquery
Create and fill a JavaScript object. Users as key, whatever remains in the end does not contain duplicate. Say we are looping over three different users The user 'Jack' with an ID of '42' appears twice When you iterate four times over the users, fill a JavaScript object while using user IDs as key var oUsers = {}; oUsers['42'] = 'Jack'; oUsers['43'] = 'Lucy'; oUsers['44'] = 'Fennel'; oUsers['42'] = 'Jack'; > oUsers > Object {42: "Jack", 43: "Lucy", 44: "Fennel"} >

Categories : Jquery

Preg_match_all repeated group
Why not just: preg_match_all('/(?<=eh=")([^"]+)(?=")/', $strg, $out, PREG_SET_ORDER); Regex101 Demo

Categories : PHP

RegExp repeated groups
Simple ^(?:d{2}-d{2}(?:;|$))+$ Which means: ^ # start of line (?: # non-capturing group d{2} # match 2 digits - # match a hyphen d{2} # match 2 digits (?:;|$) # match ; or end of line )+ # repeat 1 or more times $ # end of line Note 10-02;34-05;12-012;23-05;10-42;44-05; ^--- You have 3 digits here ??? If so change all {2} to + Online demo

Categories : Regex

repeated 'values' tag in map reduce
Have you considered using aggregation instead? It's generally more efficient than mapReduce, and seems to be a better fit for your application. For example, an aggregation solution to your issue would be: db.coll.aggregate({ $group: { _id: "$user_id", values: { $push: { business_id: "$business_id", stars: "$stars" }}}}); You could then save the result to a new collection, or whatever else you like.

Categories : Python

Remove Repeated Text
This is what I've come up with using lookbehinds and back references: (<[^>]+>)(?<=1.*1) This will match any instance of <tag> which is preceded by at least one other instance of the same <tag>. For example, to use this in C#: var input = "<text><text>extra<words><text><words><something>"; var output Regex.Replace(input, @"(<[^>]+>)(?<=1.*1)", ""); Console.WriteLine(output); // <text>extra<words><something> However, this will not work in many flavors of regex. JavaScript, for example, does not support lookbehinds.

Categories : Regex

Wpf DataGrid Repeated Columns
You can achieve this by manually adding repeated columns to your Datagrid. Headers don't need to be unique: <DataGrid ItemsSource="{Binding Path=Contacts}" AutoGenerateColumns="False"> <DataGrid.Columns> <DataGridTextColumn Header="header1" Binding="{Binding Name}"/> <DataGridTextColumn Header="header2" Binding="{Binding Age}"/> <DataGridTextColumn Header="header1" Binding="{Binding Name}"/> <DataGridTextColumn Header="header2" Binding="{Binding Age}"/> </DataGrid.Columns> </DataGrid>

Categories : C#



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.