w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How do I take a JS array that has some elements that are also arrays and make ALL array elements top level elements
You don't need the second step to have an array of arrays, just join then split it by the comma: var array = ["item1", "item2", "item3, item4", "item5", "item6"] console.log(array.join(',').split(',')); Example fiddle

Categories : Javascript

Conversion from dictionary to list preserving elements
Loop over the counter with a list comprehension: [list(k) + [v] for k, v in res.iteritems()] Demo: >>> from collections import Counter >>> res = Counter({('pintor', 'NCMS000'): 1, ('ser', 'VSIS3S0'): 1, ('muralista', 'AQ0CS0'): 1, ('diego_rivera', 'NP00000'): 1, ('frida_kahlo', 'NP00000'): 1, ('caso', 'NCMS000'): 1}) >>> [list(k) + [v] for k, v in res.iteritems()] [['pintor', 'NCMS000', 1], ['ser', 'VSIS3S0', 1], ['diego_rivera', 'NP00000', 1], ['frida_kahlo', 'NP00000', 1], ['muralista', 'AQ0CS0', 1], ['caso', 'NCMS000', 1]] If you wanted your values to be listed in sorted order, use .most_common() instead of .iteritems().

Categories : Python

CSS overlapping elements by preserving parent size
If it's ok to use jQuery, this can be done quite easily. Set the overflow property of the parent element to scroll: .designer-question { overflow: scroll; } And then you can set the height of each .designer-question to the height of its img using a simple each loop: $('.designer-question').each(function () { var $el = $(this); // Get jQuery of each designer question var $backImg = $('.back img', $el); // Get background image $el.css('height', $backImg.height()); }); I've applied this to your jsfiddle to demonstrate: http://jsfiddle.net/jfdPb/1/

Categories : CSS

Comparing class member array elements and main elements
Your canswers member is not a valid declaration. It is likely using an extension provided by your compiler to support the C flexible array member. This will act like a 0 sized array, and your access to the canswers variable are thus reading and writing beyond the object boundary, resultig in undefined behavior. You should either declare canswers with the right array size, or allow it to be a vector<char> or array<char, 20> instead. For vector<char>: class TestGrade { public: void setKey(char []); void grade(char []); std::vector<char> canswers; void display(); }; If you use vector<char>, you would need to change how you implement setKey(). void TestGrade::setKey(char answers[]) //setting values from "key" array in main { canswers.clear

Categories : C++

