qid
int64
1
74.7M
question
stringlengths
0
58.3k
date
stringlengths
10
10
metadata
list
response_j
stringlengths
2
48.3k
response_k
stringlengths
2
40.5k
26,081,941
i'm a beginner into Symfony2 and i hope that the community could help me and another peoples with this problem. I have 2 forms sent to the views, that i render these 2 into 2 differents blocks (main-col and left-col), in fact main-col contains user profile form and left-col contains form to upload the profile picture ...
2014/09/28
[ "https://Stackoverflow.com/questions/26081941", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
You can use the csv reader library in python: <https://docs.python.org/2/library/csv.html> It will be something like this: ``` >>> import csv >>> with open('output.txt', 'r') as csvfile: ... data = csv.reader(csvfile, delimiter='\t') ... print data [["1", "2"], ["3.4", "5"], ...] ``` You will need to conver...
``` file=open('output.txt', "r") for line in file: list.append(float(line.split("\t")[0])) list.append(float(line.split("\t")[1])) file.close() ``` If you require ints and floats to be stored as different types and not just have float representation of integers, then you would need to try-catch to see if you...
29,202,849
From here <http://blog.golang.org/slices> (it's right before the Capacity section) ``` type path []byte func (p path) ToUpper() { for i, b := range p { if 'a' <= b && b <= 'z' { p[i] = b + 'A' - 'a' } } } func main() { pathName := path("/usr/bin/tso") pathName.ToUpper() ...
2015/03/23
[ "https://Stackoverflow.com/questions/29202849", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4283659/" ]
You should use `rune` when you use unicode. The `unicode` package in golang has a toUpper function. ``` package main import ( "unicode" "fmt" ) type path []rune func (p path) ToUpper() { for i, b := range p { p[i] = unicode.ToUpper(b) } } func main() { pathName := path("/usr/bin/tso") ...
You can use `strings.Map` to apply a function to each rune of a string, returning the mapped string. [Playground link to this code:](https://play.golang.org/p/5Fm3Tc7RjC) ``` package main import ( "fmt" "strings" "unicode" ) func main() { pathName := strings.Map(unicode.ToUpper, "/usr/bin/tso") f...
34,544,187
I am newbie to git, I want to get update from remote to local only in particular folder of the local branch for that i did the below: ``` git fetch git checkout origin/branch-name -- /path/to/particular/folder ``` I got the latest code to that particular folder but when I perform `git status` it shows the file which...
2015/12/31
[ "https://Stackoverflow.com/questions/34544187", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5733490/" ]
When you `checkout` only particular file or folder, it changes your working directory. So obviously those files are in `modified` status. If you want everything to be `up-to-date` - You need to commit those files to your local branch. You should ask yourself - why do you checkout only particular file or folder? This ...
i agree with lgal S said also you can `git stash` your code and then `pull` your update code and then apply change after you finish it the good about `git stash` is you don't have to commit your change if not finish yet you just keep it and `pull` your updates then back to your work and after finish it your can `commi...
34,544,187
I am newbie to git, I want to get update from remote to local only in particular folder of the local branch for that i did the below: ``` git fetch git checkout origin/branch-name -- /path/to/particular/folder ``` I got the latest code to that particular folder but when I perform `git status` it shows the file which...
2015/12/31
[ "https://Stackoverflow.com/questions/34544187", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5733490/" ]
Seems that you're working with GIT in the wrong way because - not like in other source-control systems - a file or folder is not something that stand for itself. You probably want to take changes that were made on one commit (probably on a different branch) into your local branch. If that is the case then the best acti...
i agree with lgal S said also you can `git stash` your code and then `pull` your update code and then apply change after you finish it the good about `git stash` is you don't have to commit your change if not finish yet you just keep it and `pull` your updates then back to your work and after finish it your can `commi...
34,544,187
I am newbie to git, I want to get update from remote to local only in particular folder of the local branch for that i did the below: ``` git fetch git checkout origin/branch-name -- /path/to/particular/folder ``` I got the latest code to that particular folder but when I perform `git status` it shows the file which...
2015/12/31
[ "https://Stackoverflow.com/questions/34544187", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5733490/" ]
Git is not SVN. You don't checkout a revision into a certain folder. You have **one** working copy. In that working copy you can ``` git checkout branchname ``` in order to check out a single branch in this working copy. If you want to simultaneously check out two different branches of the same repo, you need two w...
i agree with lgal S said also you can `git stash` your code and then `pull` your update code and then apply change after you finish it the good about `git stash` is you don't have to commit your change if not finish yet you just keep it and `pull` your updates then back to your work and after finish it your can `commi...
61,563,049
Having a dataframe like this ``` df <- data.frame(ID = sample(rep(letters, each=3)), value = rnorm(n=26*3)) keep <- c("a", "d", "r", "x") ``` How is it possible to keep both "a" and "d" example using something like this: `df[df$ID == "a"|"d", ]`
2020/05/02
[ "https://Stackoverflow.com/questions/61563049", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11786778/" ]
Use `%in%` ```r df[df$ID %in% c("a","d"), ] ```
We can use base R function `which()`. `which()` returns indexes where given condition is met. ``` df[which(df$ID == "a" | df$ID == "d"),] ```
61,563,049
Having a dataframe like this ``` df <- data.frame(ID = sample(rep(letters, each=3)), value = rnorm(n=26*3)) keep <- c("a", "d", "r", "x") ``` How is it possible to keep both "a" and "d" example using something like this: `df[df$ID == "a"|"d", ]`
2020/05/02
[ "https://Stackoverflow.com/questions/61563049", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11786778/" ]
Use `%in%` ```r df[df$ID %in% c("a","d"), ] ```
An option with `%chin%` ``` library(data.table) setDT(df)[ID %chin% c('a', 'd')] ```
13,703,365
I have several inputs: ``` <input name="row.type[0].value"> <input name="row.type[1].value"> .... <input name="row.type[100].value"> ``` How can I to obtain an array with all these inputs? If with $$-operation, then something like that doesn't work: ``` var cabins = $$('input[name^=row.type[].value]').each(functio...
2012/12/04
[ "https://Stackoverflow.com/questions/13703365", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1274295/" ]
If all the inputs you want to grab have a name starting with `row.type[`, then you can grab them all using `$$()` like this: ``` var cabins = $$('input[name^="row.type["]'); ```
if you add a class to all of the input fields you can access them using the class for instance ``` <input class="rowvalues" name="row.type[0].value"> <input class="rowvalues" name="row.type[1].value"> .... <input class="rowvalues" name="row.type[100].value"> ``` then using `$$()` ``` var cabins = $$('.rowvalues')...
326,232
Let $f(x)=x \psi(x+1)$, where $\psi$ is the digamma function. Define $$g(x)=(f(ax)+f((1-a)x)-f(x))-(f(ax+by)+f((1-a)x+(1-b)y)-f(x+y)),$$ where $0\le a,b\le 1$ and $x,y\ge 0$. How to show that $g(x)$ is increasing in $x$ on $[0,\infty)$? Thank you! --- Here is what I have tried. Let $h(x,y)=f(ax+by)+f((1-a)x+(1-b)y)...
2019/03/24
[ "https://mathoverflow.net/questions/326232", "https://mathoverflow.net", "https://mathoverflow.net/users/33278/" ]
Numerical evidence suggests that for any $a\in(0,1]$ and $x\geq 0$, we have $$(\star)\qquad f''(ax)\leq \frac{f''(x)}{a}.$$ The inequality $(\star)$ allows to easily prove that $$f''(x+y)\ge abf''(ax+by)+(1-a)(1-b)f''((1-a)x+(1-b)y).$$ Indeed, we have $f''(ax+by) = f''(\frac{ax+by}{x+y}(x+y)) \leq \frac{x+y}{ax+by} f...
Inspired by Max's answer, I finally have a proof for the inequality $$h(x)\triangleq f''(x)-a f''(ax)\ge 0.$$ Recall that $\psi\_k(z)\triangleq \frac{d^k}{dz^k}\psi(z)$. Using the two-sided approximation presented in <https://arxiv.org/abs/0903.1984> $$\frac{(k-1)!}{\Bigl\{x+\Bigl[\frac{(k-1)!}{|\psi\_k(1)|}\Bigr]^{1/...
326,232
Let $f(x)=x \psi(x+1)$, where $\psi$ is the digamma function. Define $$g(x)=(f(ax)+f((1-a)x)-f(x))-(f(ax+by)+f((1-a)x+(1-b)y)-f(x+y)),$$ where $0\le a,b\le 1$ and $x,y\ge 0$. How to show that $g(x)$ is increasing in $x$ on $[0,\infty)$? Thank you! --- Here is what I have tried. Let $h(x,y)=f(ax+by)+f((1-a)x+(1-b)y)...
2019/03/24
[ "https://mathoverflow.net/questions/326232", "https://mathoverflow.net", "https://mathoverflow.net/users/33278/" ]
Max reduced the problem to proving that $(xf'')'\geqslant 0$. We have $f=x\psi(x+1)=1+x\psi(x)$, so $f''=(x\psi(x))''=x\psi''+2\psi'$, $f'''=x\psi'''+3\psi''$,$(xf'')'=xf'''+f''=x^2\psi'''+4x\psi''+2\psi'$. Exactly this guy is proved to be non-negative in the recent clever [MO answer](https://mathoverflow.net/questions...
Numerical evidence suggests that for any $a\in(0,1]$ and $x\geq 0$, we have $$(\star)\qquad f''(ax)\leq \frac{f''(x)}{a}.$$ The inequality $(\star)$ allows to easily prove that $$f''(x+y)\ge abf''(ax+by)+(1-a)(1-b)f''((1-a)x+(1-b)y).$$ Indeed, we have $f''(ax+by) = f''(\frac{ax+by}{x+y}(x+y)) \leq \frac{x+y}{ax+by} f...
326,232
Let $f(x)=x \psi(x+1)$, where $\psi$ is the digamma function. Define $$g(x)=(f(ax)+f((1-a)x)-f(x))-(f(ax+by)+f((1-a)x+(1-b)y)-f(x+y)),$$ where $0\le a,b\le 1$ and $x,y\ge 0$. How to show that $g(x)$ is increasing in $x$ on $[0,\infty)$? Thank you! --- Here is what I have tried. Let $h(x,y)=f(ax+by)+f((1-a)x+(1-b)y)...
2019/03/24
[ "https://mathoverflow.net/questions/326232", "https://mathoverflow.net", "https://mathoverflow.net/users/33278/" ]
Max reduced the problem to proving that $(xf'')'\geqslant 0$. We have $f=x\psi(x+1)=1+x\psi(x)$, so $f''=(x\psi(x))''=x\psi''+2\psi'$, $f'''=x\psi'''+3\psi''$,$(xf'')'=xf'''+f''=x^2\psi'''+4x\psi''+2\psi'$. Exactly this guy is proved to be non-negative in the recent clever [MO answer](https://mathoverflow.net/questions...
Inspired by Max's answer, I finally have a proof for the inequality $$h(x)\triangleq f''(x)-a f''(ax)\ge 0.$$ Recall that $\psi\_k(z)\triangleq \frac{d^k}{dz^k}\psi(z)$. Using the two-sided approximation presented in <https://arxiv.org/abs/0903.1984> $$\frac{(k-1)!}{\Bigl\{x+\Bigl[\frac{(k-1)!}{|\psi\_k(1)|}\Bigr]^{1/...
2,423,902
I'm trying to write function that converts an arbitrary large array of bytes (larger than 64-bit) into a decimal number represented as string in c# and I simply can't figure out how to do it. For example the following code ... ``` Console.WriteLine(ConvertToString( new byte[] { 0x11, 0x22, 0x33, 0x44, 0x55, ...
2010/03/11
[ "https://Stackoverflow.com/questions/2423902", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25782/" ]
Some guidelines: 1. You will need to save the digits of the number in a matrix, one space for each digit. The matrix starts empty. 2. Then you need a matrix to save the multiplication of the matrix. It too starts empty. 3. Now for each byte you have: 1. First multiply each digit of the current number matrix by 256, s...
Would [System.Decimal](http://msdn.microsoft.com/en-us/library/system.decimal.aspx) meet your needs?
2,423,902
I'm trying to write function that converts an arbitrary large array of bytes (larger than 64-bit) into a decimal number represented as string in c# and I simply can't figure out how to do it. For example the following code ... ``` Console.WriteLine(ConvertToString( new byte[] { 0x11, 0x22, 0x33, 0x44, 0x55, ...
2010/03/11
[ "https://Stackoverflow.com/questions/2423902", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25782/" ]
You want to understand the workings so take a look at *super cool* [C# BigInteger Class @ CodeProject](http://www.codeproject.com/KB/cs/biginteger.aspx). Also, I have stripped that class to bare essentials for this question. It can be optimized further. :) Try copy and paste following code it works!! ``` using Syste...
Would [System.Decimal](http://msdn.microsoft.com/en-us/library/system.decimal.aspx) meet your needs?
2,423,902
I'm trying to write function that converts an arbitrary large array of bytes (larger than 64-bit) into a decimal number represented as string in c# and I simply can't figure out how to do it. For example the following code ... ``` Console.WriteLine(ConvertToString( new byte[] { 0x11, 0x22, 0x33, 0x44, 0x55, ...
2010/03/11
[ "https://Stackoverflow.com/questions/2423902", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25782/" ]
Based on @Wilheim's answer: ``` static string BytesToString(byte[] data) { // Minimum length 1. if (data.Length == 0) return "0"; // length <= digits.Length. var digits = new byte[(data.Length * 0x00026882/* (int)(Math.Log(2, 10) * 0x80000) */ + 0xFFFF) >> 16]; int length = 1; // For each byt...
Would [System.Decimal](http://msdn.microsoft.com/en-us/library/system.decimal.aspx) meet your needs?
2,423,902
I'm trying to write function that converts an arbitrary large array of bytes (larger than 64-bit) into a decimal number represented as string in c# and I simply can't figure out how to do it. For example the following code ... ``` Console.WriteLine(ConvertToString( new byte[] { 0x11, 0x22, 0x33, 0x44, 0x55, ...
2010/03/11
[ "https://Stackoverflow.com/questions/2423902", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25782/" ]
Some guidelines: 1. You will need to save the digits of the number in a matrix, one space for each digit. The matrix starts empty. 2. Then you need a matrix to save the multiplication of the matrix. It too starts empty. 3. Now for each byte you have: 1. First multiply each digit of the current number matrix by 256, s...
You want to understand the workings so take a look at *super cool* [C# BigInteger Class @ CodeProject](http://www.codeproject.com/KB/cs/biginteger.aspx). Also, I have stripped that class to bare essentials for this question. It can be optimized further. :) Try copy and paste following code it works!! ``` using Syste...
2,423,902
I'm trying to write function that converts an arbitrary large array of bytes (larger than 64-bit) into a decimal number represented as string in c# and I simply can't figure out how to do it. For example the following code ... ``` Console.WriteLine(ConvertToString( new byte[] { 0x11, 0x22, 0x33, 0x44, 0x55, ...
2010/03/11
[ "https://Stackoverflow.com/questions/2423902", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25782/" ]
Based on @Wilheim's answer: ``` static string BytesToString(byte[] data) { // Minimum length 1. if (data.Length == 0) return "0"; // length <= digits.Length. var digits = new byte[(data.Length * 0x00026882/* (int)(Math.Log(2, 10) * 0x80000) */ + 0xFFFF) >> 16]; int length = 1; // For each byt...
You want to understand the workings so take a look at *super cool* [C# BigInteger Class @ CodeProject](http://www.codeproject.com/KB/cs/biginteger.aspx). Also, I have stripped that class to bare essentials for this question. It can be optimized further. :) Try copy and paste following code it works!! ``` using Syste...
41,634,433
In my current scenario I have 6 equally spaced blocks 3 by 3 using Bootstrap and col-\*-4. These blocks are just slightly styled thumb-nails (still using Bootstrap 3). In these boxes I have text at the bottom, which I have positioned with: `position: absolute; bottom:0;` As well as this I have an image above which I...
2017/01/13
[ "https://Stackoverflow.com/questions/41634433", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6744223/" ]
Setup correct relationships first. `Book` has many `Printing`. `Printing` belongs to a `Publisher`. ``` Book::whereHas('printings', function($q) use($id) { $q->where('publisher_id', $id); })->get(); ```
This is how you generally do it: ``` Books::with(['printings' => function ($q) use ($id) { // Query on the relationship $q->where('publishers', $id); }])->get(); ``` **Edit:** I misunderstood the question. As @AlexeyMezenin answered, what you're looking for is `->whereHas`. ``` Books::whereHas('printings',...
10,307,606
how can i do this? is it possible to have a text hyperlink and once its hovered over, that text link becomes an image? iv seen image rollovers but haven't seen or know how to code text to image rollover yet. i just dont know where to begin and with what programming language. javascript? php? jquery? i started of b...
2012/04/24
[ "https://Stackoverflow.com/questions/10307606", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1291802/" ]
You ca in do in a lots of ways, here is a CSS rough example, just to see the idea [**try this**](http://jsfiddle.net/dd5ym/3/)
Assuming HTML similar to the following: ``` <a href="http://www.example.com/image.png" class="textToImg">Some text</a> ``` The following JavaScript should work: ``` function textToImage(elem){ if (!elem) { return false; } else { var img = document.createElement('img'); img.src = ...
10,307,606
how can i do this? is it possible to have a text hyperlink and once its hovered over, that text link becomes an image? iv seen image rollovers but haven't seen or know how to code text to image rollover yet. i just dont know where to begin and with what programming language. javascript? php? jquery? i started of b...
2012/04/24
[ "https://Stackoverflow.com/questions/10307606", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1291802/" ]
You ca in do in a lots of ways, here is a CSS rough example, just to see the idea [**try this**](http://jsfiddle.net/dd5ym/3/)
Here is a javascript way to do it ``` <div id="link"> <a href = "#" onmouseover = "document.getElementById('link').style.display='none';document.getElementById('hoverImage').style.display='block';;">Mouseover here</a> </div> <div id="hoverImage" style="display:none"> <img name = "img" alt = "" border...
10,307,606
how can i do this? is it possible to have a text hyperlink and once its hovered over, that text link becomes an image? iv seen image rollovers but haven't seen or know how to code text to image rollover yet. i just dont know where to begin and with what programming language. javascript? php? jquery? i started of b...
2012/04/24
[ "https://Stackoverflow.com/questions/10307606", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1291802/" ]
You ca in do in a lots of ways, here is a CSS rough example, just to see the idea [**try this**](http://jsfiddle.net/dd5ym/3/)
This can also be done with jQuery: `**[See In Action](http://jsfiddle.net/pkZAW/)**` ``` <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> </head> <body> <script type='text/javascript'> $( function() { $("#imglink").hover( function () { $(this).attr('s...
10,307,606
how can i do this? is it possible to have a text hyperlink and once its hovered over, that text link becomes an image? iv seen image rollovers but haven't seen or know how to code text to image rollover yet. i just dont know where to begin and with what programming language. javascript? php? jquery? i started of b...
2012/04/24
[ "https://Stackoverflow.com/questions/10307606", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1291802/" ]
You can do it using just html and a css background image: html ``` <a href = "#" class="hover_image">Mouseover here</a> ``` css ``` a.hover_image:hover { background: url(/url/to/image) no-repeat center center; text-indent: -9999em; } ``` You probably need a bit more css to define the width and height of ...
Assuming HTML similar to the following: ``` <a href="http://www.example.com/image.png" class="textToImg">Some text</a> ``` The following JavaScript should work: ``` function textToImage(elem){ if (!elem) { return false; } else { var img = document.createElement('img'); img.src = ...
10,307,606
how can i do this? is it possible to have a text hyperlink and once its hovered over, that text link becomes an image? iv seen image rollovers but haven't seen or know how to code text to image rollover yet. i just dont know where to begin and with what programming language. javascript? php? jquery? i started of b...
2012/04/24
[ "https://Stackoverflow.com/questions/10307606", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1291802/" ]
This will make the link change to an image only when hovered, becomes text when hovering out (only CSS) ``` <style> .changeable img { display:none; } .changeable:hover span { display:none; } .changeable:hover img { display:inline-block; } </style> <a href="http://www.example.com" class="changeable"><span>Hyper T...
Assuming HTML similar to the following: ``` <a href="http://www.example.com/image.png" class="textToImg">Some text</a> ``` The following JavaScript should work: ``` function textToImage(elem){ if (!elem) { return false; } else { var img = document.createElement('img'); img.src = ...
10,307,606
how can i do this? is it possible to have a text hyperlink and once its hovered over, that text link becomes an image? iv seen image rollovers but haven't seen or know how to code text to image rollover yet. i just dont know where to begin and with what programming language. javascript? php? jquery? i started of b...
2012/04/24
[ "https://Stackoverflow.com/questions/10307606", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1291802/" ]
You can do it using just html and a css background image: html ``` <a href = "#" class="hover_image">Mouseover here</a> ``` css ``` a.hover_image:hover { background: url(/url/to/image) no-repeat center center; text-indent: -9999em; } ``` You probably need a bit more css to define the width and height of ...
Here is a javascript way to do it ``` <div id="link"> <a href = "#" onmouseover = "document.getElementById('link').style.display='none';document.getElementById('hoverImage').style.display='block';;">Mouseover here</a> </div> <div id="hoverImage" style="display:none"> <img name = "img" alt = "" border...
10,307,606
how can i do this? is it possible to have a text hyperlink and once its hovered over, that text link becomes an image? iv seen image rollovers but haven't seen or know how to code text to image rollover yet. i just dont know where to begin and with what programming language. javascript? php? jquery? i started of b...
2012/04/24
[ "https://Stackoverflow.com/questions/10307606", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1291802/" ]
You can do it using just html and a css background image: html ``` <a href = "#" class="hover_image">Mouseover here</a> ``` css ``` a.hover_image:hover { background: url(/url/to/image) no-repeat center center; text-indent: -9999em; } ``` You probably need a bit more css to define the width and height of ...
This can also be done with jQuery: `**[See In Action](http://jsfiddle.net/pkZAW/)**` ``` <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> </head> <body> <script type='text/javascript'> $( function() { $("#imglink").hover( function () { $(this).attr('s...
10,307,606
how can i do this? is it possible to have a text hyperlink and once its hovered over, that text link becomes an image? iv seen image rollovers but haven't seen or know how to code text to image rollover yet. i just dont know where to begin and with what programming language. javascript? php? jquery? i started of b...
2012/04/24
[ "https://Stackoverflow.com/questions/10307606", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1291802/" ]
This will make the link change to an image only when hovered, becomes text when hovering out (only CSS) ``` <style> .changeable img { display:none; } .changeable:hover span { display:none; } .changeable:hover img { display:inline-block; } </style> <a href="http://www.example.com" class="changeable"><span>Hyper T...
Here is a javascript way to do it ``` <div id="link"> <a href = "#" onmouseover = "document.getElementById('link').style.display='none';document.getElementById('hoverImage').style.display='block';;">Mouseover here</a> </div> <div id="hoverImage" style="display:none"> <img name = "img" alt = "" border...
10,307,606
how can i do this? is it possible to have a text hyperlink and once its hovered over, that text link becomes an image? iv seen image rollovers but haven't seen or know how to code text to image rollover yet. i just dont know where to begin and with what programming language. javascript? php? jquery? i started of b...
2012/04/24
[ "https://Stackoverflow.com/questions/10307606", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1291802/" ]
This will make the link change to an image only when hovered, becomes text when hovering out (only CSS) ``` <style> .changeable img { display:none; } .changeable:hover span { display:none; } .changeable:hover img { display:inline-block; } </style> <a href="http://www.example.com" class="changeable"><span>Hyper T...
This can also be done with jQuery: `**[See In Action](http://jsfiddle.net/pkZAW/)**` ``` <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> </head> <body> <script type='text/javascript'> $( function() { $("#imglink").hover( function () { $(this).attr('s...
7,503
I'm installing lights in my buildings (I'm using [Neopixel strips](https://www.adafruit.com/products/1507), which have a flat back), and I'm trying to tape the lights to the ceiling. Of course, bricks and plates aren't smooth on the bottom, so double sided tape isn't working out too well. Can you recommend either: * ...
2016/04/03
[ "https://bricks.stackexchange.com/questions/7503", "https://bricks.stackexchange.com", "https://bricks.stackexchange.com/users/7063/" ]
Take a look at [11203 - Tile, Modified 2 x 2 Inverted](http://alpha.bricklink.com/pages/clone/catalogitem.page?P=11203#T=S&O=%7B%22ss%22:%22US%22,%22rpp%22:%22500%22%7D). Works like your 2x2 round plate but is flat at the bottom. [![enter image description here](https://i.stack.imgur.com/0hGbS.jpg)](https://i.stack.im...
> > An alternate method of affixing small parts to the bottom of bricks and plates: > > > Check out sticky-tack! It has a ridiculous amount of brand names, but it's basically a safely removable, free-form version of duct-tape. It will stick to anything, and increases its own surface area by spreading all throughou...
61,410
Can you work out how this number sequence is built up? Can you work out how it continues? > > 1, 1, 2, 4, 8, 20, 60, 240, 1500, ....... > > > *Hint 1* > > this is a mathematical puzzle > > > *Hint 2* > > It does not involve complicated mathematics > > > *From time to time hints will be updated.* *...
2018/03/06
[ "https://puzzling.stackexchange.com/questions/61410", "https://puzzling.stackexchange.com", "https://puzzling.stackexchange.com/users/44224/" ]
The next number is > > 16140 > > > Following this pattern, given the sequence is $a\_n$ > > $a\_n = a\_{n-1} + a\_{n-2} \cdot (a\_{n-3} + 1)$ > > > Example: 60 = 20 + 8 \* (4 + 1) > > >
[![enter image description here](https://i.stack.imgur.com/edZ4G.png)](https://i.stack.imgur.com/edZ4G.png) It seems like I was way off on the pattern I was trying to track. Seems like this is a neat coincidence though.
61,410
Can you work out how this number sequence is built up? Can you work out how it continues? > > 1, 1, 2, 4, 8, 20, 60, 240, 1500, ....... > > > *Hint 1* > > this is a mathematical puzzle > > > *Hint 2* > > It does not involve complicated mathematics > > > *From time to time hints will be updated.* *...
2018/03/06
[ "https://puzzling.stackexchange.com/questions/61410", "https://puzzling.stackexchange.com", "https://puzzling.stackexchange.com/users/44224/" ]
The next number is > > 16140 > > > Following this pattern, given the sequence is $a\_n$ > > $a\_n = a\_{n-1} + a\_{n-2} \cdot (a\_{n-3} + 1)$ > > > Example: 60 = 20 + 8 \* (4 + 1) > > >
Obligatory nth order polynomial: > > $$f(x) = \frac{5}{384}x^8-\frac{4597}{10080}x^7+\frac{19471}{2880}x^6 - \frac{19831}{360}x^5+\frac{308935}{1152}x^4-\frac{1141669}{1440}x^3+\frac{1982957}{1440}x^2-\frac{354937}{280}+465$$ > > > Predicted next five values: > > 8116, 33619, 112289, 318913, 800021 > > >
222,810
> > Lisp and Fortran were the trunks of two separate evolutionary trees, > one rooted in math and one rooted in machine architecture. > > > I see this in *Hackers and Painters: Big Ideas from the Computer Age*. And someone said that Lisp are Human oriented and Fortran are Machine oriented. Here human oriented ...
2014/01/01
[ "https://softwareengineering.stackexchange.com/questions/222810", "https://softwareengineering.stackexchange.com", "https://softwareengineering.stackexchange.com/users/100523/" ]
> > Why we say Lisp are Human oriented and Fortran are Machine oriented? > > > “We” don't say that: Lisp advocates do ;-) Both Fortran and Lisp were designed for humans. You could say that Fortran is even more human-oriented: > > Don't you hate writing assembler? Where implementing a simple formula consists of ...
The human brain does neither think in lists or lambda calculus nor in mathematical formulas. Therefore neither LISP nor FORTRAN can be called human like. [Artificial neural networks](http://en.wikipedia.org/wiki/Artificial_neural_network) try to mimic the way biological brains work. In this sense they could be called t...
222,810
> > Lisp and Fortran were the trunks of two separate evolutionary trees, > one rooted in math and one rooted in machine architecture. > > > I see this in *Hackers and Painters: Big Ideas from the Computer Age*. And someone said that Lisp are Human oriented and Fortran are Machine oriented. Here human oriented ...
2014/01/01
[ "https://softwareengineering.stackexchange.com/questions/222810", "https://softwareengineering.stackexchange.com", "https://softwareengineering.stackexchange.com/users/100523/" ]
> > Why we say Lisp are Human oriented and Fortran are Machine oriented? > > > “We” don't say that: Lisp advocates do ;-) Both Fortran and Lisp were designed for humans. You could say that Fortran is even more human-oriented: > > Don't you hate writing assembler? Where implementing a simple formula consists of ...
I think first-class functions are the reason people say that and I would argue that we do in fact think in terms of lamdas/first-class funcs. Question: "What are you going to do with it?" How do you answer that question/solve that problem without passing a function to your answer method? I believe the chief reason ...
15,021
> > Insert $+$, $-$, $\times$, $/$, $($, $)$ into $123456789$ to make it equal to $100$. > > > Looks like a question for pupils, right? In fact, if the available math symbols are limited to addition ($+$), subtraction ($-$), multiplication ($\times$), and division ($/$), then it's easy to solve: ``` Select[Tuple...
2012/11/22
[ "https://mathematica.stackexchange.com/questions/15021", "https://mathematica.stackexchange.com", "https://mathematica.stackexchange.com/users/1871/" ]
In a sense described below, this answer finds $422716$ distinct solutions. The innovations presented here are 1. using postfix operators to eliminate problems with parentheses; 2. avoiding having to deal with unary negation; 3. initially computing "too many" solutions, some of which make no sense, and eliminating th...
Similar to [whuber](https://mathematica.stackexchange.com/users/91/whuber)'s [answer](https://mathematica.stackexchange.com/a/15117/2090), we can use [Groupings](http://reference.wolfram.com/language/ref/Groupings.html)(introduced in version 11) to simplify the generation patterns, the number of patterns is related to ...
15,021
> > Insert $+$, $-$, $\times$, $/$, $($, $)$ into $123456789$ to make it equal to $100$. > > > Looks like a question for pupils, right? In fact, if the available math symbols are limited to addition ($+$), subtraction ($-$), multiplication ($\times$), and division ($/$), then it's easy to solve: ``` Select[Tuple...
2012/11/22
[ "https://mathematica.stackexchange.com/questions/15021", "https://mathematica.stackexchange.com", "https://mathematica.stackexchange.com/users/1871/" ]
Here's a possibility ``` next`ops = HoldForm /@ {Plus, Times, Divide, Subtract}; (nextOp[#1] = #2) & @@@ Most@Transpose@{next`ops, RotateLeft@next`ops}; next`children = True; SetAttributes[{next`Plus, next`Times}, Flat]; next[{i_}] := False; next[l_List] := HoldForm[Plus][{l[[1]]}, l[[2 ;;]]]; next[op_[arg1_, arg2_]] ...
Check the Wolfram Blog and the very nice contribution by Christopher Carlson: Happy 10\*9\*8+7+6-5+4\*321 ! February 2, 2012 <http://blog.wolfram.com/2012/02/02/happy-109876-54321/>
15,021
> > Insert $+$, $-$, $\times$, $/$, $($, $)$ into $123456789$ to make it equal to $100$. > > > Looks like a question for pupils, right? In fact, if the available math symbols are limited to addition ($+$), subtraction ($-$), multiplication ($\times$), and division ($/$), then it's easy to solve: ``` Select[Tuple...
2012/11/22
[ "https://mathematica.stackexchange.com/questions/15021", "https://mathematica.stackexchange.com", "https://mathematica.stackexchange.com/users/1871/" ]
The solution in this answer is quite incomplete, As @whuber points out in the comment below, $34(−5×6+89)+2$ or $34(5/(6/(8×9))−1)+2$ isn't involved in the output of my second sample, I think the reason is: 1 My solution only treat "$-$" as *binary minus*, while it can also be used as a unary operator. (This isn't har...
Here's a `Compile`d version of [chyanog's answer](https://mathematica.stackexchange.com/a/255350/1871), it's a pity the code is more than an order slower than that directly coded with C and I've no idea how to improve it further, but the timing is already acceptable so I'd like to share it. ``` n = 9; original = Grou...
15,021
> > Insert $+$, $-$, $\times$, $/$, $($, $)$ into $123456789$ to make it equal to $100$. > > > Looks like a question for pupils, right? In fact, if the available math symbols are limited to addition ($+$), subtraction ($-$), multiplication ($\times$), and division ($/$), then it's easy to solve: ``` Select[Tuple...
2012/11/22
[ "https://mathematica.stackexchange.com/questions/15021", "https://mathematica.stackexchange.com", "https://mathematica.stackexchange.com/users/1871/" ]
**EDIT**: As @Rojo points out in the comments, my code doesn't really find all solutions. For example, a term of the form `a * (b * c + d)` can't be represented with "precedence plus/minus" operators. I'm not sure if it is salvageable, but as it is, the code below does not find all solutions. A very simple solution wo...
Check the Wolfram Blog and the very nice contribution by Christopher Carlson: Happy 10\*9\*8+7+6-5+4\*321 ! February 2, 2012 <http://blog.wolfram.com/2012/02/02/happy-109876-54321/>
15,021
> > Insert $+$, $-$, $\times$, $/$, $($, $)$ into $123456789$ to make it equal to $100$. > > > Looks like a question for pupils, right? In fact, if the available math symbols are limited to addition ($+$), subtraction ($-$), multiplication ($\times$), and division ($/$), then it's easy to solve: ``` Select[Tuple...
2012/11/22
[ "https://mathematica.stackexchange.com/questions/15021", "https://mathematica.stackexchange.com", "https://mathematica.stackexchange.com/users/1871/" ]
In a sense described below, this answer finds $422716$ distinct solutions. The innovations presented here are 1. using postfix operators to eliminate problems with parentheses; 2. avoiding having to deal with unary negation; 3. initially computing "too many" solutions, some of which make no sense, and eliminating th...
Here's a possibility ``` next`ops = HoldForm /@ {Plus, Times, Divide, Subtract}; (nextOp[#1] = #2) & @@@ Most@Transpose@{next`ops, RotateLeft@next`ops}; next`children = True; SetAttributes[{next`Plus, next`Times}, Flat]; next[{i_}] := False; next[l_List] := HoldForm[Plus][{l[[1]]}, l[[2 ;;]]]; next[op_[arg1_, arg2_]] ...
15,021
> > Insert $+$, $-$, $\times$, $/$, $($, $)$ into $123456789$ to make it equal to $100$. > > > Looks like a question for pupils, right? In fact, if the available math symbols are limited to addition ($+$), subtraction ($-$), multiplication ($\times$), and division ($/$), then it's easy to solve: ``` Select[Tuple...
2012/11/22
[ "https://mathematica.stackexchange.com/questions/15021", "https://mathematica.stackexchange.com", "https://mathematica.stackexchange.com/users/1871/" ]
Similar to [whuber](https://mathematica.stackexchange.com/users/91/whuber)'s [answer](https://mathematica.stackexchange.com/a/15117/2090), we can use [Groupings](http://reference.wolfram.com/language/ref/Groupings.html)(introduced in version 11) to simplify the generation patterns, the number of patterns is related to ...
Here's a `Compile`d version of [chyanog's answer](https://mathematica.stackexchange.com/a/255350/1871), it's a pity the code is more than an order slower than that directly coded with C and I've no idea how to improve it further, but the timing is already acceptable so I'd like to share it. ``` n = 9; original = Grou...
15,021
> > Insert $+$, $-$, $\times$, $/$, $($, $)$ into $123456789$ to make it equal to $100$. > > > Looks like a question for pupils, right? In fact, if the available math symbols are limited to addition ($+$), subtraction ($-$), multiplication ($\times$), and division ($/$), then it's easy to solve: ``` Select[Tuple...
2012/11/22
[ "https://mathematica.stackexchange.com/questions/15021", "https://mathematica.stackexchange.com", "https://mathematica.stackexchange.com/users/1871/" ]
In a sense described below, this answer finds $422716$ distinct solutions. The innovations presented here are 1. using postfix operators to eliminate problems with parentheses; 2. avoiding having to deal with unary negation; 3. initially computing "too many" solutions, some of which make no sense, and eliminating th...
The solution in this answer is quite incomplete, As @whuber points out in the comment below, $34(−5×6+89)+2$ or $34(5/(6/(8×9))−1)+2$ isn't involved in the output of my second sample, I think the reason is: 1 My solution only treat "$-$" as *binary minus*, while it can also be used as a unary operator. (This isn't har...
15,021
> > Insert $+$, $-$, $\times$, $/$, $($, $)$ into $123456789$ to make it equal to $100$. > > > Looks like a question for pupils, right? In fact, if the available math symbols are limited to addition ($+$), subtraction ($-$), multiplication ($\times$), and division ($/$), then it's easy to solve: ``` Select[Tuple...
2012/11/22
[ "https://mathematica.stackexchange.com/questions/15021", "https://mathematica.stackexchange.com", "https://mathematica.stackexchange.com/users/1871/" ]
Here's a possibility ``` next`ops = HoldForm /@ {Plus, Times, Divide, Subtract}; (nextOp[#1] = #2) & @@@ Most@Transpose@{next`ops, RotateLeft@next`ops}; next`children = True; SetAttributes[{next`Plus, next`Times}, Flat]; next[{i_}] := False; next[l_List] := HoldForm[Plus][{l[[1]]}, l[[2 ;;]]]; next[op_[arg1_, arg2_]] ...
Similar to [whuber](https://mathematica.stackexchange.com/users/91/whuber)'s [answer](https://mathematica.stackexchange.com/a/15117/2090), we can use [Groupings](http://reference.wolfram.com/language/ref/Groupings.html)(introduced in version 11) to simplify the generation patterns, the number of patterns is related to ...
15,021
> > Insert $+$, $-$, $\times$, $/$, $($, $)$ into $123456789$ to make it equal to $100$. > > > Looks like a question for pupils, right? In fact, if the available math symbols are limited to addition ($+$), subtraction ($-$), multiplication ($\times$), and division ($/$), then it's easy to solve: ``` Select[Tuple...
2012/11/22
[ "https://mathematica.stackexchange.com/questions/15021", "https://mathematica.stackexchange.com", "https://mathematica.stackexchange.com/users/1871/" ]
Similar to [whuber](https://mathematica.stackexchange.com/users/91/whuber)'s [answer](https://mathematica.stackexchange.com/a/15117/2090), we can use [Groupings](http://reference.wolfram.com/language/ref/Groupings.html)(introduced in version 11) to simplify the generation patterns, the number of patterns is related to ...
Check the Wolfram Blog and the very nice contribution by Christopher Carlson: Happy 10\*9\*8+7+6-5+4\*321 ! February 2, 2012 <http://blog.wolfram.com/2012/02/02/happy-109876-54321/>
15,021
> > Insert $+$, $-$, $\times$, $/$, $($, $)$ into $123456789$ to make it equal to $100$. > > > Looks like a question for pupils, right? In fact, if the available math symbols are limited to addition ($+$), subtraction ($-$), multiplication ($\times$), and division ($/$), then it's easy to solve: ``` Select[Tuple...
2012/11/22
[ "https://mathematica.stackexchange.com/questions/15021", "https://mathematica.stackexchange.com", "https://mathematica.stackexchange.com/users/1871/" ]
Here's a possibility ``` next`ops = HoldForm /@ {Plus, Times, Divide, Subtract}; (nextOp[#1] = #2) & @@@ Most@Transpose@{next`ops, RotateLeft@next`ops}; next`children = True; SetAttributes[{next`Plus, next`Times}, Flat]; next[{i_}] := False; next[l_List] := HoldForm[Plus][{l[[1]]}, l[[2 ;;]]]; next[op_[arg1_, arg2_]] ...
Here's a `Compile`d version of [chyanog's answer](https://mathematica.stackexchange.com/a/255350/1871), it's a pity the code is more than an order slower than that directly coded with C and I've no idea how to improve it further, but the timing is already acceptable so I'd like to share it. ``` n = 9; original = Grou...
176,924
According to Jeff Atwood, ["Expletives are not acceptable behavior on meta or any other Stack Overflow site."](https://meta.stackexchange.com/a/22233/166851) My question is: to what degree (if any) does this apply in chat as well as on meta or main?
2013/04/17
[ "https://meta.stackexchange.com/questions/176924", "https://meta.stackexchange.com", "https://meta.stackexchange.com/users/166851/" ]
If we're going for a general rule here, I would say that Jeff's statement holds equally well in chat as it does on any site within the network. Swearing is not okay. I think of the network as a (largely) professional environment. And swearing has no place in it. There are admittedly chat rooms in which language is so...
Since the MPAA doesn't publish guidelines around what words will make ears bleed, I feel the best method for determining what words are appropriate is by deciding the age rating for each room. Let's say that **The Heap** has an R rating. These words would be censored in the transcript, but visible to anyone who enters ...
30,277,612
I have SSRS report that has around 80+ columns. I have requirement where in dynamically hide\show columns in report based on user selection. I could able to do it by setting expression for "Visiblity" property and having report parameter thro' which columns to display can be choosen. My problem is 2 points 1. fox exa...
2015/05/16
[ "https://Stackoverflow.com/questions/30277612", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1108049/" ]
Here is the shortest version I could come up with. ``` _.reduce = function(list, iteratee, memo){ var memoUndefined = arguments.length < 3; _.each(list, function(elem, index, list){ if(memoUndefined) { memoUndefined = false; memo = elem; } else memo = iteratee(memo, elem, index, list); }); ...
Reduce accepts three parameters: A collection (array or object), callback, and accumulator (this one is optional). Reduce iterates through the collection, which invokes the callback and keeps track of the result in the accumulator. If an accumulator is not passed in, we'll set it to the first element of the collectio...
30,277,612
I have SSRS report that has around 80+ columns. I have requirement where in dynamically hide\show columns in report based on user selection. I could able to do it by setting expression for "Visiblity" property and having report parameter thro' which columns to display can be choosen. My problem is 2 points 1. fox exa...
2015/05/16
[ "https://Stackoverflow.com/questions/30277612", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1108049/" ]
Here is the shortest version I could come up with. ``` _.reduce = function(list, iteratee, memo){ var memoUndefined = arguments.length < 3; _.each(list, function(elem, index, list){ if(memoUndefined) { memoUndefined = false; memo = elem; } else memo = iteratee(memo, elem, index, list); }); ...
First, you need a way to determine whether `reduce` received an initial `memo` value when you are inside the function you pass to `_.each`. You could do this a number of ways. One way is to simply set a flag based on the length of `arguments`. You need to do this outside the `_.each` call because the function you pass ...
39,578,249
I have a `SCNNode` and a full working physics body attached to it, but the physics bodies center/resting-point is at the bottom of the `SCNNode`. Here's what I'm trying to do: * Figure out how to position the physics body at the center of the node. * Figure out how to control its positioning in some way. Apple Devel...
2016/09/19
[ "https://Stackoverflow.com/questions/39578249", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6802724/" ]
I'd suggest trying the `SCNPhysicsShape` [`init(shapes:transforms:)`](https://developer.apple.com/reference/scenekit/scnphysicsshape/1508886-init) initializer — rather than constructing a physics shape out of several shapes (and using the `transforms` parameter to position them relative to one another), you might be ab...
For a full example (my physics were centered about the base of my .dae animation, and I needed the physics body centered at the center of mass of the SCNNode): ``` // refNode is the SCNReferenceNode loaded from the .dae animation let kCharacterScale = SCNVector3(20.0,20.0,20.0) //Set the node and physics scales le...
35,375
I am using a third party module which is rewriting catalog/image helper function for product images. ``` <global> <models> <pio> <class>Kadro_PIO_Model</class> </pio> <catalog> <rewrite> <product_image>Kadro_PIO_Model_Produ...
2014/09/10
[ "https://magento.stackexchange.com/questions/35375", "https://magento.stackexchange.com", "https://magento.stackexchange.com/users/9801/" ]
The answer is obviously, **Yes, You Can**. :) If you disable this third party extension either via editing code or via admin, then magento will start to use its default helper/Model class. Yes Magento is smart enough to to do that. In order to disable this extension via admin, you need to go ``` System > Configura...
A work around for your problem is that you could register a flag from catalog/navigation/subcategory\_listing sections and then based on if this flag is set just call and return the parent functionality from your helper rather than executing your helper funciton..something like ``` public function image($product) { ...
35,375
I am using a third party module which is rewriting catalog/image helper function for product images. ``` <global> <models> <pio> <class>Kadro_PIO_Model</class> </pio> <catalog> <rewrite> <product_image>Kadro_PIO_Model_Produ...
2014/09/10
[ "https://magento.stackexchange.com/questions/35375", "https://magento.stackexchange.com", "https://magento.stackexchange.com/users/9801/" ]
The answer is obviously, **Yes, You Can**. :) If you disable this third party extension either via editing code or via admin, then magento will start to use its default helper/Model class. Yes Magento is smart enough to to do that. In order to disable this extension via admin, you need to go ``` System > Configura...
I ended up using Varien\_Image methode. I used this code in my list.phtml: ``` <?php if (!$_product->getThumbnail()) { $imageUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'placeholder.jpg'; } else { $imageUrl = Mage::getBaseUrl(Mage_C...
62,926,820
I've the list in the following format: ``` int intervalInMinutes = 10; String startTimeForGrouping = "2017-05-09T15:37:51.896+00:00"; List<MyObject> myObjList = Arrays.asList( new MyObject("1","a","2017-05-09T15:38:51.896+00:00"), new MyObject("1","a","2017-05-09T16:41:51.896+00:00"), new MyObject("1","a"...
2020/07/16
[ "https://Stackoverflow.com/questions/62926820", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1552037/" ]
You should parse the date strings into `Instant` objects, and call `Duration.between` to get a duration. Then, divide that duration by `intervalInMinutes` minutes. Finally, multiply this number by `intervalInMinutes` and add that to `startTimeForGrouping` to get the grouping key. Before the stream operation, parse `st...
I think the code is that,you could try and remodify the getTime method to fix your need ``` package com.test; import java.text.SimpleDateFormat; import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.Map; import java.util.stream.Collectors; /** * * * * * * * @author shikai.li...
6,229,197
I have these two arrays: one is filled with information from an ajax request and another stores the buttons the user clicks on. I use this code (I filled with sample numbers): ``` var array1 = [2, 4]; var array2 = [4, 2]; //It cames from the user button clicks, so it might be disordered. array1.sort(); //Sorts both Aj...
2011/06/03
[ "https://Stackoverflow.com/questions/6229197", "https://Stackoverflow.com", "https://Stackoverflow.com/users/702565/" ]
When you compare those two arrays, you're comparing the objects that represent the arrays, not the contents. You'll have to use a function to compare the two. You could write your own that simply loops though one and compares it to the other after you check that the lengths are the same.
Simple solution for shallow equality using ES6: ``` const arr1test = arr1.slice().sort() const arr2test = arr2.slice().sort() const equal = !arr1test.some((val, idx) => val !== arr2test[idx]) ``` Creates shallow copies of each array and sorts them. Then uses `some()` to loop through `arr1test` values, checking each ...
6,229,197
I have these two arrays: one is filled with information from an ajax request and another stores the buttons the user clicks on. I use this code (I filled with sample numbers): ``` var array1 = [2, 4]; var array2 = [4, 2]; //It cames from the user button clicks, so it might be disordered. array1.sort(); //Sorts both Aj...
2011/06/03
[ "https://Stackoverflow.com/questions/6229197", "https://Stackoverflow.com", "https://Stackoverflow.com/users/702565/" ]
``` Array.prototype.compare = function(testArr) { if (this.length != testArr.length) return false; for (var i = 0; i < testArr.length; i++) { if (this[i].compare) { //To test values in nested arrays if (!this[i].compare(testArr[i])) return false; } else if (this[i] !== testAr...
Try this ``` function arraysEqual(arr1, arr2){ if (!Array.isArray(arr1) || !Array.isArray(arr2) || arr1.length!=arr2.length) return false; return arr1.length==arr1.filter(word => arr2.includes(word)).length; } ```
6,229,197
I have these two arrays: one is filled with information from an ajax request and another stores the buttons the user clicks on. I use this code (I filled with sample numbers): ``` var array1 = [2, 4]; var array2 = [4, 2]; //It cames from the user button clicks, so it might be disordered. array1.sort(); //Sorts both Aj...
2011/06/03
[ "https://Stackoverflow.com/questions/6229197", "https://Stackoverflow.com", "https://Stackoverflow.com/users/702565/" ]
Using ES6 ========= We'll use Ramda's `equals` function, but instead we can use Lodash's or Underscore's `isEqual`: ``` const R = require('ramda'); const arraysHaveSameValues = (arr1, arr2) => R.equals( [...arr1].sort(), [...arr2].sort() ) ``` Using the spread opporator, we avoid mutating the original arrays, and ...
A function to Compare two Arrays, to check if both has same elements. Even if they are out of order... It's good for simple arrays. [String,Number,Boolean,null,NaN]. I don't use .sort(), it modifies the original array. Some say's its bad... Caution. This function is limited it can't compare Objects"[],{}" or functio...
6,229,197
I have these two arrays: one is filled with information from an ajax request and another stores the buttons the user clicks on. I use this code (I filled with sample numbers): ``` var array1 = [2, 4]; var array2 = [4, 2]; //It cames from the user button clicks, so it might be disordered. array1.sort(); //Sorts both Aj...
2011/06/03
[ "https://Stackoverflow.com/questions/6229197", "https://Stackoverflow.com", "https://Stackoverflow.com/users/702565/" ]
You can use `reduce` instead of loops to appear clever, but at the risk of having your fellow developers think of you as a smart-ass. ``` function isArrayContentSame(a, b) { if (Array.isArray(a) && Array.isArray(b) && a.length == b.length) { a = a.concat().sort() b = b.concat().sort() return a.reduce((ac...
Here is my solution without sorting: ```js function isDifferent(t1,t2) { return ((t1.length !== t2.length) || t1.some(tag1 => !t2.some(t=>t===tag1))); } let a1=['t','','b','xx','i','p','i']; let a2=['','o','xx','b','t','p','i']; console.log("DIFFERENT=",isDifferent(a1,a2)); //false a1=['a','c','d']; a2=['a','c'...
6,229,197
I have these two arrays: one is filled with information from an ajax request and another stores the buttons the user clicks on. I use this code (I filled with sample numbers): ``` var array1 = [2, 4]; var array2 = [4, 2]; //It cames from the user button clicks, so it might be disordered. array1.sort(); //Sorts both Aj...
2011/06/03
[ "https://Stackoverflow.com/questions/6229197", "https://Stackoverflow.com", "https://Stackoverflow.com/users/702565/" ]
### Why your code didn't work JavaScript has [primitive data types](https://developer.mozilla.org/en-US/docs/Glossary/Primitive) and non-primitive data types. For primitive data types, `==` and `===` check whether the things on either side of the bars have the same value. That's why `1 === 1` is true. For non-primit...
I have another way based on the accepted answer. ``` function compareArrays(array1, array2) { if ( !Array.isArray(array1) || !Array.isArray(array2) || array1.length !== array2.length ) return false; var first = array1.sort().map(value => (String(value))).join(); var second = a...
6,229,197
I have these two arrays: one is filled with information from an ajax request and another stores the buttons the user clicks on. I use this code (I filled with sample numbers): ``` var array1 = [2, 4]; var array2 = [4, 2]; //It cames from the user button clicks, so it might be disordered. array1.sort(); //Sorts both Aj...
2011/06/03
[ "https://Stackoverflow.com/questions/6229197", "https://Stackoverflow.com", "https://Stackoverflow.com/users/702565/" ]
What about this? ES 2017 i suppose: ```js const array1 = [1, 3, 5]; const array2 = [1, 5, 3]; const isEqual = (array1.length === array2.length) && (array1.every(val => array2.includes(val))); console.log(isEqual); ``` 1st condition checks if both arrays have same length and 2nd condition checks if 1st array is a ...
kindly check this answer ``` var arr1= [12,18]; var arr2= [12, 18, 20, 11, 19, 14, 6, 7, 8, 16, 9, 3, 1, 13, 5, 4, 15, 10, 2, 17]; for(i=0;i<arr1.length;i++) { var array1=arr1[i]; for(j=0;j<arr2.length;j++) { var array2=arr2[j]; if(array1==array2) { return true; } } } ```
6,229,197
I have these two arrays: one is filled with information from an ajax request and another stores the buttons the user clicks on. I use this code (I filled with sample numbers): ``` var array1 = [2, 4]; var array2 = [4, 2]; //It cames from the user button clicks, so it might be disordered. array1.sort(); //Sorts both Aj...
2011/06/03
[ "https://Stackoverflow.com/questions/6229197", "https://Stackoverflow.com", "https://Stackoverflow.com/users/702565/" ]
Object equality check:`JSON.stringify(array1.sort()) === JSON.stringify(array2.sort())` The above test also works with arrays of objects in which case use a sort function as documented in <http://www.w3schools.com/jsref/jsref_sort.asp> Might suffice for small arrays with flat JSON schemas.
If the order of the array elements are not important, you could try ``` function arraysEqual<T>(a:T[], b:T[]) { if (a === b) return true; if (a == null || b == null) return false; if (a.length !== b.length) return false; const aClone = [...a].sort(); const bClone = [...b].sort(); for (var i = 0; i < aClon...
6,229,197
I have these two arrays: one is filled with information from an ajax request and another stores the buttons the user clicks on. I use this code (I filled with sample numbers): ``` var array1 = [2, 4]; var array2 = [4, 2]; //It cames from the user button clicks, so it might be disordered. array1.sort(); //Sorts both Aj...
2011/06/03
[ "https://Stackoverflow.com/questions/6229197", "https://Stackoverflow.com", "https://Stackoverflow.com/users/702565/" ]
When you compare those two arrays, you're comparing the objects that represent the arrays, not the contents. You'll have to use a function to compare the two. You could write your own that simply loops though one and compares it to the other after you check that the lengths are the same.
A function to Compare two Arrays, to check if both has same elements. Even if they are out of order... It's good for simple arrays. [String,Number,Boolean,null,NaN]. I don't use .sort(), it modifies the original array. Some say's its bad... Caution. This function is limited it can't compare Objects"[],{}" or functio...
6,229,197
I have these two arrays: one is filled with information from an ajax request and another stores the buttons the user clicks on. I use this code (I filled with sample numbers): ``` var array1 = [2, 4]; var array2 = [4, 2]; //It cames from the user button clicks, so it might be disordered. array1.sort(); //Sorts both Aj...
2011/06/03
[ "https://Stackoverflow.com/questions/6229197", "https://Stackoverflow.com", "https://Stackoverflow.com/users/702565/" ]
The most easiest way to get the result is below ```js const array1 = [1,2,3,4] const array2 = [3,4,5,6] const result = array1.filter(arr => array2.includes(arr)) console.log(result) ```
Here is my solution without sorting: ```js function isDifferent(t1,t2) { return ((t1.length !== t2.length) || t1.some(tag1 => !t2.some(t=>t===tag1))); } let a1=['t','','b','xx','i','p','i']; let a2=['','o','xx','b','t','p','i']; console.log("DIFFERENT=",isDifferent(a1,a2)); //false a1=['a','c','d']; a2=['a','c'...
6,229,197
I have these two arrays: one is filled with information from an ajax request and another stores the buttons the user clicks on. I use this code (I filled with sample numbers): ``` var array1 = [2, 4]; var array2 = [4, 2]; //It cames from the user button clicks, so it might be disordered. array1.sort(); //Sorts both Aj...
2011/06/03
[ "https://Stackoverflow.com/questions/6229197", "https://Stackoverflow.com", "https://Stackoverflow.com/users/702565/" ]
Object equality check:`JSON.stringify(array1.sort()) === JSON.stringify(array2.sort())` The above test also works with arrays of objects in which case use a sort function as documented in <http://www.w3schools.com/jsref/jsref_sort.asp> Might suffice for small arrays with flat JSON schemas.
Answering after long time but hope this will help somebody who looking for a simple solution and modern newbies. Now we can achieve this using multiple libraries like `lodash`, `underscore`, etc. (These becomes part of the project nowadays due to simplicity, multiple features and high usage) You can use intersection ...
5,287,816
I'm messing around with a USB RFID scanner and trying to read input with [raw input](http://msdn.microsoft.com/en-us/library/ms645536%28v=VS.85%29.aspx), so far I have this ``` #define _WIN32_WINNT 0x0601 #include <windows.h> #include <stdio.h> int main(void) { PRAWINPUTDEVICELIST pRawInputDeviceList; PUINT p...
2011/03/13
[ "https://Stackoverflow.com/questions/5287816", "https://Stackoverflow.com", "https://Stackoverflow.com/users/657267/" ]
When you call `GetRawInputDeviceInfo`, it expects `pcbSize` to be a pointer. You have it as a pointer, but its not pointing to anything. Try this: 1. Get rid of `pcbSize` (everywhere). 2. Create a variable `UINT cbDataSize = 1000`. This is the size of your `pData` array. 3. For the last argument of `GetRawInputDeviceI...
I am going to go out on a limb here and guess that this thing may actually be a HID device. Do you know if it is? HID Devices are actually pretty easy to talk to; you connect to them via CreateFile() -- the same way that you would open a COM port -- and then just ReadFile() to get data. Most of the problem is figurin...
14,683,818
I have downloaded qt-5.0.0 for windows. <http://releases.qt-project.org/qt5/5.0.1/qt-windows-opensource-5.0.1-msvc2010_32-x86-offline.exe> I have added INCLUDEPATH += C:\opencv\build\include in the .pro file. Opencv 2.4.3 is already installed. When I include header file in qtcreator : ``` #include <opencv2/opencv...
2013/02/04
[ "https://Stackoverflow.com/questions/14683818", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1747257/" ]
Things to check: * does `C:\opencv\build\include\opencv2\opencv.hpp` actually exist? * does the compile command (which you can check in the Qt Creator "compile output" window) show `-IC:\opencv\build\include` argument in the compile command? * qmake should be run automatically after modifying the .pro file, but re-run...
The correct header files are: ``` <opencv2/core/core.hpp> <opencv2/imgproc/imgproc.hpp> <opencv2/highgui/highgui.hpp> ``` … and so on. The include of "opencv.h" is deprecated! It also does not work anymore for QtCreator auto-completion. The solution is to update your sources to use the correct header files.
14,683,818
I have downloaded qt-5.0.0 for windows. <http://releases.qt-project.org/qt5/5.0.1/qt-windows-opensource-5.0.1-msvc2010_32-x86-offline.exe> I have added INCLUDEPATH += C:\opencv\build\include in the .pro file. Opencv 2.4.3 is already installed. When I include header file in qtcreator : ``` #include <opencv2/opencv...
2013/02/04
[ "https://Stackoverflow.com/questions/14683818", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1747257/" ]
I found the solution. In Qt Creator, goto Projects on the left pane ( ctrl+5), then Build Environment -> Use System Environment, click on Details. Edit LIB variable. Add here.
Things to check: * does `C:\opencv\build\include\opencv2\opencv.hpp` actually exist? * does the compile command (which you can check in the Qt Creator "compile output" window) show `-IC:\opencv\build\include` argument in the compile command? * qmake should be run automatically after modifying the .pro file, but re-run...
14,683,818
I have downloaded qt-5.0.0 for windows. <http://releases.qt-project.org/qt5/5.0.1/qt-windows-opensource-5.0.1-msvc2010_32-x86-offline.exe> I have added INCLUDEPATH += C:\opencv\build\include in the .pro file. Opencv 2.4.3 is already installed. When I include header file in qtcreator : ``` #include <opencv2/opencv...
2013/02/04
[ "https://Stackoverflow.com/questions/14683818", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1747257/" ]
Things to check: * does `C:\opencv\build\include\opencv2\opencv.hpp` actually exist? * does the compile command (which you can check in the Qt Creator "compile output" window) show `-IC:\opencv\build\include` argument in the compile command? * qmake should be run automatically after modifying the .pro file, but re-run...
After any change made to `.pro` file , Do right-click on `project folder` and click on run `qmake` .
14,683,818
I have downloaded qt-5.0.0 for windows. <http://releases.qt-project.org/qt5/5.0.1/qt-windows-opensource-5.0.1-msvc2010_32-x86-offline.exe> I have added INCLUDEPATH += C:\opencv\build\include in the .pro file. Opencv 2.4.3 is already installed. When I include header file in qtcreator : ``` #include <opencv2/opencv...
2013/02/04
[ "https://Stackoverflow.com/questions/14683818", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1747257/" ]
Things to check: * does `C:\opencv\build\include\opencv2\opencv.hpp` actually exist? * does the compile command (which you can check in the Qt Creator "compile output" window) show `-IC:\opencv\build\include` argument in the compile command? * qmake should be run automatically after modifying the .pro file, but re-run...
Well, I just ran into this problem tonight. luckily enough, after taking a fair time, the solution was found. If your project is managed by qmake, and Qcreator is used, just go to the `Build->Run qmake`, then build and run your project. A tip, whenever you change your `*.pro` file, remember to rerun `Build->Run qmake`,...
14,683,818
I have downloaded qt-5.0.0 for windows. <http://releases.qt-project.org/qt5/5.0.1/qt-windows-opensource-5.0.1-msvc2010_32-x86-offline.exe> I have added INCLUDEPATH += C:\opencv\build\include in the .pro file. Opencv 2.4.3 is already installed. When I include header file in qtcreator : ``` #include <opencv2/opencv...
2013/02/04
[ "https://Stackoverflow.com/questions/14683818", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1747257/" ]
I found the solution. In Qt Creator, goto Projects on the left pane ( ctrl+5), then Build Environment -> Use System Environment, click on Details. Edit LIB variable. Add here.
The correct header files are: ``` <opencv2/core/core.hpp> <opencv2/imgproc/imgproc.hpp> <opencv2/highgui/highgui.hpp> ``` … and so on. The include of "opencv.h" is deprecated! It also does not work anymore for QtCreator auto-completion. The solution is to update your sources to use the correct header files.
14,683,818
I have downloaded qt-5.0.0 for windows. <http://releases.qt-project.org/qt5/5.0.1/qt-windows-opensource-5.0.1-msvc2010_32-x86-offline.exe> I have added INCLUDEPATH += C:\opencv\build\include in the .pro file. Opencv 2.4.3 is already installed. When I include header file in qtcreator : ``` #include <opencv2/opencv...
2013/02/04
[ "https://Stackoverflow.com/questions/14683818", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1747257/" ]
I found the solution. In Qt Creator, goto Projects on the left pane ( ctrl+5), then Build Environment -> Use System Environment, click on Details. Edit LIB variable. Add here.
After any change made to `.pro` file , Do right-click on `project folder` and click on run `qmake` .
14,683,818
I have downloaded qt-5.0.0 for windows. <http://releases.qt-project.org/qt5/5.0.1/qt-windows-opensource-5.0.1-msvc2010_32-x86-offline.exe> I have added INCLUDEPATH += C:\opencv\build\include in the .pro file. Opencv 2.4.3 is already installed. When I include header file in qtcreator : ``` #include <opencv2/opencv...
2013/02/04
[ "https://Stackoverflow.com/questions/14683818", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1747257/" ]
I found the solution. In Qt Creator, goto Projects on the left pane ( ctrl+5), then Build Environment -> Use System Environment, click on Details. Edit LIB variable. Add here.
Well, I just ran into this problem tonight. luckily enough, after taking a fair time, the solution was found. If your project is managed by qmake, and Qcreator is used, just go to the `Build->Run qmake`, then build and run your project. A tip, whenever you change your `*.pro` file, remember to rerun `Build->Run qmake`,...
17,962,287
My site is done in ASP .NET MVC and SQL Server. I want to add a view counter feature for details page of each products in my e-ccommerce site,that is number of total hits to a page. Which is the best way to achieve this without affecting the current performance in the loading of the page .?
2013/07/31
[ "https://Stackoverflow.com/questions/17962287", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1634933/" ]
if you just want to keep track of hits you can do as mercsen said in his second comment, if you want to display the number of hits on the product details page then you can write an ajax request which fetches the counter periodically
Using cookie: ``` var productId = 1; if (Request.Cookies["ViewedPage"] != null) { if (Request.Cookies["ViewedPage"][string.Format("pId_{0}",productId )] == null) { HttpCookie cookie = (HttpCookie)Request.Cookies["ViewedPage"]; cookie[string.Format("pId_{0}",productId )] = "1"; cookie.E...
17,962,287
My site is done in ASP .NET MVC and SQL Server. I want to add a view counter feature for details page of each products in my e-ccommerce site,that is number of total hits to a page. Which is the best way to achieve this without affecting the current performance in the loading of the page .?
2013/07/31
[ "https://Stackoverflow.com/questions/17962287", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1634933/" ]
"without affecting the current performance..." So I suggest a 3rd party visitor stats counter tool like Google analytics. Page specific statistics in GA: <http://www.askdavetaylor.com/get_traffic_stats_for_a_specific_page_in_google_analytics.html> <http://3by400.com/index.php/get-support/tutorials16/item/finding-p...
Using cookie: ``` var productId = 1; if (Request.Cookies["ViewedPage"] != null) { if (Request.Cookies["ViewedPage"][string.Format("pId_{0}",productId )] == null) { HttpCookie cookie = (HttpCookie)Request.Cookies["ViewedPage"]; cookie[string.Format("pId_{0}",productId )] = "1"; cookie.E...
24,381,554
When I want to store dynamic array of data in a C structure, there are two ways to write it: ``` typedef struct { int row; int col; char* data; } item1; ``` Or ``` typedef struct { int row; int col; char data[]; } item2; ``` Both of them will work. But they got some differences on my 64bit Mac O...
2014/06/24
[ "https://Stackoverflow.com/questions/24381554", "https://Stackoverflow.com", "https://Stackoverflow.com/users/987180/" ]
Size of pointer is [machine specific](https://stackoverflow.com/q/13109666/2455888) (whether it is 32-bit or 64-bit). The result would be `12` and `8` bytes respectively on 32 bit machine. For 64-bit machine, answer would be `16` and `8` bytes. See the explanation ``` typedef struct { int row; // 4 bytes...
``` typedef struct item2 { int row; int col; char data[]; } ``` in this struct `item2` we have 2 ints, so the size will be `2*sizeof(int)` in most of the systems, and also we have an array `char data[]` with undefined size so it counts as zero in this case, I think if there is padding in the struct then the ...
14,918,964
I have a table called `assets`, where an asset can belong to a user,team, or division, and possibly multiple of each. My issue is that the assets are highly variable, and can have properties associated with them that are different for each one. ex. These could be assets: ``` 1.) type:workbench cost:200 vendor:Acme Co...
2013/02/17
[ "https://Stackoverflow.com/questions/14918964", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1142543/" ]
I would suggest this: ``` assets ( id asset_type_id vendor_id cost purchase_date ) asset_poperties ( id asset_id asset_property_type_id value ) asset_property_types ( id property_type ) asset_types ( id asset_type ) vendors ( id vendor ) ```
You can add another table for asset\_metadata ``` asset_metadata asset_metadata_id,asset_id,metadata_name,metadata_value ``` if you want to normalize and categorize the metadata, normalize it to this way: ``` asset_metadata asset_metadata_id,asset_id,metadata_name_id,metadata_value metadata_name metadata_name_id,m...
14,918,964
I have a table called `assets`, where an asset can belong to a user,team, or division, and possibly multiple of each. My issue is that the assets are highly variable, and can have properties associated with them that are different for each one. ex. These could be assets: ``` 1.) type:workbench cost:200 vendor:Acme Co...
2013/02/17
[ "https://Stackoverflow.com/questions/14918964", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1142543/" ]
I would suggest this: ``` assets ( id asset_type_id vendor_id cost purchase_date ) asset_poperties ( id asset_id asset_property_type_id value ) asset_property_types ( id property_type ) asset_types ( id asset_type ) vendors ( id vendor ) ```
I'd recommend putting the common attributes like cost in conventional column. Then add one more column in which you put a serialized collection of all the other variable asset attributes. ``` CREATE TABLE assets ( asset_id INT AUTO_INCREMENT PRIMARY KEY, cost NUMERIC(9,2), purchase_date DATE, variables TEXT );...
14,918,964
I have a table called `assets`, where an asset can belong to a user,team, or division, and possibly multiple of each. My issue is that the assets are highly variable, and can have properties associated with them that are different for each one. ex. These could be assets: ``` 1.) type:workbench cost:200 vendor:Acme Co...
2013/02/17
[ "https://Stackoverflow.com/questions/14918964", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1142543/" ]
I would suggest this: ``` assets ( id asset_type_id vendor_id cost purchase_date ) asset_poperties ( id asset_id asset_property_type_id value ) asset_property_types ( id property_type ) asset_types ( id asset_type ) vendors ( id vendor ) ```
When I've been faced with this in the past, the "best" answer always ends up varying depending on how much processing I want to do in the database, vs how much in the client code. For what it's worth, often the approach that has worked best for me in the past has been to end up with one table per optional attribute (...
14,918,964
I have a table called `assets`, where an asset can belong to a user,team, or division, and possibly multiple of each. My issue is that the assets are highly variable, and can have properties associated with them that are different for each one. ex. These could be assets: ``` 1.) type:workbench cost:200 vendor:Acme Co...
2013/02/17
[ "https://Stackoverflow.com/questions/14918964", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1142543/" ]
I would suggest this: ``` assets ( id asset_type_id vendor_id cost purchase_date ) asset_poperties ( id asset_id asset_property_type_id value ) asset_property_types ( id property_type ) asset_types ( id asset_type ) vendors ( id vendor ) ```
You can create two new tables: 1) Defining multiple asset attributes in the following table (as many as the asset may have) asset\_id asset\_attribute asset\_value 2) asset\_attribute table attribute\_id asset\_attribute The logic would be that asset\_attributes will need to be first defined in the asset\_attri...
14,918,964
I have a table called `assets`, where an asset can belong to a user,team, or division, and possibly multiple of each. My issue is that the assets are highly variable, and can have properties associated with them that are different for each one. ex. These could be assets: ``` 1.) type:workbench cost:200 vendor:Acme Co...
2013/02/17
[ "https://Stackoverflow.com/questions/14918964", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1142543/" ]
You can add another table for asset\_metadata ``` asset_metadata asset_metadata_id,asset_id,metadata_name,metadata_value ``` if you want to normalize and categorize the metadata, normalize it to this way: ``` asset_metadata asset_metadata_id,asset_id,metadata_name_id,metadata_value metadata_name metadata_name_id,m...
You can create two new tables: 1) Defining multiple asset attributes in the following table (as many as the asset may have) asset\_id asset\_attribute asset\_value 2) asset\_attribute table attribute\_id asset\_attribute The logic would be that asset\_attributes will need to be first defined in the asset\_attri...
14,918,964
I have a table called `assets`, where an asset can belong to a user,team, or division, and possibly multiple of each. My issue is that the assets are highly variable, and can have properties associated with them that are different for each one. ex. These could be assets: ``` 1.) type:workbench cost:200 vendor:Acme Co...
2013/02/17
[ "https://Stackoverflow.com/questions/14918964", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1142543/" ]
I'd recommend putting the common attributes like cost in conventional column. Then add one more column in which you put a serialized collection of all the other variable asset attributes. ``` CREATE TABLE assets ( asset_id INT AUTO_INCREMENT PRIMARY KEY, cost NUMERIC(9,2), purchase_date DATE, variables TEXT );...
You can create two new tables: 1) Defining multiple asset attributes in the following table (as many as the asset may have) asset\_id asset\_attribute asset\_value 2) asset\_attribute table attribute\_id asset\_attribute The logic would be that asset\_attributes will need to be first defined in the asset\_attri...
14,918,964
I have a table called `assets`, where an asset can belong to a user,team, or division, and possibly multiple of each. My issue is that the assets are highly variable, and can have properties associated with them that are different for each one. ex. These could be assets: ``` 1.) type:workbench cost:200 vendor:Acme Co...
2013/02/17
[ "https://Stackoverflow.com/questions/14918964", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1142543/" ]
When I've been faced with this in the past, the "best" answer always ends up varying depending on how much processing I want to do in the database, vs how much in the client code. For what it's worth, often the approach that has worked best for me in the past has been to end up with one table per optional attribute (...
You can create two new tables: 1) Defining multiple asset attributes in the following table (as many as the asset may have) asset\_id asset\_attribute asset\_value 2) asset\_attribute table attribute\_id asset\_attribute The logic would be that asset\_attributes will need to be first defined in the asset\_attri...
55,549,001
I have a string and i want to modify all 4 digit numbers and inserting colon between. Example: 1320 will become 13:20 ``` $data = "The time is 1020 and the time is 1340 and 1550"; ``` I'm thinking to use `preg_match('/[0-9]{4}/', '????', $data);` But not sure how to pass the same value again in the preg?
2019/04/06
[ "https://Stackoverflow.com/questions/55549001", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9992791/" ]
One way could be to use [preg\_replace](https://www.php.net/manual/en/function.preg-replace.php) instead and use capturing groups to capture 2 times 2 digits `(\d{2})(\d{2})` between word boundaries `\b` In the replacement use the 2 capturing groups using `$1:$2` ``` $data = "The time is 1020 and the time is 1340 an...
You don't need to use capture groups, you merely need to seek the qualifying 4-digit substrings and target the zero-length position in the middle of the substring. Code: ([Demo](https://3v4l.org/56TVP)) ``` $data = "The time is 1020 and the time is 1340 and 1550"; echo preg_replace('~\b\d{2}\K(?=\d{2}\b)~', ':', ...
2,580,343
I have been trying to solve $\sin x - \cos x = 1$ by squaring both sides but has not been able to obtain the solution. Here is what I did: $$\begin{align}(\sin x - \cos x)^2 &=1^2\\\sin^2x-2\sin x\cos x+\cos^2x&=1\\1-\sin 2x&=1\\\sin2x&=0\end{align}$$ Obviously $x=0$ is not a solution. May I ask why this is the case ...
2017/12/26
[ "https://math.stackexchange.com/questions/2580343", "https://math.stackexchange.com", "https://math.stackexchange.com/users/516372/" ]
After squaring both sides of the equarion, we get $$ 1=\sin^2x+\cos^2x-2\sin x\cos x=1-\sin2x. $$ Hence $$ \sin 2x=0 $$ i.e. $$ x=x\_k=\frac{\pi}{2}k, \qquad k \in \mathbb{Z}. $$ Checking with the original equation, we have: If $k=2n$, then $$ \sin(x\_{2n})-\cos(x\_{2n})=(-1)^n $$ If $k=2n+1$, then $$ \sin(x\_{2n+1})-...
As squaring will yield more answers than enough, I am now going to solve the equation using $\sin ^{2} x+\cos ^{2} x=1$. Let $a=\sin x \text { and } b=\cos x,$ then $$ \begin{aligned} &\left\{\begin{array}{l} a-b=1 \quad \cdots(1) \\ a^{2}+b^{2}=1 \quad \cdots(2) \end{array}\right.\\ \Rightarrow \quad & a^{2}+(a-1)^{...
2,580,343
I have been trying to solve $\sin x - \cos x = 1$ by squaring both sides but has not been able to obtain the solution. Here is what I did: $$\begin{align}(\sin x - \cos x)^2 &=1^2\\\sin^2x-2\sin x\cos x+\cos^2x&=1\\1-\sin 2x&=1\\\sin2x&=0\end{align}$$ Obviously $x=0$ is not a solution. May I ask why this is the case ...
2017/12/26
[ "https://math.stackexchange.com/questions/2580343", "https://math.stackexchange.com", "https://math.stackexchange.com/users/516372/" ]
Note that : $$\sin x - \cos x = \sqrt2 \sin(x - \frac{\pi}{4})$$ In this case, $$\sin x - \cos x = \sqrt2 \sin(x-\frac{\pi}{4})=1 \implies \sin(x-\frac{\pi}{4})=\frac{1}{\sqrt2}$$ Thus, two possible solutions are: * $$x - \frac{\pi}{4}=\frac{\pi}{4} \implies x = \frac{\pi}{2}+2k\pi \, ,k \in \mathbb{Z}$$ * $$x -\frac...
After squaring both sides of the equarion, we get $$ 1=\sin^2x+\cos^2x-2\sin x\cos x=1-\sin2x. $$ Hence $$ \sin 2x=0 $$ i.e. $$ x=x\_k=\frac{\pi}{2}k, \qquad k \in \mathbb{Z}. $$ Checking with the original equation, we have: If $k=2n$, then $$ \sin(x\_{2n})-\cos(x\_{2n})=(-1)^n $$ If $k=2n+1$, then $$ \sin(x\_{2n+1})-...
2,580,343
I have been trying to solve $\sin x - \cos x = 1$ by squaring both sides but has not been able to obtain the solution. Here is what I did: $$\begin{align}(\sin x - \cos x)^2 &=1^2\\\sin^2x-2\sin x\cos x+\cos^2x&=1\\1-\sin 2x&=1\\\sin2x&=0\end{align}$$ Obviously $x=0$ is not a solution. May I ask why this is the case ...
2017/12/26
[ "https://math.stackexchange.com/questions/2580343", "https://math.stackexchange.com", "https://math.stackexchange.com/users/516372/" ]
Use the property that $$\sin(x-y)=\sin x\cos y-\cos x\sin y$$ We can rewrite the left side of the equation.... $$\begin{align}\sin x-\cos x&=1\\\sqrt 2\left(\sin x\cos\dfrac\pi4-\cos x\sin\dfrac\pi4\right)&=1\\\sin\left(x-\dfrac\pi4\right)&=\dfrac1{\sqrt2}\\x-\dfrac\pi4&=\dfrac\pi4+2k\pi,\pi-\dfrac\pi4+2k\pi\\x&=\box...
Let $a:= \sin x -\cos x;$ $ b=1;$ You have $a = b.$ Squaring: $a^2 =b^2$ gives $(a-b)(a+b)=0. $ You find solutions for the squared equation: $a=b$, or $a = -b.$ Need to be a bit careful: $\sin 2x =0;$ or $x=0;$ implies: 1) $x = 2πk$, $k$ integer. These are the solutions for $a = -b.$, I.e. $\sin x - \cos x =...
2,580,343
I have been trying to solve $\sin x - \cos x = 1$ by squaring both sides but has not been able to obtain the solution. Here is what I did: $$\begin{align}(\sin x - \cos x)^2 &=1^2\\\sin^2x-2\sin x\cos x+\cos^2x&=1\\1-\sin 2x&=1\\\sin2x&=0\end{align}$$ Obviously $x=0$ is not a solution. May I ask why this is the case ...
2017/12/26
[ "https://math.stackexchange.com/questions/2580343", "https://math.stackexchange.com", "https://math.stackexchange.com/users/516372/" ]
You can not use squaring because $a=b$ is not equal to $a^2=b^2$. After squaring you obtain also solutions of the following equations. $$\sin{x}-\cos{x}=-1,$$ which we don't want. I think it's better the following way. $$2\sin\frac{x}{2}\cos\frac{x}{2}-2\cos^2\frac{x}{2}=0$$ or $$\cos\frac{x}{2}(\sin\frac{x}{2}-\co...
Let $a:= \sin x -\cos x;$ $ b=1;$ You have $a = b.$ Squaring: $a^2 =b^2$ gives $(a-b)(a+b)=0. $ You find solutions for the squared equation: $a=b$, or $a = -b.$ Need to be a bit careful: $\sin 2x =0;$ or $x=0;$ implies: 1) $x = 2πk$, $k$ integer. These are the solutions for $a = -b.$, I.e. $\sin x - \cos x =...
2,580,343
I have been trying to solve $\sin x - \cos x = 1$ by squaring both sides but has not been able to obtain the solution. Here is what I did: $$\begin{align}(\sin x - \cos x)^2 &=1^2\\\sin^2x-2\sin x\cos x+\cos^2x&=1\\1-\sin 2x&=1\\\sin2x&=0\end{align}$$ Obviously $x=0$ is not a solution. May I ask why this is the case ...
2017/12/26
[ "https://math.stackexchange.com/questions/2580343", "https://math.stackexchange.com", "https://math.stackexchange.com/users/516372/" ]
I hope you know the expansion$$\sin(\theta+\varphi)=\sin\theta\cos\varphi+\sin\varphi\cos\theta$$Because we can use it in the equation and greatly simplify the algebra needed. Rewriting your equation$$\sin x-\cos x=1\quad\implies\quad\sqrt2\left(\frac {\sin x}{\sqrt2}-\frac {\cos x}{\sqrt2}\right)=1$$The expression ins...
Let $a:= \sin x -\cos x;$ $ b=1;$ You have $a = b.$ Squaring: $a^2 =b^2$ gives $(a-b)(a+b)=0. $ You find solutions for the squared equation: $a=b$, or $a = -b.$ Need to be a bit careful: $\sin 2x =0;$ or $x=0;$ implies: 1) $x = 2πk$, $k$ integer. These are the solutions for $a = -b.$, I.e. $\sin x - \cos x =...
2,580,343
I have been trying to solve $\sin x - \cos x = 1$ by squaring both sides but has not been able to obtain the solution. Here is what I did: $$\begin{align}(\sin x - \cos x)^2 &=1^2\\\sin^2x-2\sin x\cos x+\cos^2x&=1\\1-\sin 2x&=1\\\sin2x&=0\end{align}$$ Obviously $x=0$ is not a solution. May I ask why this is the case ...
2017/12/26
[ "https://math.stackexchange.com/questions/2580343", "https://math.stackexchange.com", "https://math.stackexchange.com/users/516372/" ]
Use the property that $$\sin(x-y)=\sin x\cos y-\cos x\sin y$$ We can rewrite the left side of the equation.... $$\begin{align}\sin x-\cos x&=1\\\sqrt 2\left(\sin x\cos\dfrac\pi4-\cos x\sin\dfrac\pi4\right)&=1\\\sin\left(x-\dfrac\pi4\right)&=\dfrac1{\sqrt2}\\x-\dfrac\pi4&=\dfrac\pi4+2k\pi,\pi-\dfrac\pi4+2k\pi\\x&=\box...
I hope you know the expansion$$\sin(\theta+\varphi)=\sin\theta\cos\varphi+\sin\varphi\cos\theta$$Because we can use it in the equation and greatly simplify the algebra needed. Rewriting your equation$$\sin x-\cos x=1\quad\implies\quad\sqrt2\left(\frac {\sin x}{\sqrt2}-\frac {\cos x}{\sqrt2}\right)=1$$The expression ins...
2,580,343
I have been trying to solve $\sin x - \cos x = 1$ by squaring both sides but has not been able to obtain the solution. Here is what I did: $$\begin{align}(\sin x - \cos x)^2 &=1^2\\\sin^2x-2\sin x\cos x+\cos^2x&=1\\1-\sin 2x&=1\\\sin2x&=0\end{align}$$ Obviously $x=0$ is not a solution. May I ask why this is the case ...
2017/12/26
[ "https://math.stackexchange.com/questions/2580343", "https://math.stackexchange.com", "https://math.stackexchange.com/users/516372/" ]
Let $a:= \sin x -\cos x;$ $ b=1;$ You have $a = b.$ Squaring: $a^2 =b^2$ gives $(a-b)(a+b)=0. $ You find solutions for the squared equation: $a=b$, or $a = -b.$ Need to be a bit careful: $\sin 2x =0;$ or $x=0;$ implies: 1) $x = 2πk$, $k$ integer. These are the solutions for $a = -b.$, I.e. $\sin x - \cos x =...
$$ \begin{aligned} \sin x-\cos x &=1 \\ -\frac{1}{\sqrt{2}} \sin x+\frac{1}{\sqrt{2}} \cos x &=-\frac{1}{\sqrt{2}} \\ \cos \left(x+\frac{\pi}{4}\right) &=-\frac{1}{\sqrt{2}} \\ x+\frac{\pi}{4} &=2 n \pi \pm \frac{3 \pi}{4} \\ x &=\frac{\pi}{2}(4 n+1) \text { or }(2 n-1) \pi, \text{ where }n\in Z. \end{aligned} $$
2,580,343
I have been trying to solve $\sin x - \cos x = 1$ by squaring both sides but has not been able to obtain the solution. Here is what I did: $$\begin{align}(\sin x - \cos x)^2 &=1^2\\\sin^2x-2\sin x\cos x+\cos^2x&=1\\1-\sin 2x&=1\\\sin2x&=0\end{align}$$ Obviously $x=0$ is not a solution. May I ask why this is the case ...
2017/12/26
[ "https://math.stackexchange.com/questions/2580343", "https://math.stackexchange.com", "https://math.stackexchange.com/users/516372/" ]
Let $a:= \sin x -\cos x;$ $ b=1;$ You have $a = b.$ Squaring: $a^2 =b^2$ gives $(a-b)(a+b)=0. $ You find solutions for the squared equation: $a=b$, or $a = -b.$ Need to be a bit careful: $\sin 2x =0;$ or $x=0;$ implies: 1) $x = 2πk$, $k$ integer. These are the solutions for $a = -b.$, I.e. $\sin x - \cos x =...
As squaring will yield more answers than enough, I am now going to solve the equation using $\sin ^{2} x+\cos ^{2} x=1$. Let $a=\sin x \text { and } b=\cos x,$ then $$ \begin{aligned} &\left\{\begin{array}{l} a-b=1 \quad \cdots(1) \\ a^{2}+b^{2}=1 \quad \cdots(2) \end{array}\right.\\ \Rightarrow \quad & a^{2}+(a-1)^{...
2,580,343
I have been trying to solve $\sin x - \cos x = 1$ by squaring both sides but has not been able to obtain the solution. Here is what I did: $$\begin{align}(\sin x - \cos x)^2 &=1^2\\\sin^2x-2\sin x\cos x+\cos^2x&=1\\1-\sin 2x&=1\\\sin2x&=0\end{align}$$ Obviously $x=0$ is not a solution. May I ask why this is the case ...
2017/12/26
[ "https://math.stackexchange.com/questions/2580343", "https://math.stackexchange.com", "https://math.stackexchange.com/users/516372/" ]
Note that : $$\sin x - \cos x = \sqrt2 \sin(x - \frac{\pi}{4})$$ In this case, $$\sin x - \cos x = \sqrt2 \sin(x-\frac{\pi}{4})=1 \implies \sin(x-\frac{\pi}{4})=\frac{1}{\sqrt2}$$ Thus, two possible solutions are: * $$x - \frac{\pi}{4}=\frac{\pi}{4} \implies x = \frac{\pi}{2}+2k\pi \, ,k \in \mathbb{Z}$$ * $$x -\frac...
As squaring will yield more answers than enough, I am now going to solve the equation using $\sin ^{2} x+\cos ^{2} x=1$. Let $a=\sin x \text { and } b=\cos x,$ then $$ \begin{aligned} &\left\{\begin{array}{l} a-b=1 \quad \cdots(1) \\ a^{2}+b^{2}=1 \quad \cdots(2) \end{array}\right.\\ \Rightarrow \quad & a^{2}+(a-1)^{...
2,580,343
I have been trying to solve $\sin x - \cos x = 1$ by squaring both sides but has not been able to obtain the solution. Here is what I did: $$\begin{align}(\sin x - \cos x)^2 &=1^2\\\sin^2x-2\sin x\cos x+\cos^2x&=1\\1-\sin 2x&=1\\\sin2x&=0\end{align}$$ Obviously $x=0$ is not a solution. May I ask why this is the case ...
2017/12/26
[ "https://math.stackexchange.com/questions/2580343", "https://math.stackexchange.com", "https://math.stackexchange.com/users/516372/" ]
I hope you know the expansion$$\sin(\theta+\varphi)=\sin\theta\cos\varphi+\sin\varphi\cos\theta$$Because we can use it in the equation and greatly simplify the algebra needed. Rewriting your equation$$\sin x-\cos x=1\quad\implies\quad\sqrt2\left(\frac {\sin x}{\sqrt2}-\frac {\cos x}{\sqrt2}\right)=1$$The expression ins...
$$ \begin{aligned} \sin x-\cos x &=1 \\ -\frac{1}{\sqrt{2}} \sin x+\frac{1}{\sqrt{2}} \cos x &=-\frac{1}{\sqrt{2}} \\ \cos \left(x+\frac{\pi}{4}\right) &=-\frac{1}{\sqrt{2}} \\ x+\frac{\pi}{4} &=2 n \pi \pm \frac{3 \pi}{4} \\ x &=\frac{\pi}{2}(4 n+1) \text { or }(2 n-1) \pi, \text{ where }n\in Z. \end{aligned} $$
65,839
In 2018, Ethereum dapps has $2.6 Billion worth transaction volume in 2018; EOS has $3.45B; TRON has $600M. However, number of transactions on Ethereum is way less than EOS and TRON. Ethereum has a huge user base but TRON has a lot of incentives to offer and they have strong marketing support. [![enter image descrip...
2019/01/20
[ "https://ethereum.stackexchange.com/questions/65839", "https://ethereum.stackexchange.com", "https://ethereum.stackexchange.com/users/47726/" ]
It's a problem with the new Truffle version (using on Quorum). `truffle` v5 and `truffle-contract` v4 don't work. Using the latest v3 `truffle-contract@3.0.7` solved this particular issue.
In many blogs I've found it was a Truffle version problem. Truffle v5 would make problems of this type. They suggest to downgrade to truffle@4.1.15. This has not been so for me. I have continue to use truffle v5. I've resolved by checking my gas limit when I sent a transaction. gasLimit: web3.utils.toHex( gas\_limit )...
37,726,922
I have a bundle version set in a file, like this: ``` "dist/app-build-v1.08": { ``` How can I sed the version number and swap it out with an incremented number? First I'm attempting to grab the line itself, which is the third line in my bundle file. ``` BUILD=$(sed '3q;d' ./build/bundles.js) ``` Which does indee...
2016/06/09
[ "https://Stackoverflow.com/questions/37726922", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5963599/" ]
I would suggest some re-architecting as right now you have your interface controllers doing "networking" and model work. My recommended approach would be to create a "persistence manager" that is the WCSession delegate. Any data that is received is persisted, and then using an observer or notification pattern other pa...
You can check for the keys of your dictionary that you send. You can use three different keys and then check whether it is the right key for the right interface controller.
37,726,922
I have a bundle version set in a file, like this: ``` "dist/app-build-v1.08": { ``` How can I sed the version number and swap it out with an incremented number? First I'm attempting to grab the line itself, which is the third line in my bundle file. ``` BUILD=$(sed '3q;d' ./build/bundles.js) ``` Which does indee...
2016/06/09
[ "https://Stackoverflow.com/questions/37726922", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5963599/" ]
I would suggest some re-architecting as right now you have your interface controllers doing "networking" and model work. My recommended approach would be to create a "persistence manager" that is the WCSession delegate. Any data that is received is persisted, and then using an observer or notification pattern other pa...
Give the ***didReceiveMessage*** method in ExtensionDelegate.m in the watch app extension. Pass the name of the interface controller to which the message is intended in the ***sendMessage*** method. In if-else condition, call the method in the intended interface controller using notification centre.
37,726,922
I have a bundle version set in a file, like this: ``` "dist/app-build-v1.08": { ``` How can I sed the version number and swap it out with an incremented number? First I'm attempting to grab the line itself, which is the third line in my bundle file. ``` BUILD=$(sed '3q;d' ./build/bundles.js) ``` Which does indee...
2016/06/09
[ "https://Stackoverflow.com/questions/37726922", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5963599/" ]
You can check for the keys of your dictionary that you send. You can use three different keys and then check whether it is the right key for the right interface controller.
Give the ***didReceiveMessage*** method in ExtensionDelegate.m in the watch app extension. Pass the name of the interface controller to which the message is intended in the ***sendMessage*** method. In if-else condition, call the method in the intended interface controller using notification centre.
98,023
We have a small business website that has been compromised. They are somehow getting customers order details and contacting them requesting their credit card details. We have had our web team and a third party IT company looking into it and we can't find out where the breach is. There seems to be no suspicious access...
2015/08/28
[ "https://security.stackexchange.com/questions/98023", "https://security.stackexchange.com", "https://security.stackexchange.com/users/84574/" ]
If you can't find the entry point of the hackers, and a "third party IT company" can't find it either, consider hiring a professional security firm to investigate the attack. This is not an appropriate forum for product or company recommendations, so please don't ask specifically "who" to hire. I have found that pe...
One of the things left to do would be too lookup for known security flaws on the XCart version you currently have. You mentioned that that is the e-commerce manager you are using and that you didn't update it to the latest version. Now, I am not sure which version you still use, but try to make a Google search to see i...
98,023
We have a small business website that has been compromised. They are somehow getting customers order details and contacting them requesting their credit card details. We have had our web team and a third party IT company looking into it and we can't find out where the breach is. There seems to be no suspicious access...
2015/08/28
[ "https://security.stackexchange.com/questions/98023", "https://security.stackexchange.com", "https://security.stackexchange.com/users/84574/" ]
What troubles me is that you mention there was [another user](https://security.stackexchange.com/questions/85999/email-phishing-scam-asking-customers-for-card-details) affected by an attacker using the very same name "*Lucy Whetton*". Are you by any chance using some standard well-known eCommerce website solution (or ...
One of the things left to do would be too lookup for known security flaws on the XCart version you currently have. You mentioned that that is the e-commerce manager you are using and that you didn't update it to the latest version. Now, I am not sure which version you still use, but try to make a Google search to see i...
6,810,036
What is typically regarded as more Pythonic/better/faster to use, the reverse method or the reversed built-in function? Both in action: ``` _list = list(xrange(4)) print _list rlist = list(reversed(_list)) print rlist _list.reverse() print _list ```
2011/07/24
[ "https://Stackoverflow.com/questions/6810036", "https://Stackoverflow.com", "https://Stackoverflow.com/users/433417/" ]
`foo.reverse()` actually reverses the elements in the container. `reversed()` doesn't actually reverse anything, it merely returns an object that can be used to iterate over the container's elements in reverse order. If that's what you need, it's often faster than actually reversing the elements.
Expanding on [@Niklas R](https://stackoverflow.com/questions/6810036/whats-better-the-reverse-method-or-the-reversed-built-in-function#answer-6810160) answer: ``` import timeit print('list.reverse() - real-list', timeit.timeit('_list.reverse()', '_list = list(range(1_000))')) print('list.reverse() - iterator', timeit...
6,810,036
What is typically regarded as more Pythonic/better/faster to use, the reverse method or the reversed built-in function? Both in action: ``` _list = list(xrange(4)) print _list rlist = list(reversed(_list)) print rlist _list.reverse() print _list ```
2011/07/24
[ "https://Stackoverflow.com/questions/6810036", "https://Stackoverflow.com", "https://Stackoverflow.com/users/433417/" ]
Without knowing real stats about performance, `_list.reverse()` modifies the list itself, whereas `reversed(_list)` returns an iterator ready to traverse the list in reversed order. That's a big difference itself. If that's not a problem, `object.reverse()` seems more readable to me, but maybe you have specific speed...
Expanding on [@Niklas R](https://stackoverflow.com/questions/6810036/whats-better-the-reverse-method-or-the-reversed-built-in-function#answer-6810160) answer: ``` import timeit print('list.reverse() - real-list', timeit.timeit('_list.reverse()', '_list = list(range(1_000))')) print('list.reverse() - iterator', timeit...
6,810,036
What is typically regarded as more Pythonic/better/faster to use, the reverse method or the reversed built-in function? Both in action: ``` _list = list(xrange(4)) print _list rlist = list(reversed(_list)) print rlist _list.reverse() print _list ```
2011/07/24
[ "https://Stackoverflow.com/questions/6810036", "https://Stackoverflow.com", "https://Stackoverflow.com/users/433417/" ]
* \_list.reverse() does an in-place reversal and does not return a value * reversed(\_list) does not change \_list, but returns a reverse iterable object * \_list[::-1] does not change \_list, but returns reversed slice example: ``` _list = [1,2,3] ret1 = list(reversed(_list)) ret2 = _list[::-1] #reverse order slice ...
It is always better to use reversed() if eventually you are going to modify the list in iterator making list immutable and working with immutable data is always better especially when your doing functional programming.
6,810,036
What is typically regarded as more Pythonic/better/faster to use, the reverse method or the reversed built-in function? Both in action: ``` _list = list(xrange(4)) print _list rlist = list(reversed(_list)) print rlist _list.reverse() print _list ```
2011/07/24
[ "https://Stackoverflow.com/questions/6810036", "https://Stackoverflow.com", "https://Stackoverflow.com/users/433417/" ]
Depends on whether you want to reverse the list in-place (i.e. change the list) or not. No other real difference. Often using `reversed` leads to nicer code.
Expanding on [@Niklas R](https://stackoverflow.com/questions/6810036/whats-better-the-reverse-method-or-the-reversed-built-in-function#answer-6810160) answer: ``` import timeit print('list.reverse() - real-list', timeit.timeit('_list.reverse()', '_list = list(range(1_000))')) print('list.reverse() - iterator', timeit...
6,810,036
What is typically regarded as more Pythonic/better/faster to use, the reverse method or the reversed built-in function? Both in action: ``` _list = list(xrange(4)) print _list rlist = list(reversed(_list)) print rlist _list.reverse() print _list ```
2011/07/24
[ "https://Stackoverflow.com/questions/6810036", "https://Stackoverflow.com", "https://Stackoverflow.com/users/433417/" ]
`foo.reverse()` actually reverses the elements in the container. `reversed()` doesn't actually reverse anything, it merely returns an object that can be used to iterate over the container's elements in reverse order. If that's what you need, it's often faster than actually reversing the elements.
* \_list.reverse() does an in-place reversal and does not return a value * reversed(\_list) does not change \_list, but returns a reverse iterable object * \_list[::-1] does not change \_list, but returns reversed slice example: ``` _list = [1,2,3] ret1 = list(reversed(_list)) ret2 = _list[::-1] #reverse order slice ...
6,810,036
What is typically regarded as more Pythonic/better/faster to use, the reverse method or the reversed built-in function? Both in action: ``` _list = list(xrange(4)) print _list rlist = list(reversed(_list)) print rlist _list.reverse() print _list ```
2011/07/24
[ "https://Stackoverflow.com/questions/6810036", "https://Stackoverflow.com", "https://Stackoverflow.com/users/433417/" ]
Depends on whether you want to reverse the list in-place (i.e. change the list) or not. No other real difference. Often using `reversed` leads to nicer code.
Without knowing real stats about performance, `_list.reverse()` modifies the list itself, whereas `reversed(_list)` returns an iterator ready to traverse the list in reversed order. That's a big difference itself. If that's not a problem, `object.reverse()` seems more readable to me, but maybe you have specific speed...
6,810,036
What is typically regarded as more Pythonic/better/faster to use, the reverse method or the reversed built-in function? Both in action: ``` _list = list(xrange(4)) print _list rlist = list(reversed(_list)) print rlist _list.reverse() print _list ```
2011/07/24
[ "https://Stackoverflow.com/questions/6810036", "https://Stackoverflow.com", "https://Stackoverflow.com/users/433417/" ]
`foo.reverse()` actually reverses the elements in the container. `reversed()` doesn't actually reverse anything, it merely returns an object that can be used to iterate over the container's elements in reverse order. If that's what you need, it's often faster than actually reversing the elements.
Depends on whether you want to reverse the list in-place (i.e. change the list) or not. No other real difference. Often using `reversed` leads to nicer code.