w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
Increasing an number in PowerShell with Regular Expressions
Why not just: $tmp = Get-Content regex-test | foreach { $n = [regex]::match($_,'"#?(d+)"$').groups[1].value; if ($n) {$_ -replace "$n", ([int32]$n+1)} else {$_}; } Then save the $tmp.

Categories : Regex

Auto increasing numbers in array
There are too many magic numbers in this code, but here you go: // Build an Array of keys @[@"item_1_type_1", @"item_1_type_2", ..., @"item_1_type_9"] programmatically const int numberOfElements = 9; NSMutableArray *keys = [NSMutableArray arrayWithCapacity:numberOfElements]; for (int i = 1; i <= numberOfElements; i++) { [keys addObject:[NSString stringWithFormat:@"item_1_type_%d", i]]; } // Extract chosen keys from JSON Dictionary into an Array, matching the // order of the keys above. NSDictionary *subDict = myJSONData[@"item1"]; NSArray *myArray = [subDict objectsForKeys:keys notFoundMarker:[NSNull null]];

Categories : Objective C

use std::fill to populate vector with increasing numbers
You should use std::iota algorithm: std::vector<int> ivec; std::iota(ivec.begin(), ivec.end(), 0); Because std::fill just assigns the given fixed value to the elements in the given range [n1,n2). And std::iota fills the given range [n1, n2) with sequentially increasing values, starting with the initial value and then using ++value.You can also use std::generate as an alternative. Don't forget that std::iota is C++11 STL algorithm. But a lot of modern compilers support it e.g. GCC, Clang and VS2012 : http://msdn.microsoft.com/en-us/library/vstudio/jj651033.aspx

Categories : C++

Find permutations of a list of numbers with increasing length in C
You can use a combination generating algorithm that will spit out the sequence of C(n, k) combinations for increasing k in an outer loop, and apply the P(k, k) permutation algorithm to produce the sequence of permutations for each combination. c = empty_combination(); for (k = 0; k <= n; ++k) { do { c = next_combination(c, sequence, k); p = empty_permutation(); do { p = next_permutation(p, c); print_permutation(p); } while (! is_empty_permutation(p)); } while (! is_empty_combination(c)); }

Categories : C

An algorithm to remove the least amount of numbers in the list in increasing and decreasing order?
This is a lightly camouflaged Longest increasing (decreasing) subsequence problem. The algorithm to solving your problem is as follows: Find the longest increasing (decreasing) subsequence in the array Remove all elements that do not belong to the longest increasing subsequence. Since the increasing/decreasing subsequence is longest, the amount of numbers that you will remove is the smallest. Wikipedia article has a nice pseudocode for solving the LIS/LDS problem. You can substitute binary search for a linear one unless the original sequence is 1000+ elements long.

Categories : Algorithm

PowerShell, search specific directories for specifc filename
The Path parameter accepts an array of paths so you can specify more than one. You use the Filter parameter to get the file name you're after and pipe the results to the Copy-Item cmdlet: Get-ChildItem -Path C:UsersPublicDocuments,$path2,$path3 -Recurse -Filter $fileName | Copy-Item -Destination $Destination

Categories : Search

Padding numbers in filename with 0's
Instead of doing that prefix replacement, you could isolate the number like this: (remove echo to enable the rename command) @echo off setlocal ENABLEDELAYEDEXPANSION for %%A in (*.jpg) do ( for /f "tokens=1-3 delims=. " %%F in ("%%A") do ( set /a a=%%G set zeros= if !a! LSS 1000 set zeros=0 if !a! LSS 100 set zeros=00 if !a! LSS 10 set zeros=000 set "name=%%F !zeros!!a!.%%H" echo ren "%%A" "!name!" ) ) endlocal Using set /a does a numeric conversion, then you can use the extension comparator LSS to compare the number and create the relevant padding, and finally reassemble the filename using its tokens. This particular snippet isn't generic - it only works if your prefix has no spaces or dots, and the name only has three main t

Categories : Batch File