Efficient way to check if elements of an array is a substring of elements in another array
die if @array1 != @array2; for (0..$#array1) { die if $array2[$_] ne qq{Name: creating "$array1[$_]"}; } or if the Name part is variable, die if @array1 != @array2; for (0..$#array1) { die if $array2[$_] !~ /: creating "Q$array1[$_]E"$/; }

Categories : Arrays

How can I rotate an element without covering the elements under it?
In pure CSS, no. But you can use jQuery to set some new margins: var e = $(el); e.css({ 'margin-bottom': (e.width( ) * Math.abs( Math.sin( degree * Math.PI / 180.0 ) ) + e.height( ) * (Math.abs( Math.cos( degree * Math.PI / 180.0 ) ) - 1)) / 2 }); Fiddle: http://jsfiddle.net/8pFUB/21/ Also to reply to Colonel Panic's answer, here is a version which sets all 4 margins: http://jsfiddle.net/8pFUB/24/. It's a bit less elegant in the rotation, so I'd suggest only setting the margins you actually want to change. Full (adapted) code: function setPaddedRotation( element, degree ) { var e = $(element); var rads = degree * Math.PI / 180.0; var ss = Math.abs( Math.sin( rads ) ); var cc = Math.abs( Math.cos( rads ) ); var padx = (e.height( ) * ss + e.width( ) * (cc - 1))

Categories : Javascript

How to replace elements in array with elements of another array
You can use the splice method to replace part of an array with items from another array, but you have to call it in a special way as it expects the items as parameters, not the array. The splice method expects parameters like (0, anotherArr.Length, 1, 2, 3), so you need to create an array with the parameters and use the apply method to call the splice method with the parameters: Array.prototype.splice.apply(arr, [0, anotherArr.length].concat(anotherArr)); Example: var arr = [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']; var anotherArr = [ 1, 2, 3 ]; Array.prototype.splice.apply(arr, [0, anotherArr.length].concat(anotherArr)); console.log(arr); Output: [ 1, 2, 3, 'd', 'e', 'f', 'g', 'h', 'i', 'j'] Demo: http://jsfiddle.net/Guffa/bB7Ey/

Categories : Javascript

How to convert array with elements utf8 strings to NSArray with elements utf8 strings in objective c
I assume utfStringArray is terminated with a NULL, else you'll need to provide the element count separately. I am also assuming ARC. Note I am using NSData as you have stipulated that NSString's cannot be used (for some reason): unsigned char **utfStringArray = ...; NSMutableArray *array = [[NSMutableArray alloc] init]; for (unsigned i = 0; utfStringArray[i] != NULL; i++) { NSData *data = [NSData dataWithBytes:utfStringArray[i] length:strlen(utfStringArray[i])]; [array addObject:data]; }

Categories : Objective C

In Firefox SPAN elements cannot be dynamically added to elements with -column-width values
Solved it. As I suspected, its a matter of forcing Firefox to redraw elements. The problem is fixed after adding the following line to the addSpan( ) function. document.getElementById("content").innerHTML = document.getElementById("content").innerHTML;

Categories : HTML

Dynamically adding elements to jQuery Mobile , when these elements are retrieved Asynchronously?
Try to populate your list where you're building your albums arrays. var myList = $("ul"); // better save this in a var for (i=0; i<response.data.length; i++) { myList.append('<li><img src="' + response.data[i].cover_photo + '" /><h2>' + response.data[i].name + '</h2></li>').listview('refresh'); } Also, it seems you won't need these data arrays anymore unless you plan to do some additional things with it.

Categories : Jquery

String gsub - Replace characters between two elements, but leave surrounding elements
You can do it using this character class : [^/] (all that is not a slash) and lookarounds mystring.gsub(/(?<=start/)[^/]+(?=/end)/,"7")

Categories : Ruby

Do elements with "position: absolute;" behave as block-level elements?
A <div> element is not inline while a <span> element is. Here's the definition of absolute from position: absolute - The element is positioned relative to its first positioned (not static) ancestor element. So the answer to your questions is yes: span elements with display: block display as somewhat block-level elements. Let me know if you still need clarification.

Categories : CSS

alternative to a for loop for replacing a subset of elements in a matrix with elements in a vector in R
The items you are comparing are of different classes: character and Dates. (I get an entire matrix filled with 1's.) Try this: mydates <- as.Date(mydates) # then the comparisons will more sensible It get to a vectorized answer I resorted to the use of outer and rearranged the logic a bit to create a matrix with the "new" values, and then set the failing items back to strating value of 1: myarray2 <-matrix(mycons, nrow=length(dates), ncol=length(mydates), byrow=TRUE) myarray2[ outer(dates, mydates, "<=") ] <- 1 myarray2 I tried using mapply thinking I could do something like to pass "parallel items" from two sequences but there is no way that I could get the "i" indexing to take hold. mapply(function(x,y) {myarray[i , ] <- y[x>dates]} , mydates,

Categories : R

What best way to populate java list with separate elements and elements from other lists?
You could at least introduce a loop: List<WebElement> containers = Arrays.asList(inetConnection, wiredConnection, phonesConnection, usbConnection, wifiConnection); List<WebElement> list = new LinkedList<WebElement>(containers); for (WebElement e : containers) list.addAll(e.getExpectedElements());

Categories : Java

Removing elements that have no attributes, child elements, or text during transform
This should do the job: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt"> <xsl:output indent="yes" method="xml" omit-xml-declaration="yes"/> <xsl:strip-space elements="*"/> <!-- Elements/attributes to remove. Note that comments are not elements or attributes. Since there is no template to match comments they are automatically ignored. --> <xsl:template match="@*[normalize-space()='']|info|@file_line_nr|@file_name"/> <!-- Match any attribute --> <xsl:template match="@*"> <xsl:copy> <xsl:apply-templates select="@*"/> </xsl:copy> </xsl:template> <!-- Match any element --> &l

Categories : Xml

Backbone Collection Set method remove existing elements and then add all elements
From the docs The set method performs a "smart" update of the collection with the passed list of models. If a model in the list isn't yet in the collection it will be added; if the model is already in the collection its attributes will be merged; and if the collection contains any models that aren't present in the list, they'll be removed. It is also a good idea to provide `idAttribute' to the model so that the collection identifies that based on the id. Otherwise the collection would not know if the model is a new one or not. So after setting the id and using set, you can see that is performs a smart update $(function () { var MyModel = Backbone.Model.extend({ // This attribute should be set as a default defaults: { Name: '' },

Categories : Backbone Js

extract elements from list of lists with variable number of elements and NAs R
So this can be marked as answered: SimonO101's solution (checking for NA values): lapply(mytestlist, function(x) { if( all(is.na(x)) ){ c(a=0,b=1,c=0) } else { x$nums } }) My solution (checking for named list elements): lapply(mytestlist, function(x) { if('nums' %in% names(x)) { x$nums } else { c(a=0, b=1, c=0) } })

Categories : R

How to add elements from sublists with 2 elements (the first element is a string and the second one a number)?
You just need to break out the string versus the number: sum_fire( [[_,N]|Tail], Sum ) :- sum_fire( Tail, S1 ), Sum is N + S1. sum_fire( [], 0 ). So I'm using [_,N] instead of H for the head item because I want what's inside (the number N). I don't care about the string for the sum, so it's _.

Categories : Prolog

check if matrixs elements are all not equal or deferent elements
I recommend using the unique command. It will return the values of all unique values. If you want to check that all values in your matrix v are unique, I would use the following command: everything_is_unique = length(unique(v))==length(v); You can also return the indices of the equal elements. See the documentation on unique for more information.

Categories : Matlab

Check all tr elements for visibility:hidden between two same class tr elements
Try this - $('tr.header').each(function(){ if ($(this).nextUntil("tr.header").filter(function(){ return $(this).is(':visible'); }).length == 0){ $(this).hide(); } else { $(this).show() } });

Categories : Jquery

How to make html elements fire effects on other elements using css
You can try this: .view-first { opacity: 0; /*more properties here*/} .myDiv:hover ~ .view-first{ -webkit-animation: boxanimation 1.5s; opacity: 1; -webkit-transition: all 0s; -webkit-animation-fill-mode: initial; /*more properties here*/} This will work for chrom and safary, for more broser you can set the -moz for firefox, and -o for opera

Categories : HTML

HTML Elements whose parent elements are transparent won't go opaque
Children can't have a higher opacity than their parents as their opacities multiply. You use could png backgrounds or rgba colors: http://css-tricks.com/rgba-browser-support/ div { background-color: rgba(255,255,255,0.5); }

Categories : HTML

How do you expand all elements in the WebKit Inspector elements view?
Here's how i've decided to do it: Highlight the element tag I wish to inspect, if it's the whole (expand all) the requirement, then highlight <body> tag, click F2. Note: F2 is actually the shortcut for 'Toggle edit as HTML'. You can directly make any change in this mode, changes are reflected on web page. You may right-click within this new code view-window and enable/disable wordwrap.

Categories : Google Chrome

jQuery select elements only if they aren't nested within like elements
Try using the jQuery :not selector $('.a:not(.a .a)') http://jsfiddle.net/7E7Mk/1/

Categories : Javascript

how to combine extjs graphical elements and easelJs elements
From a quick look at it, easel doesn't seem to pollute the global namespace, and nor does Ext4, so there is no reason they can't play well on the same page. I have tested this theory in this fiddle, and it indeed works. I hope the following code can get you started. It is using the html option of the window to create the canvas. Ext.define('EaselWindow', { extend: 'Ext.Window' ,html: '<canvas id="demoCanvas" width="500" height="300">' + 'alternate content' + '</canvas>' // The canvas markup will only be available after the window has rendered. // This is a useful protected method, but you could use a afterrender event instead. ,afterRender: function() { this.callParent(arguments); // The canvas is available to do easel s

Categories : Javascript

Sequence contains no elements for Query with Multiple Elements Possible
If the sequence is empty and you iterate over it, nothing should happen, which is the semantic you usually want (and what you're looking for as well). What exactly is the iteration code you're using? A foreach shouldn't have any problems with an empty sequence.

Categories : C#

How to change origin of elements based on another elements in ios
You could use the previous frame, since you are using [label1 sizeToFit]; Example below for label 2: UILabel *label2 =[[ UILabel alloc]init]; label2.frame=CGRectMake(10, label1.frame.origin.y+label1.frame.size.height+30, 10, 150); label2.text=@"Preferred Dress Style";

Categories : IOS

Float box to the right and let it overlap elements below static elements
without giving it too much thought, you could let it float and apply clear[left|right] - whichever suits your needs. Depending the surrounding rules, you may need to set clear also to the image, preferably with a value of [none]. That should let the image flow and the box float without either one getting in the way of the other.

Categories : CSS

HTML overlapping elements in absolute elements
Your problem is how the z-index stacking works. In this case, you actually need to put a z-index on #content that is higher than the z-index of #menu, as those two elements exist in the same stacking context. Two elements are only in the same stacking context if they are direct siblings. In this case, #content and #menu are siblings. You can z-index #content>.layoutOuter all you want but if the z-index of #menu is higher than the z-index of #content, #menu will display higher than it no matter the values.

Categories : HTML

How to fetch attribute value under elements/elements in xml using LINQ
To get the value attribute you can use the following: var foo = (from n in xml.Descendants("property") where n.Attribute("name").Value == "TestcaseId" select n.Attribute("value").Value).FirstOrDefault(); Gives: 70592

Categories : C#

Is there a way to tell crossfilter to treat elements of array as separate records instead of treating whole array as single key?
Solved it myself, here's fiddle with working code http://jsfiddle.net/uhXf5/6/ Here's code in case someone will came across similar problem: function reduceAdd(p, v) { v.tags.forEach (function(val, idx) { p[val] = (p[val] || 0) + 1; //increment counts }); return p; } function reduceRemove(p, v) { v.tags.forEach (function(val, idx) { p[val] = (p[val] || 0) - 1; //decrement counts }); return p; } function reduceInitial() { return {}; } var data = [ {"key":"KEY-1","tags":["tag1", "tag2"], "date":new Date("10/02/2012")}, {"key":"KEY-2","tags":["tag2"], "date": new Date("10/05/2012")}, {"key":"KEY-3","tags":["tag3", "tag1"], "date":new Date("10/08/2012")}]; var cf = crossfilter(data); var tags = cf.dimension(function(d){ return d.tags;}); var tagsG

Categories : Javascript

inserting elements into array creates nested array where they aren't wanted
You are getting the post meta data and putting them back onto the same array, $voters. You should either assign the $voter_id ahead of time and use it as the key before you use post_meta_data, or use a different variable to store it. If you mean use $voter_id as a key ahead of time, have you tried this: //initialize vote arrays and vars $quarter = substr($date, 1,1); $year = substr($date, 2,4); $votes = $_POST['votes']; $voter_id = $_POST['voter_id']; $voting_array = array(); $current_vote = array(); $voters[$voter_id] = get_post_meta(2165, 'bonus_votesq'. $quarter . $year); parse_str($votes, $voting_array); foreach ($voting_array as $vid => $awarded_points) { $current_vote[sanitize_key($vid)] = sanitize_key($awarded_points); } // push the local array into what will be the gl

Categories : PHP

Initializing multidimensial array with unknown size array elements gives error
It's a warning, because you should write like this instead: char list_ch[][2] = { {'a', 'A'}, {'b', 'B'}, {'c', 'C'}, {'d', 'D'}, {'e', 'E'}, {'f', 'F'}, {'g', 'G'}};

Categories : C

After deleting the particular multidimensional array element in PHP, the Next array elements are not positioning automatically
Using unset doesn't alter the indexing of the Array. You probably want to use array_splice. http://www.php.net/manual/en/function.array-splice.php http://php.net/manual/en/function.unset.php

Categories : PHP

Jquery Array. How to display array elements that match if statements at once?
Rather than over-write your HTML each time, start appending: var current = $('#errors').html(); $('#errors').html( current + " " + error[ i ] ); Appending a ul of errors may be more appropriate, but this will get you started.

Categories : Javascript

MongoDB Full Text on an Array within an Array of Elements
Text search does not currently support indexed fields of nested arrays (at least not explicitly specified ones). An index on "foo.name" works fine as it is only one array deep, but the text search will not recurse through the subarray at "foo.data.text". Note that this behavior may change in the 2.6 release. But fear not, in the meantime nested arrays can be text-indexed, just not with individually specified fields. You may use the wildcard specifier $** to recursively index ALL string fields in your collection, i.e. db.collection.ensureIndex({"$**": "text" } as documented at http://docs.mongodb.org/manual/tutorial/create-text-index-on-multiple-fields/ . Be careful though as this will index EVERY string field and could have negative storage and performance consequences. The simple docu

Categories : Mongodb

How do I sort an array in Perl if not all of the elements in the array are defined?
undef will is lower than any string, this is why it get's sorted at the beginning. What you probably want is a "cleaned" result array with all undef elements removed? If so, here: #!/usr/bin/perl use strict; use Data::Dumper; my @names; $names[1] = 'alpha'; $names[3] = 'gamma'; $names[10] = 'beta'; @names = sort grep { defined } @names; print Dumper(@names); # $VAR1 = [ # 'alpha', # 'beta', # 'gamma' # ];

Categories : Arrays

longest repeated subset of array elements in given array
Loop through the array, then in the inner loop to search all possible sub-string lengths. The maximum re-occuring sub-string can only a maximum of half the array length. Use indexOf and indexLastOf functions to search for a re-occuring sub-string. If both functions find the sub-string and the positions found differ, then the sub-string has re-occurred. my_array = ['b','r','o','w','n','f','o','x','h','u','n','t','e','r','n','f','o','x','r','y','h','u','n']; str = my_array.join(''); var greatestLen = 0; var highestPosn1 = -1; var highestPosn2 = -1; for (var n = 0; n < my_array.length; ++n) { for (var l = 1; l <= my_array.length/2; ++l) { var subs = str.substr(n,l); var find1 = str.indexOf(subs); var find2 =

Categories : Javascript

How do I replace repetitive elements in an array matching another array?
array_main.map { |e| array_second.include?( e ) ? 0 : e } And if you drop that requirement about replacing with 0, you can simply write array_main - array_second

Categories : Ruby On Rails

Javascript - Access elements of array using an array of indices
You can make one and have it available to all Arrays if you've no qualms about extending native prototypes in your environment. Array.prototype.atIndices = function(ind) { var result = []; for (var i = 0; i < arguments.length; i++) { if (arguments[i] in this) result.push(this[arguments[i]]) } return result; } var result = array.atIndices(1,3); You could also have it check to see if an Array was passed, or a mix of indices and Arrays. Array.prototype.atIndices = function(ind) { var result = []; for (var i = 0; i < arguments.length; i++) { if (Array.isArray(arguments[i])) result.push.apply(result, this.atIndices.apply(this, arguments[i])) else if (arguments[i] in this) result.push(this

Categories : Javascript



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