w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
shorten (subtract) header and remove empty line in fasta file by perl
Remove anything from headers (lines starting with >) after GL and 6 digits: s/^>GLd{6}K.+// Only print non-empty (whitespace only) lines: print if /S/ Putting it all together: perl -ne 's/^>GLd{6}K.+//; print if /S/' file

Categories : Perl

Powershell Test if array in one line
There are type operators one can use to test the type of a variable. -is is the one you need. Like so, $foo = @() # Array $bar = "zof" # String $foo -is [array] # Is foo an array? True # Yes it is $foo -is [string] # Is foo a string? False # No it is not $bar -is [array] # How about bar False # Nope, not an array $bar -is [string] # A string then? True # You betcha! So something like this could beused if($csv -is [array]) { # Stuff for array } else { # Stuff for string }

Categories : Arrays

Powershell in-line "if" for send-mailmessage
Not the way you've written above but you can splat the parameters, building the hash with conditions, so you only have one call to send-mailmessage. An example from a script I wrote a few months ago: #Set up default/standard/common parameters $MailParams = @{ "Subject"="This is my subject"; "BodyAsHtml" = $true; "From" = $MailFrom; "To" = $MailTo; "SmtpServer" = $SMTPServer; }; #On the last day of the month, attach a logfile. if ((Get-Date).AddDays(1).Day -eq 1) { $attachment = $LogFilePath; $ReportContent = "Full log for the the preceding month is attached.<br><br>" + $ReportContent; $MailParams.Add("Attachments",$attachment); } send-mailmessage @MailParms So in your case, it would be: $MailParams = @{ "Subject"="This is my subject"; "From" = $MailFrom; "To" = $recipient

Categories : Powershell

How to get the line number of error in Powershell
I figured out what the issue was: Instead of: $e = $_.Exception $line = $_.Exception.InvocationInfo.ScriptLineNumber $msg = $e.Message Write-Host -ForegroundColor Red "caught exception: $e at $line" It needs to be: $e = $_.Exception $line = $_.InvocationInfo.ScriptLineNumber $msg = $e.Message Write-Host -ForegroundColor Red "caught exception: $e at $line"

Categories : Dotnet

How to read a line from a file in Powershell
I'm never seen anything from PowerShell, but I mean it can be helpfull for you. What about something like this: foreach ($line in $lines.Split(' ')){ Test-Connection $line.Split(' ')[1] } http://en.wikipedia.org/wiki/Newline

Categories : Powershell