powershell - concatenate N text files and prepend filename to each line
This one worked for me: ls c: empdata*.txt | foreach-object { $fname=[System.IO.Path]::GetFileName($_); get-content $_ | foreach-object { echo $fname": "$_ >> output.txt}} Just make sure you delete output.txt if you need to run it again or if new data needs to be added. inputs used from above, output.txt: PS C:> cat . empoutput.txt data1.txt: this is the text in data1.txt: data1 file - hello data2.txt: four score and data2.txt: seven years ago

Categories : Powershell

Convert filename in a folder from upper case to lower case (Windows Command Prompt or PowerShell)
In PowerShell: Get-ChildItem | Rename-Item -NewName { $_.Basename.ToUpper() + $_.Extension } or shorter: ls | ren -n { $_.Basename.ToUpper() + $_.Extension }

Categories : Windows

Get digit from filename immediately preceeding file extension, with other digits in filename
regex='([0-9]+).[^.]*$' [[ $file =~ $regex ]] && number=${BASH_REMATCH[1]} This uses bash's underappreciated =~ regex operator which stores matches in an array named BASH_REMATCH.

Categories : Regex

Getting "Bad Filename or Number" when renaming file with a variable for the destination filename
Don't replace known bad characters. Replace everything that is not a known good character, e.g. by using a regular expression: Set re = New RegExp re.Pattern = "[^a-z0-9+._-]+" re.Global = True re.IgnoreCase = True NewFilename = re.Replace(OldFilename, "_") The underscore (_) usually is a safe character for this kind of replacement. Also, don't try to manually parse elements from an HTML file unless you have to. In your case the title can be extracted far easier, like this: Set html = CreateObject("HTMLFile") html.Write objFso.OpenTextFile(File.Name).ReadAll title = html.Title It will even collapse and trim whitespace for you. And a file can be renamed by simply changing its Name property when you already have a handle to that file: objFile.Name = NewFilename Simplified versio

Categories : Vbscript

Apache / PHP / .htaccess routing filename to filename.php
This is happening because of this line in your vhost config: Options Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews Not sure why you need Multiviews to be set to "on" but it's part of mod_negotiation and processes the request before mod_rewrite does. It takes requests like /cart and decides whether there's a fuzzy match against an existing resource. It sees /cart.php and assumes that's what you want and serves up the request before mod_rewrite even gets a chance to do anything. You can turn it off by adding a - in front: Options Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI -MultiViews You can also do this via the htaccess file's Options directive: Options +FollowSymLinks -MultiViews

Categories : PHP

Difference between "./ [filename]" vs. "node [filename]"
It's the same as running bash script using ./[Filename] or bash [Filename]. To use ./[Filename] syntax your node script should: be runable (chmod +x [Filename]) contain proper header (e.g. #!/usr/bin/node or #!/usr/bin/env node) There is no requirements for running your script with node [Filename].

Categories : Node Js

