w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
While Sending Html Mails from my web application Recieved Mails contains Symbols like &ldquo,&rdquo, ‘
Check with another constructor for htmlView: ContentType mimeType = new System.Net.Mime.ContentType("text/html"); var htmlView = AlternateView.CreateAlternateViewFromString(bodyMessage, mimeType);

Categories : Asp Net Mvc

How can I use line.replace to add space around any brackets in a string that are elements in another bracket set, through a loop?
try with list operations: import functools def replaceif(x): if x in brackets: x=' '+x+' ' return x brackets = [')', '(', '{', '}', '[', '>', ']', '<'] string_line = '<[2{12.5 6.0}](3 -4 5)>' print(functools.reduce(lambda x,y: replaceif(x)+replaceif(y), string_line))

Categories : Python

How can I replace non zero elements randomly with zero in matlab?
The function find is your friend: indices = find(A); This will return an array of the indices of 1 elements in your matrix A and you can use your method of replacing a percent of elements with zero on a subset of this array. Then, A(subsetIndices) = 0; will replace the remaining indices of A with zero.

Categories : Matlab

How to randomly select elements with same class?
var items = $('.thumbnails'); var random = shuffle(items).slice(0, 3); Explanation: $('.thumbnails') selects all elements with class thumbnails shuffle() returns 3 random elements from the array (check out the link) .slice(0, 3) grabs the first 3 values of the shuffled array. Here's a Fiddle I made to see the result: Fiddle

Categories : Javascript

How to add elements randomly into a vector using push_back
You are updating refGiveCard, but you are adding giveCard. Therefore they are all the same value. There is also the fact that you are adding to a different vector than you might expect as jogojapan pointed out.

Categories : C++

how to replace some elements symmetrically with zero randomly?
Assuming it's an mxn matrix (m = n) and you want to replace k elements, you could do: %Find the indeces for the elements equal to 1 [onesX, onesY] = find(A == 1); numOnesX = size(onesX,1); numOnesY = size(onesY,1); % numOnesX and numOnesY should be the same %Generate a random set of elements to be replaced xRep = randperm(numOnesX); xRep = onesX(xRep(1:k)); yRep = randperm(numOnesY); yRep = onesY(yRep(1:k)); %Do the replacement A(xRep, yRep) = ~A(xRep, yRep); A(yRep, xRep) = ~A(yRep, xRep);

Categories : Matlab

Difference between using bracket (`[]`) and dot (`.`) notation
You should use . when you know the name of the property var object = {}; object.property = 'whatever'; , use [] when the name of the property is contained in a variable var object = {}; var property = 'another-property'; object[property] = 'whatever'; As @DCoder added certain object properties cannot be accessed without using the [] notation because their names break the syntax. E.g. properties named class, default, or data-prop-value

Categories : Javascript

Randomly select elements from a big text file
You could do like so : Get the size of the file (in bytes) Pick a byte (randomly chosen number in [0..file.length()] - RandomAccessFile) Seek to that position in the file (file.seek(number)) Seek to the position right after the next character (file.seek(1)) Read line (file.readLine()) for example... This way you don't have to store anything. A sample theoretic snippet could look like this (contains some side effects) : File f = new File("D:/abc.txt"); RandomAccessFile file; try { file = new RandomAccessFile(f, "r"); long file_size = file.length(); long chosen_byte = (long)(Math.random() * file_size); file.seek(chosen_byte); for (;;) { byte a_byte = file.readByte(); char wordChar = (char)a_byte; if (chosen_byte >= file_size || wo

Categories : Java

how to select randomly from the set of elements in a csv file in java?
In order to pick one of the set of values that has the same first value from the file, use a map structure with a list for the values. Like this: TreeMap<String, ArrayList<String>> When reading, add entries into the map, making sure to initialize the list for new keys, and add to the existing list for existing keys. The first value from the file is the key. The second is a value to insert into the ArrayList. Once the map is filled, iterate over the map keys (using a TreeMap, they will be in alphabetical order). On each iteration, find the size of the list, generate a random number between 0 and (size - 1), then pull out that element of the ArrayList. I hesitate to write code for this answer because this sounds a lot like a homework problem.

Categories : Java

Randomly changing colors of specified elements within one div or post
In order to recolor all elements fitting the selector you provide to JQuery, remove the .each() call from your code. In your example, replace: $(".post").each(function() { $(this).css('background-color', get_random_color()); }); with $(".post").css('background-color', get_random_color()); Then all elements with the class ".post" will be colored to the same random color all at once.

Categories : Jquery

How can a print elements in a list randomly in python?
Use random.shuffle() to shuffle a list, in-place: import random words = ["python", "java", "constant", "immutable"] random.shuffle(words) print(*words) input('') Demo: >>> import random >>> words = ["python", "java", "constant", "immutable"] >>> random.shuffle(words) >>> words ['python', 'java', 'constant', 'immutable'] If you wanted to preserve words (maintain the order), you can use sorted() with a random key to return a new randomized list: words = ["python", "java", "constant", "immutable"] print(*sorted(words, key=lambda k: random.random())) This leaves words unaltered: >>> words = ["python", "java", "constant", "immutable"] >>> sorted(words, key=lambda k: random.random()) ['immutable', 'java', 'constant', 'python'] >

Categories : Python

