The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My work

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,842 other followers

Archive for the ‘JavaScript/ECMAScript’ Category

Is there a standard function to check for null, undefined, or blank variables in JavaScript? – Stack Overflow

Posted by jpluimers on 2017/10/11

Yes there is; it’s the answer below. Note I needed to exclude false by adding a check value === false to the code below as that was a valid value for me.

You can just check if the variable has a truthy value or not. That means

if( value ) {
}

will evaluate to true if value is not:

  • null
  • undefined
  • NaN
  • empty string (“”)
  • 0
  • false

The above list represents all possible falsy values in ECMA-/Javascript. Find it in the specification at the ToBoolean section.

Furthermore, if you do not know whether a variable exists (that means, if it was declared) you should check with the typeof operator. For instance

if( typeof foo !== 'undefined' ) {
    // foo could get resolved and it's defined
}

If you can be sure that a variable is declared at least, you should directly check if it has a truthyvalue like shown above.

Further read: http://typeofnan.blogspot.com/2011/01/typeof-is-fast.html

Thanks to [WayBackUser jAndy – Stack Overflow who answered the above at [WayBackIs there a standard function to check for null, undefined, or blank variables in JavaScript? – Stack Overflow.

–jeroen

Posted in Development, JavaScript/ECMAScript, Scripting, Software Development | Leave a Comment »

How do I make the first letter of a string uppercase in JavaScript? – Stack Overflow

Posted by jpluimers on 2017/10/11

I’m a JavaScript n00b, so I like solutions like these:

Another solution:

function capitalizeFirstLetter(string) {
    return string.charAt(0).toUpperCase() + string.slice(1);
}

You could also add it to the String.prototype so you could chain it with other methods:

String.prototype.capitalizeFirstLetter = function() {
    return this.charAt(0).toUpperCase() + this.slice(1);
}

and use it like this:

'string'.capitalizeFirstLetter() // String

Thanks [WayBackHutch Moore and [WayBackDeviljho for answering at [WayBackHow do I make the first letter of a string uppercase in JavaScript? – Stack Overflow!

Note you can do it in CSS too as explained by [WayBacksam6ber:

In CSS:

p:first-letter {
    text-transform:capitalize;
}

–jeroen

Posted in CSS, Development, JavaScript/ECMAScript, Scripting, Software Development, Web Development | Leave a Comment »

Visual Studio Code – getting started – some links

Posted by jpluimers on 2017/10/05

It might sound like I’m late in the game, but remember that blog posts are usually scheduled like a year in advance.

So I found out a long time ago (I think it’s Matthijs ter Woord who attended me) about Visual Studio Code.

At the start [WayBack] it was more limited (from memory something like C#, TypeScript, Java Script languages and frameworks Node.js and ASP.NET 5) than my other development environments but now it’s much richer.

It’s based on the Electron framework which I kew from the Atom.io editor and Koush‘s framework Electron Chrome that wraps Chrome Apps in Electron so he ensured Vysor would live after Google will kill Chrome Apps.

Oh it’s free and runs multi-platform which I like a lot (and was one of the reasons to start using Atom.io): Mac OS X, Windows and Linux are supported.

So here are a few links to get started:

I got reminded a while back** that it is now supported by OmniPascal [WayBack] which I like because of my Turbo Pascal -> VAX/VMS -> csh -> Delphi -> AS/400 -> .NET background.

Like Visual Studio Code is updated often, the Omni Pascal blog [WayBack] shows regular updates and I like it a lot better than the Lazarus IDE (I’m not a visual RAD person: I’m a RAD code person) especially the refactorings.

So start playing with it. I will post more about my Visual Studio Code experience in due time.

–jeroen

** via [WayBackFinally: OmniPascal 0.11.0 released – Implement an interface via key stroke …

Posted in .NET, ASP.NET, C#, Delphi, Development, JavaScript/ECMAScript, Node.js, Omni Pascal, Pascal, Scripting, Software Development, TypeScript, Visual Studio and tools, Visual Studio Code | 1 Comment »

Need to write a proper bookmarklet for the wayback archive (:

Posted by jpluimers on 2017/09/14

Some inspiration for writing a proper bookmarklet that finds or saves a WayBack machine page:

On the last link, I was hoping that the https://web.archive.org/liveweb/https://www.example.org would work but it doesn’t work for many URLs and I’m not sure yet why that is.

It has a nice tip that works though:

Another useful tip: To see the raw copy of the page without the archive.org overlay, insert im_ into the URL, so for example:
http://web.archive.org/web/20130626030834/http://vorb.is/
becomes
http://web.archive.org/web/20130626030834im_/http://vorb.is/

Read the rest of this entry »

Posted in Development, JavaScript/ECMAScript, Power User, Scripting, Software Development | Leave a Comment »

Sending various HTTP request kinds using curl

Posted by jpluimers on 2017/07/25

I’ve been using cURL but always had a feeling not to its potential basically because the cURL man page [WayBack] is both massive and lacks concrete useful practical examples.

For instance, I knew about the --header and --verbose options (I always use verbose names even though shorter -H and -v exist) to pass a specific header and get verbose output, but the man page basic examples like this by Tader:

curl --header --verbose "X-MyHeader: 123" http://www.google.com

source: How to send a header using a HTTP request through a curl call? – Stack Overflow [WayBack]

There are some more examples at bropages.org/curl but they’re hardly organised or documented.

So I was really glad I found the below answer [WayBack] by Amith Koujalgi to web services – HTTP POST and GET using cURL in Linux – Stack Overflow.

But first note that recent versions (around 7.22 or higher) of cURL now need to combine the --silent and --show-error (or in short -sS) parameters to suppress progress but show errors: linux – How do I get cURL to not show the progress bar? – Stack Overflow [WayBack]

Back to the examples

Read the rest of this entry »

Posted in *nix, Communications Development, cURL, Delphi, Development, HTTP, https, Internet protocol suite, JavaScript/ECMAScript, JSON, Power User, REST, Scripting, Security, Software Development, TCP, TLS, XML, XML/XSD | 1 Comment »

 
%d bloggers like this: