Archive for the ‘JavaScript/ECMAScript’ Category
Posted by jpluimers on 2017/12/04
via: [WayBack] Hacker News – coinmon: In case you don’t want to install 61 packages [1] :) and [WayBack] The curl + jq based approach to check Bitcoin prices looks a bit more attractive than using a node.js package with 61 dependencies, doesn’t it? Source:… – ThisIsWhyICode – Google+
Function to call curl from bash:
$ coinmon() {
> curl "https://api.coinmarketcap.com/v1/ticker/?convert=$1" | jq ".[0] .price_$1"
> }
$ coinmon eur
"6988.4723188"
Or in Python (from the same HackerNew thread): [Archive.is] https://www.pastery.net/jnscrh/
#!/usr/bin/env python3
from urllib.request import urlopen
from decimal import Decimal
import json
def print_coin(coin):
print("{} ticker:".format(coin["name"]))
print("Price: {:,} EUR".format(Decimal(coin["price_eur"])))
print("Market cap: {:,} EUR".format(Decimal(coin["market_cap_eur"])))
print()
r = urlopen("https://api.coinmarketcap.com/v1/ticker/?convert=eur")
coins = json.loads(r.read().decode("utf8"))
for coin in coins:
if coin["id"] in ("bitcoin", "ethereum", "ripple", "monero"):
print_coin(coin)
–jeroe
Posted in Development, JavaScript/ECMAScript, Node.js, Software Development | Leave a Comment »
Posted by jpluimers on 2017/11/08
No more issue reporting: tohosokawa/rst-preview-pandoc: reStructuredText preview in Atom using Pandoc
This is a very useful Atom.io package, but it has one big issue: when you close a preview window then re-opening it, the settings are restored to the default -frst -thtml --webtex ones.
As I’m an Atom.io n00b, I need to dig into this another time.
Notes:
I want the defaults to include --standalone --toc --toc-depth=5 or at least --standalone --toc.
For now I’ve hardcoded them.
–jeroen
Posted in atom editor, CoffeeScript, Development, JavaScript/ECMAScript, Power User, Scripting, Software Development, Text Editors | Leave a Comment »
Posted by jpluimers on 2017/11/03
Via [WayBack] Graph of programming languages influence poster – nice gift idea for programmers… – This is why I Code – Google+:
A network graph with more than a thousand programming languages connected by influence relations. Highly influential languages like Lisp, Smalltalk, C, Java, Pascal, C++, Haskel or Python are shown as larger circles as compared to languages with little influence on others like PHP or Argh!. / The influence relation data was retrieved from Freebase in 2013. This design available on posters and other products. An awesome gift for programmers who are into digital art. • Also buy this artwork on wall prints, apparel, kids clothes, and more.
[WayBack] “Network Graph of Programming Language Influence – White Background” Posters by ramiro | Redbubble
I wonder how they drew the relations and why certain languages are in certain places.
--jeroen
Read the rest of this entry »
Posted in C, C++, COBOL, Development, Haskell, Java, Java Platform, JavaScript/ECMAScript, LISP, Pascal, Perl, PHP, Python, Ruby, Scripting, Smalltalk, Software Development, Turbo Prolog | Leave a Comment »
Posted by jpluimers on 2017/11/02
Quoted in full because even 2.5 years later, it’s just too funny:
- Python: What if everything was a dict?
- Java: What if everything was an object?
- JavaScript: What if everything was a dict *and* an object?
- C: What if everything was a pointer?
- APL: What if everything was an array?
- Tcl: What if everything was a string?
- Prolog: What if everything was a term?
- LISP: What if everything was a pair?
- Scheme: What if everything was a function?
- Haskell: What if everything was a monad?
- Assembly: What if everything was a register?
- Coq: What if everything was a type/proposition?
- COBOL: WHAT IF EVERYTHING WAS UPPERCASE?
- C#: What if everything was like Java, but different?
- Ruby: What if everything was monkey patched?
- Pascal: BEGIN What if everything was structured? END
- C++: What if we added everything to the language?
- C++11: What if we forgot to stop adding stuff?
- Rust: What if garbage collection didn’t exist?
- Go: What if we tried designing C a second time?
- Perl: What if shell, sed, and awk were one language?
- Perl6: What if we took the joke too far?
- PHP: What if we wanted to make SQL injection easier?
- VB: What if we wanted to allow anyone to program?
- VB.NET: What if we wanted to stop them again?
- Forth: What if everything was a stack?
- ColorForth: What if the stack was green?
- PostScript: What if everything was printed at 600dpi?
- XSLT: What if everything was an XML element?
- Make: What if everything was a dependency?
- m4: What if everything was incomprehensibly quoted?
- Scala: What if Haskell ran on the JVM?
- Clojure: What if LISP ran on the JVM?
- Lua: What if game developers got tired of C++?
- Mathematica: What if Stephen Wolfram invented everything?
- Malbolge: What if there is no god?
–jeroen
Read the rest of this entry »
Posted in .NET, APL, Assembly Language, BASIC, C, C#, C++, COBOL, Development, EPS/PostScript, Fun, Go (golang), Java, Java Platform, JavaScript/ECMAScript, LISP, Makefile, Pascal, Perl, PHP, Python, Quotes, Ruby, Rust, Scala, Scripting, Smalltalk, Software Development, T-Shirt quotes, TCL, Turbo Prolog, VB.NET, Visual BASIC, XML/XSD, XSLT | Leave a Comment »
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 [WayBack] User jAndy – Stack Overflow who answered the above at [WayBack] Is 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 »
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 [WayBack] Hutch Moore and [WayBack] Deviljho for answering at [WayBack] How 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 [WayBack] sam6ber:
In CSS:
p:first-letter {
text-transform:capitalize;
}
–jeroen
Posted in CSS, Development, JavaScript/ECMAScript, Scripting, Software Development, Web Development | Leave a Comment »
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 [WayBack] Finally: 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, vscode Visual Studio Code | 1 Comment »
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:
Read the rest of this entry »
Posted in Bookmarklet, Conference Topics, Conferences, Development, Event, JavaScript/ECMAScript, Power User, Scripting, Software Development, Web Browsers | Leave a Comment »
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" 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 »
Posted by jpluimers on 2017/04/26
Printing Markdown with GitPrint
Simply view any Markdown file on GitHub, then in your URL bar replace the github.com part of the URL with gitprint.com — your markdown file will be rendered to a beautiful, printable PDF.
Try an example https://gitprint.com/jquery/jquery/blob/master/README.md
Every once in a while I feel like I’ve been living under a stone for years. Today is such a day as gitprint has been around since 2014 and I only noticed it until now.
It’s cool as it prints any github page (including Markdown, RestructuredText, etc) as a PDF file.
Notes:
Read the rest of this entry »
Posted in Bookmarklet, Development, DVCS - Distributed Version Control, git, GitHub, jQuery, Software Development, Source Code Management, Web Browsers | Leave a Comment »