Is it legal to compare a pointer to the beginning of an array with a pointer of the same type pointing before the beginning of the array?
No, it isn't. Using a pointer which doesn't point to an element of the array or one past its end (i. e. which isn't in the range [&arr[0], &arr[size]]) invokes undefined behavior. C11 Standard, 6.5.6.8 ("Additive Operators"): If both the pointer operand and the result [of P + N] point to elements of the same array object, or one past the last element of the array object, the evaluation shall not produce an overflow; otherwise, the behavior is undefined. (emphasis mine)

Categories : C

Given 4 numbers of array of 1 to 10 elements. Find 3 numbers whose sum can generate all the four numbers?
Since the solution contains only 3 numbers which are in 1..10 range, brute force is an effective algorithm here (at most 1000 possibilities to check even in naive implementation). So C# code could be public static int[] BruteForce(int[] data) { HashSet<int> hs = new HashSet<int>(); for (int x = 1; x <= 10; ++x) for (int y = x; y <= 10; ++y) for (int z = y; z <= 10; ++z) { hs.Clear(); for (int i = 0; i < data.Length; ++i) hs.Add(data[i]); hs.Remove(x); hs.Remove(y); hs.Remove(z); hs.Remove(x + y); hs.Remove(x + z); hs.Remove(y + z); hs.Remove(x + y + z); if (hs.Count <= 0) return new int[] { x, y, z }; // <- Solution } return new in

Categories : Arrays

Java arraylist. I need to pass random numbers to an array list and pass them to another class to check those numbers against another set of numbers
You can always transform the random int to a string by using Integer.toString() before inserting into your array list. You can convert the String back to int using Integer.parseInt() E.g. for (int i = 0 ; i < 3 ; i++) { locations.add(Integer.toString((int)(Math.random() * 5)); }

Categories : Java

Why would installing Azure SDK 2.1 or powershell 3 on the build server break some of our tests which run in powershell?
Have you tried passing a fully qualified path to startInfo.FileName instead of just Powershell.exe incase there's a problem with %PATH% since the update Complete total guess, but any chance your running into FileSystemRedirector 32 vs. 64 issues as seen in this answer - Process.Start(): The system cannot find the file specified, but my file path seems to be legit

Categories : Powershell

Add Powershell Snapin for Powershell Module and Import Multiple Times
You might want to try to specify this module required by your own module through a module manifest (.psd1). See RequiredModules here.

Categories : Powershell

Executing Powershell script as different User in Exchange 2007 Powershell
I just found out that executing Remote Powershell Commands/Skripts is not supported with Exchange 2007 (http://howexchangeworks.com/2009/11/exchange-2007-sp2-supports-powershell.html). So I need to wait until the upgrade to 2013. Some workarounds: http://social.technet.microsoft.com/Forums/en-US/exchangesvrgeneral/thread/4596035a-cede-4541-8b8e-e2e9bf1b40dc Or: http://peerfect.blogspot.co.at/2012/10/re-blog-of-my-exchange-remote.html

Categories : Powershell

PowerShell Community Extensions not Recognized by TeamCity PowerShell Runner
Do you import the PSCX module in your script? PowerShell v3 will cache the module info after you have done this once so you don't need to import it again. However if TeamCity is running the 64-bit console and you normally run the 32-bit console, then the 64-bit console wouldn't have PSCX commands in the command cache. Anyway, it is a good practice to have your scripts explicitly require the modules it depends upon e.g. #requires -Modules Pscx

Categories : Powershell

Powershell Script that will login into powershell for office 365
For the exchange powershell use: $SecPass1 = convertto-securestring -asplaintext -string "PasSword" -force $MSOLM = new-object System.Management.Automation.PSCredential -argumentlist "GlobalAdmin@some.com",$SecPass1 $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $MSOLM -Authentication Basic -AllowRedirection Import-Module MSOnline Import-PSSession $Session –AllowClobber

Categories : Actionscript

How to use powershell variable in PowerShell.AddParameter method in C#?
The variable won't be available until you invoke the first script. Try this: ps.AddScript("$backupFile = [System.IO.Path]::Combine([System.IO.Path]::GetTempPath(),'{0}.bak')".FormatInvariant(databaseName)); ps.Invoke(); ps.Commands.Clear(); var backupFile = ps.Runspace.SessionStateProxy.PSVariable.Get("backupFile"); ps.AddCommand("New-Item") .AddParameter("Force") .AddParameter("ItemType", "File") .AddParameter("Path", backupFile )); ps.Invoke(); If you go this route though, I don't think you can use the RunspacePool because you're likely to get different runspaces between each Invoke(). In that case, the variable won't be available to the other runspace. Do you really need to use the RunspacePool in this scenario? If you do then why not just do the first bit in C#: var backup

Categories : C#

How do I return value or object from C# powershell command to Powershell
You have to use the CmdLet.WriteObject method. Here a good explanation from @RomanKuzmin.

Categories : Powershell

Extract string that is delimited with constant and ends with two numbers (numbers have to be included)
You can use this regex (?<=XYZs+)[a-zA-Zs,]+d+s+d+ ---------- ---------- --------- | | |->matches two numbers separated by space | |->matches names separated by , |->lookbehind assertion which checks for a XYZ followed by space before matching the string

Categories : Python

How to generate 6-8 digit random numbers without colliding with previous generated numbers in time critical fashion?
The easiest thing to do is generate random numbers and generating a new random id if you get a duplicate. This works because with your figures the probability of getting a duplicate is pretty small. If that doesnt convince you, you can think of many schemes that guarantee mathematically that the numbers will be unique and still look random, but it gets complex.

Categories : C#

how do you format numbers in vector without having extra spaces and quotes around the numbers
You could use ?sprintf (it use the same syntax like sprintf in C): x <- c(97.1433841613379, 1102.1208262592, 32.5418522860492, 217.694780086999, 1306.31759309228, 202.18335752298, 22.8301149425287) sprintf("%.2f", x) # [1] "97.14" "1102.12" "32.54" "217.69" "1306.32" "202.18" "22.83" EDIT: Or do you look for ?round? round(x, digits=2) # [1] 97.14 1102.12 32.54 217.69 1306.32 202.18 22.83

Categories : R

regex match string of exactly 6 numbers in text that has telephone numbers as well
It's a bit difficult to review the regex without the sample input but couple of observations: [0-9] can be replaced with d (since, you're already using it at the end) [D] is exactly the same as D. It's a character class itself and unless you have some more characters to include it'ss fine without being enclosed in []. (?:,) should simply be , because you neither want to capture it nor it has any quantifiers. ,[W_] Here it seems you want to use the character class but the would escape the first [. If you actually need a literal there; you need to escape it as \ since it's a special character.

Categories : PHP

How to read numbers from extracted lines (deleting repeated numbers)
You document has an XML structure. You are much better off exploiting that by using a proper XML parser. XML::Twig allows you to easily isolate the parts of an XML document in which you are interested. In this case, all we want are <Hr> elements that occur within <SchDay> elements: my $parser = XML::Twig->new( twig_roots => { 'SchDay/Hr' => &do_print }, ); This just tells the parser to invoke the do_print sub for each <Hr> within a <SchDay>. do_print will be called with two arguments: The parser instance we just created and the element. Use $element->att('index') to access the value of the index attribute, and $attr->text to get the text of the attribute, and format and print them. Here is the script: #!/usr/bin/env perl use strict; use w

Categories : Regex

How to prevent randomly generated numbers from creating matching numbers
first cookies is not the best idea and random number too to stay more friendly try to use an ip lock save the ip in an cookie with expiration date of the time of the location use a cookie and a mysql table try to do 2 table one stores the ipa like this 111.111.111,32 the number after the comma is a film id each film has its own id and for each film put another comma the id and for another film another comma and the id and do this each film and save the ids on a cookie and check the ids and check if the film id on the page matches with the ones in cookie and if the cookie matches with the mysql table is more secure and more friendly in case of the client needs to use other browser he can and if ip of the browser matches with the one in the mysql table then set a cookie on this browser I bel

Categories : PHP

How can I make my program select numbers that divide the sum of numbers from an array?
Nothing built in, but you can do it like this: int[] data = new [] {2, 3, 4, 5, 6}; int sum = data.Sum(); var dividers = from number in data where (sum % number) == 0 select number; foreach (var divider in dividers) Console.WriteLine(divider);

Categories : C#

java random numbers generator which generate twenty four numbers
Here's the easiest way I can think of: @Test public void random24Numbers() { String random = RandomStringUtils.random(24, false, true); System.out.println(random); } This uses RandomStringUtils.random. The first parameter is the length, the second says, "no letters". The third says, "give me numbers". Here's an example output: 564266161898194666197908 Yes, it's a String, but I'm going to assume you know how to convert a String into a number.

Categories : Java

PHP generate two random numbers without repeating eachother neither previous numbers
I am just shooting in the dark here, but if the numbers are in the same call i.e $ticket_number1 and $ticket_number2 are same in one call to the page, you can fix this by telling the function to reject an already chosen number function getTicket($exclude=-1){ $count=1; while($count){ $ticket_number = mt_rand(01990, 32000); $query = "SELECT ticket1 FROM `tickets` WHERE `ticket1` == '$ticket_number' or `ticket2` == '$ticket_number'"; $count = mysql_num_rows(mysql_query($query)); if(!$count) $count=$ticket_number==$exclude; } return $ticket_number; } $ticket_number1 = getTicket(); $ticket_number2 = getTicket($ticket_number1);

Categories : PHP

Powershell Start-Process to start Powershell session and pass local variables
I'm pretty sure there's no direct way to pass variables from one PowerShell session to another. The best you can do is some workaround, like declaring the variables in the code you pass in -ArgumentList, interpolating the values in the calling session. How you interpolate the variables into the declarations in -ArgumentList depends on what types of variables. For an array and a string you could do something like this: $command = '<contents of your scriptblock without the curly braces>' Start-Process powershell -ArgumentList ("`$Array = echo $Array; `$String = '$String';" + $command)

Categories : Powershell

Increasing the tab size?
Switch over to Fragments. You will never face such an issue. See this tutorial. http://wptrafficanalyzer.in/blog/implement-swiping-between-tabs-with-viewpager-in-action-bar-using-sherlock-library/ Moreover tab activity gets deprecated.

Categories : Android

Increasing io.sort.mb
according to the article here io.sort.mb should be 10 * io.sort.factor incase you have ram. "core-site.xml" <property> <name>io.sort.factor</name> <value>100</value> <description>More streams merged at once while sorting files.</description> </property> <property> <name>io.sort.mb</name> <value>200</value> <description>Higher memory-limit while sorting data.</description> </property> trying changing sort factor also on all nodes.

Categories : Hadoop

Factor large numbers in Matlab and then get the numbers in the result
How about this : >> x=factor( sym('79228162514264337589248983040') ) x = 2^32*3*5*17*257*641*65537*6700417 >> p=char(x) p = 2^32*3*5*17*257*641*65537*6700417 >> s=regexp(p,'*','split') s = '2^32' '3' '5' '17' '257' '641' '65537' '6700417' >> exp=regexp(s{1},'^','split') exp = '2' '32' >> [exp s(2:end)] ans = '2' '32' '3' '5' '17' '257' '641' '65537' '6700417' Now play with the characters, convert them to numbers, as required.

Categories : Matlab

Getting numbers based on list of other numbers in matlab / octave
you can use this function: function num = getTheMissingNumbers( from, jump, to ) num = from:to; num = setdiff( num, from:jump:to ); You can call this function >> getTheMissingNumbers( 1, 4, 16 ) to get the numbers you want. If you further assume the input to getThemissingNumbers always starts with 1, you can implement it even more efficiently using function num = getTheMissingNumbers( jump, to ) num = 1:to; num(1:jump:to) = []; % remove the elements in ind EDITED according to comment by tmpearce.

Categories : Matlab

How to sort listbox with letters and numbers ascendent by numbers vb.net
I guess what you are looking for is the IComparer Interface Please take a look at Natural Comparer or this question on SO.

Categories : Dotnet

Efficiently counting numbers falling within each range of numbers
This is about 25% faster but outputs as a matrix rather than a list. You many be able to use appy/sappy to make it work with a list (saving as a list was slowing it down). c=matrix(0,length(x),100) for(j in 1:length(x)){ a=-1 b=0 for(i in 1:length(x[[j]])){ a=b b=b+x[[j]][i] c[j,i]=sum((a<=y[[j]])*(y[[j]]<=b)) } }

Categories : R

Converting string with letters and numbers to decimal only numbers
To convert from hexadecimal to decimal, you can do this: string hexString = "01048CABFB"; long intVal = Int64.Parse(hexString, System.Globalization.NumberStyles.HexNumber); // intVal = 4371295227

Categories : C#



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