Powershell: Update current output line
Use carriage return to return to the start of the line: `r See this: http://ss64.com/ps/syntax-esc.html And definition of carriage return: http://en.wikipedia.org/wiki/Carriage_return If you want to clear a line, that and a load of spaces. Otherwise you can overwrite stuff. I can't really write up an example here as it's SO's code character, but put it at the start of the "world" string and it should work. Hope this helps!

Categories : Powershell

output fields on single line from Powershell
Method 1: First get contents from file using Get-Content cmdlet and then pipe it to ConvertFrom-CSV cmdlet and finally Select-Object and expression syntax to combine columns. Get-Content C:Scriptimport.csv | ConvertFrom-CSV -Header ColumnA,ColumnB,ColumnC,columnD | Select ColumnB,ColumnD,@{Name="ComputedAC";Expression = {$_.ColumnA + " " + $_.ColumnC }} | Export-CSV C:scriptexport.csv Method 2: You can use select object and the expression syntax to combine columnA and ColumnC Import-csv -Path C:Scriptimport.csv | Select ColumnB,ColumnD,@{Name="ComputedAC";Expression = {$_.ColumnA + " " + $_.ColumnC }} | Export-CSV C:scriptexport.csv Method 3 (less recommended due to performance issues): I am creating a new PSObject and setting its Property and then adding that object to $Objs ar

Categories : Powershell

Powershell - Replacing value on one line in a text file
$_.replace($oldValue,$value) in your innermost conditional replaces $oldValue with $value and then prints the modified string, but you don't have code printing non-matching strings. Because of that only the modified string are written back to $path. Replace the line # Do nothing with $_ and also add an else branch with a $_ to the inner conditional. Or you could assign $_ to another variable and modify your code like this: Foreach-Object { $line = $_ if ($line -like "*=*") { $arr = $line -split "=", 2 if ($arr[0].Trim() -eq $key) { $arr[1] = $value $line = $arr -join "=" } } $line }

Categories : String

How to write this multi-line statement in PowerShell 3.0
The error about the / operator usually indicates that PowerShell is not treating the command as a command line; prefix a & to force it to do so. Note you'll also need to use .cspack if cspack is in the current directory. PowerShell will also treat semicolons as statement terminators, so you'll want to surround each parameter with quotes to prevent that. & cspack "$a/ServiceDefinition.csdef" "/role:$b;$c" "/rolePropertiesFile:$a.$b;c$" "/sites:$a;$b;$c" "/out:$out"

Categories : Powershell

PowerShell Get-Content and replace object in a specific line
Check if a line is starting with a 'Static Text ' followed by a sequence of word characters and return your string in case there a match: Get-Content $OptionsFile | foreach { if($_ -match '^Static Texts+(w+s)+') { 'Static Text MachineX MachineY' } else { $_ } }

Categories : Regex

powershell select-object outputs array on one line
You need to convert your 4 arrays into an array of objects with 4 properties. Try this: $Array1 = @(...) $Array2 = @(...) $Array3 = @(...) $Array4 = @(...) $len1 = [Math]::Max($Array1.Length, $Array2.Length) $len2 = [Math]::Max($Array3.Length, $Array4.Length) $maxlen = [Math]::Max($len1, $len2) $csv = for ($i=0; $i -lt $maxlen; $i++) { New-Object -Type PSCustomObject -Property @{ 'Column1' = $Array1[$i]; 'Column2' = $Array2[$i]; 'Column3' = $Array3[$i]; 'Column4' = $Array4[$i]; } } $csv | Export-Csv 'C:path ooutput.csv'

Categories : Powershell

How do I pass raw strings to commands through the command line in PowerShell?
If you are using Powershell v3.0, there is a new syntax to make Powershell avoid any extra parsing for arguments. Something like: inventory.exe --% 'inventory', 'date', 'owner' There are other approaches as mentioned here: http://blogs.technet.com/b/josebda/archive/2012/03/03/using-windows-powershell-to-run-old-command-line-tools-and-their-weirdest-parameters.aspx

Categories : Powershell

Send email from powershell command line with credentials
Send-MailMessage -smtpServer 'smtp.gmail.com' -port 587 -from 'myself@gmail.com' -to 'myself@gmail.com' -subject 'Test' -body 'Body' –UseSsl -Credential (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "myUsername" (ConvertTo-SecureString -String "myPassword" -AsPlainText -Force))

Categories : Windows

Using C# to execute PowerShell script with command line args using V2 methods
Answering my own question here. It looks like the right approach would be for my application to function as a PowerShell Host http://msdn.microsoft.com/en-us/library/windows/desktop/ee706610(v=vs.85).aspx Use of PowerShell V2 objects is defined here: http://msdn.microsoft.com/en-us/library/windows/desktop/system.management.automation.powershell(v=vs.85).aspx

Categories : C#

PowerShell cmdlet CommandRuntime WriteProgress line returns and tabs
The backtick is the double quoted string escape character. write-host "Hi`tKevin`n" They don't work within single quotes. I just tried `n and `t with double quotes in write-progress and I see the funny face for the tab, so I can tell they are interpreted correctly So this means tab and newline don't behave as you want them to within write-progress. I did verify that the -status and -currentoperation strings will wrap if they are long enough. YOu could use wrapping to achieve the look of a table. But that means you're script is dependent on what environment is hosting Powershell. From the command line version PS, you can set these: $host.ui.RawUI.BufferSize.Width=80 $host.UI.RawUI.WindowSize.Width=80 but it doesn't have any effect. You could run mode.exe: mode con: cols=80 whi

Categories : C#

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

What's a difference between Azure PowerShell commandlets and Command-Line Tools?
The PowerShell cmdlets work only in PowerShell (on Windows machines). They're great for automating several concurrent tasks (i.e. scripting out an entire environment), or carrying out single tasks. The command-line tools are cross platform tools (work on Windows, Linux, etc.) These are written in node.js. They're not as good for scripting multiple actions, but are great for developers that prefer the command line to execute tasks (instead of going to the Azure management portal). As far as I can tell, they are not on a synced release schedule. You can follow the progress of each via their github.com repositories (https://github.com/WindowsAzure/azure-sdk-tools-xplat and https://github.com/WindowsAzure/azure-sdk-tools).

Categories : Powershell

Call a script in SharePoint PowerShell post-deployment command line with array in paramaters
CMD doesn't know anything about PowerShell arrays, so it passes "m2","m1" into the powershell script as a single string. You can see that when you add Write-Host $ModelNameList[0] Write-Host $ModelNameList[0].GetType() to your PowerShell script. I think you have to split the argument inside your script: if ($ModelNameList[0] -match ',') { $ModelNameList = $ModelNameList[0].Split(',') }

Categories : Visual Studio

CSS Shorthand available?
What you want is: .parent1 .inner1, .parent1 .inner2 { /*styles*/ } .parent2 .inner1, .parent2 .inner2 { /*styles*/ } This will apply the styles to the 2 lots accordingly.

Categories : CSS

PHP Shorthand If/Else when using return
With your current syntax, what do you expect your function to return when $data[0] is not set? Surely you don't expect your function to not return anything, depending upon a condition. The only alternative I see is the ternary operator, where you return something other than $data[0] when it is not set: return isset($data[0]) ? $data[0] : null;

Categories : PHP

Jquery shorthand IF-ELSE
If somediv is actually a div as the name would indicates, you should use text() or html() instead of val() since value is only valid for input elements.

Categories : Jquery

jQuery 'each' shorthand
Assuming you want to expand the selection, you might be interested in the .add() function: $('someElement').add('onotherElement').each(function() { }) will apply your logic to all matches of the someElement as well as onotherElement

Categories : Javascript

Shorthand for if-else statement
Try like var hasName = 'N'; if (name == "true") { hasName = 'Y'; } Or even try with ternary operator like var hasName = (name == "true") ? "Y" : "N" ; Even simply you can try like var hasName = (name) ? "Y" : "N" ; Since name has either Yes or No but iam not sure with it.

Categories : Javascript

multiple if in a shorthand and in an compact way
You can use else: if (abciden != null) { // PERFORM SSS } else { if (subject.equalsIgnoreCase(IOAConstants.DDD_REPORT_SUBJECT_ert)) { //PERFORM CCC } if (subject.equalsIgnoreCase(IOAConstants.DDD_REPORT_SUBJECT_fgt)) { //PERFORM BBB } } Or as I'm assuming subject cannot match both constants: if (abciden != null) { // PERFORM SSS } else if (subject.equalsIgnoreCase(IOAConstants.DDD_REPORT_SUBJECT_ert)) { //PERFORM CCC } else if (subject.equalsIgnoreCase(IOAConstants.DDD_REPORT_SUBJECT_fgt)) { //PERFORM BBB } Re your edit: want to replace if with shorthand conditional ternary operator ? : Okay, if you specifically want the ternary, then ensure that whatever these "perform" steps are, they return a value. Then you could use this

Categories : Java

PHP Constructor and Dependencies Shorthand
There is an alternative, property injection: use DIAnnotationInject; class TestController { /** * @Inject * @var AppleService */ private $appleService; /** * @Inject * @var BananaService */ private $bananaService; /** * @Inject * @var LemonService */ private $lemonService; /** * @Inject * @var PearService */ private $pearService; /** * @Inject * @var PeachService */ private $peachService; } Is that shorter, or simpler to write? I'll let you judge. But I love it, I don't end up with a bloated constructor. This is inspired from Java/Spring FYI. Now this example works with PHP-DI (disclaimer: I work on that), but there may be other DI containers that offer the same functiona

Categories : PHP

shorthand properties and method of css
From http://sass-lang.com Sass avoids repetition by nesting selectors within one another. The same thing works with properties. table.hl { margin: 2em 0; td.ln { text-align: right; } } li { font: { family: serif; weight: bold; size: 1.2em; } } which compiles to: /* CSS */ table.hl { margin: 2em 0; } table.hl td.ln { text-align: right; } li { font-family: serif; font-weight: bold; font-size: 1.2em; }

Categories : HTML

Shorthand for assigning variables
TypeScript will allow you to cast the item in this case... although this means that test1 and test2 are the same object. interface Foo1 { a: string; b: boolean c: Object; } interface Foo2 extends Foo1 { d: number; } var test1: Foo1 = { a: '...', b: true, c: {} }; var test2: Foo2 = <Foo2> test1; test2.d = 1; If you want a copy, not the same object, you can create a method to copy the object's properties. Here is an example of a copy: var test1: Foo1 = { a: '...', b: true, c: {} }; var test2: Foo2 = <Foo2>{}; for (var variable in test1) { if( test1.hasOwnProperty( variable ) ) { test2[variable] = test1[variable]; } } With a little hint of generics, you can encapsulate this in a static helper method, like this: class ObjectHelper { st

Categories : Typescript

Python: "as" keyword for shorthand
I think you want this (iterate the key/value pair as n, o using iteritems()): class SomeClass: class_dict = {0:0,1:1,2:2,3:3} newClass = SomeClass() for n, o in newClass.class_dict.iteritems(): print(o)

Categories : Python

Shorthand if then else performance/optimization in php
Both normal ifelse statement and a ternary operator have a slight perfomance difference.You can check the below stackoverflow links for more reference Click here

Categories : PHP

php ternary shorthand for use in template
The ternary operation is not meant to replace checking with isset() - it needs it's variable defined or else you get a notice. Template engines usually offer a way to use a default value instead, but they also do not use pure PHP code. You you are out of luck here: Either suppress the notice, or use the longer code variant. Or ensure that every variable is set, which enables you to consider any notice an error.

Categories : PHP

Shorthand syntax for PHP arrays
That is no more than an array of arrays. These two snippets are identical: $array = [ [1, 2], [3, 4], ]; $array = array( array (1, 2), array (3, 4), ); This is documented in the PHP manual page for Arrays and has been possible since PHP 5.4.

Categories : PHP

AngularJS $stateProvider shorthand
There's a couple of ways you could do it but neither are particularly satisfactory. The first one is simply do everyone in 1 large object literal held in another file so you can easily add/edit routes in one place. Then simply loop over them with $stateProvider at application bootstrap. An extension of that is then to have this large object literal as a .json file instead, and load it dynamically at application bootstrap. But I don't think either of these really help you much. What I've done in the past in projects with a lot of very similar routes (such as pure MVC style routing) is have a grunt task which generates the routes object literal for me based on reading the controllers and views directories to determine what routes to make. This works quite well, and you can set up grunt

Categories : Angularjs

Shorthand if else and anonymous functions
That's not a "short hand if/else", it's the ternary operator. Secondly, you're not actually invoking your functions, just assigning one or the other to the variable $str. You need to actually invoke the resulting function. Why you'd do this, I have no idea...

Categories : PHP

Shorten php if var use var
you can use $lang = $this->session->userdata('lang')?$this->session->userdata('lang'):""; but as @bwoebi points out this does not avoid doubling down on the function call. You can create a function to do the dirty work for you. function getValueOrDefault($value, $default = null){ return $value?$value:$default; } $lang = getValueOrDefault($this->session->userdata('lang'), "en"); or for your case depending on what a false return of $this->session->userdata() is this $lang = $this->session->userdata('lang'); may be an equivalent.

Categories : PHP

Php insert shorthand if inside array:
I can only see this issue: Change $fields == null ? 'fields' => $fields : 'gg' to 'fields' => ($fields == null ? 'gg' : $fields) Edit: If the parameter should not be there at all then use a separate statement after the $param declaration if ($fields != null) $param['fields'] = $fields; If the order is important as well you will need to split it up even more.

Categories : PHP

jQuery shorthand for tabindex naming
Create a for loop: for (var index = 4; index <= 40; ++index) { $('[tabindex="' + index + '"]').on({ focus: function() { $(this).addClass('active'); }, blur: function() { $(this).removeClass('active'); } }); }

Categories : Jquery

shorthand if else mixing php with javascript not working
It should be: var checked = ( '<?php echo $original_delivery_date; ?>' == json['dates_per_zone'][i] ? "checked" : "" ); You're missing the quotes around the string that PHP prints.

Categories : PHP

PHP + HTML if function exists shorthand
You don't need the : and endif here. Try this: if (returnString('image')) echo '<img src="'.returnString('image').'" />'; Alternatively, you could store the return value in a variable (as mplungjan suggested above) and use that in your code (more readable, IMO). That way, you can avoid your function from being called twice. $src = returnString('image'); if (isset($src)) echo '<img src="'.$src.'" />'; I'd actually like to add that I want to check if the function exists, which is why I have the if at the start. There's a built-in function, exactly for the same purpose -- function_exists() You can do the following: if (function_exists('returnString')) { $src = returnString('image'); echo '<img src="'.$src.'"/>'; } Hope this helps!

Categories : PHP

Shorthand for create new instance if null?
use ?? operator foo ?? new Foo(); Or in your case var myVar = returnObjectOrNull() ?? new MyObject(); The ?? operator is called the null-coalescing operator and is used to define a default value for nullable value types or reference types. It returns the left-hand operand if the operand is not null; otherwise it returns the right operand.

Categories : C#

css font italic shorthand not working?
If you write normal right after 36px italic it would be recognized or say override the italic by normal. Use like this: font: italic normal 36px Georgia; Using shorthand properties for font would be best result if you order like below 1. font-style 2. font-variant 3. font-weight 4. font-size/line-height 5. font-family

Categories : CSS



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