randomly separate a group of elements into several groups
You can use function sample() to get "a random permutation" of your original data and then select first 200, then 300 and so on. #original data x<-runif(1000) #random permutation y<-sample(x) #data selection y[1:200] y[201:500] y[501:1000]

Categories : R

Randomly storing elements from an array into a table
Use var countCells; var cardValues = []; var checker = true; var createTable = function (col, row) { $('table').empty(); for (var i = 0; i < col; i++) { $('table').append($('<tr>')); } for (var j = 0; j < row; j++) { $('tr').append($('<td>')); } countCells = row * col; }; createTable(3, 6); for (i = 0; i < countCells; i++) { cardValues.push(i % 9 + 1); } var giveCellValue = function () { var len = cardValues.length, tds = $('td'); for (var i = 0; i < len; i++) { var random = Math.floor(Math.random() * cardValues.length); tds.eq(i).append(cardValues.splice(random, 1)); } }; giveCellValue(); console.log(cardValues); Demo: Fiddle

Categories : Javascript

Array of length bracket notation
if u do a = [] a[3] = 100 the indices 0,1,2 will be filled in with undefined for u. u do not have to set a specific array length before using certain indices. array will grow as u use it. all these are the same: a = [,,,] b = [] b.length = 3 c = new Array(3) d = [] d[2] = undefined

Categories : Javascript

jQuery animation function to apply to elements randomly
This first part is to add the function shuffle to the javascript Array object Array.prototype.shuffle = function() { var i = this.length, j, temp; if ( i == 0 ) return this; while ( --i ) { j = Math.floor( Math.random() * ( i + 1 ) ); temp = this[i]; this[i] = this[j]; this[j] = temp; } return this; } Then var array = [1,2,3,4,5,6].shuffle(); var counter = 0 function drop_points(){ $('.c'+array[counter]).animate({top :'+=400'}, 700, 'easeOutBounce',function(){ counter++; if(counter<array.length-1)drop_points(); }); }

Categories : Javascript

Randomly assigning labels to elements in a 2 dimensional array in Python
I'm not sure the concept of labelling columns works here. These are not columns but elements with the same index point in multiple lists. Why not create a LabelList and use that to access the 'columns' you want. You can randomly order the LabelList import random LabelList = [1, 2, 3, 4] random.shuffle(LabelList) print LabelList Now you have a randomly ordered Label List, and you can use this in order to access your '4x4 Array' which is really a list of four lists in python terms. Now in each list within your array 'column1' is accessed by referencing LabelList[0] and so on. If you want to work in terms of pairs of columns the first two elements of the LabelList will refrence the index points in your lists that you are interested in pairing. for example: List = [[0, 1, 2, 3],[1, 0, 3,

Categories : Python

Math.random and splice to randomly delete array elements
You should be using c.splice(num, 1);, because you want to remove one element from the array at a time, not num elements. This updated fiddle logs the length after each removal, and always outputs 9,8,7,6,5.

Categories : Javascript

Force bracket notation when compiling from CoffeeScript to JavaScript
Well as I can see on js2coffee, the best way to accomplish that is: class test 'method': -> console.log 'this is a test method' And u will get this js output: var Test; Test = (function() { function Test() {} Test.prototype['method'] = function() { return console.log('this is a test method'); }; return Test; })(); By the way, I suggest for the minification/uglification to use Browserify.

Categories : Javascript

Construct object's square bracket notation from array values
You can use a loop: var o = myObject; for (var i = 0; i < yourArray.length; i++) { o = o[yourArray[i]]; } Or with Array.reduce, which looks nicer but won't work in older browsers: var o = { 'one': { 'two': { 'three': 'four' } } }; ['one', 'two', 'three'].reduce(function(object, key) { return object[key]; }, o);

Categories : Javascript

.appendTo within a for loop only works on half the elements
Your loop should be: for (i = 0; i < looper; i++) { $(this).children().eq(0).appendTo($(this).find('.holderjkdfgjkdfg')); } where eq(i) should be changed to eq(0) so that each time the loop ran, the top most 'img' tag was picked off. In your code, the first time the loop ran 'i' was 0 and this pointed to the first element which was then removed from the original div and moved to the '.holderjkdfgjkdfg' div. The second time the loop ran, there were only 3 elements in the original div but 'i' had incremented to 1. eq(1) would be the second element of the remaining 3 elements (which is in effect the third of the original 4 elements). Hope you understood that :).

Categories : Jquery

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

JQuery .hide function works okay with text fields but assigns a particular value to select box elements
Is there a "blank" value in your select box? If not, try this: <select id="mySelect"> <option value="">Please select an option</option> </select> Fiddle

Categories : Jquery

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

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

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

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

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

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

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

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++

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

variable turns to undefined inside a for loop
This is because getElementsByClassName returns a NodeList, which is live. That is, it updates itself when the elements it refers to change. When you remove the class attribute from an element in the NodeList, it gets removed from that list (since it no longer has the visible class name). You don't actually need to remove the attribute. Just setting it will do the job just as well. But since the NodeList is changing as you manipulate the elements it contains, you need to count backwards through it (as each time you change one element of it, it is removed so the length decreases by one): for (var i = elements.length - 1; i >= 0; i--) { elements[i].setAttribute("class", "hidden"); }

Categories : Javascript

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 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

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

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

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 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

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



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