How to get project badge via GitHub API? - api

I have build a resume page for my self, and list all my projects there by using GitHub API. Some of the project are document which have rtfd build passing badge, some are python projects which have travis-ci and pep-lint badges.
Now, I want to display the badges as with the projects, how should I use with the API?
My page is here: http://gh.windrunner.info/resume/#/github

You could also use a different API with https://github-shields.com/
See "How to embed live Github PR status in your blogs & docs"
Consider the PR https://github.com/cloudfoundry/bosh/pull/715.
The URL doesn't indicate if the PR is open/merged/closed.
The cloudfoundry/bosh/pull/715 portion of the URL is copied directly into the following base URL:
https://github-shields.com/github/ + cloudfoundry/bosh/pull/715 + .svg gives a URL that redirects to the PR.
https://github-shields.com/github/cloudfoundry/bosh/pull/715.svg
As an image URL it gives cloudfoundry/bosh/pull/715
Awesome, it was merged!
For the status of a project, the OP kxxoling reports in the comments having found shields.io:
https://img.shields.io/badge/<SUBJECT>-<STATUS>-<COLOR>.svg
it indicates how to get the status of a badge.
If there none badge added for that project, it will return a inaccessible badge like this: https://img.shields.io/travis/kxxoling/z42-doc.svg =>

For projects like https://github.com/kxxoling/z42-doc (which does have a badge in it), you need to fetch the README and then search through it for possible badges. Without knowing what language you'd prefer to use, I'm going to write some pseudo-code
First you need to retrieve the README that GitHub identified as the one to render on your home-page. You can do this by doing
GET /repos/kxxoling/z42-doc/readme
Host: https://api.github.com
Accept: application/vnd.github.v3.raw
If instead you'd rather parse HTML, change "raw" to "html" in the last header, e.g.,
GET /repos/kxxoling/z42-doc/readme
Host: https://api.github.com
Accept: application/vnd.github.v3.html
With the contents of the README, now you just need to parse it for links or directives that are specific to the mark-up languages you chose for your READMEs. You can parse them out with regular expressions or an HTML/XML parsing library of your choosing (if you're retrieving the rendered content from GitHub).

Related

Can vscode's markdown preview scripts trigger actions directly in an extension?

I'm writing a vscode extension where I'm hoping to squeeze more dynamic functionality out of markdown preview. Effectively the problem I'm trying to solve is:
In markdown preview, there's a checkbox
When user clicks the checkbox in markdown preview, send a message/event to the vscode extension runtime
Vscode extension can listen for this message/event and store the action in local storage
Checkbox state is saved - and subsequent renders of the markdown preview can use this action
Ideally, I'd like to do this while keeping the default markdown preview security (https://code.visualstudio.com/Docs/languages/markdown#_strict). After all, I don't need the extension to or markdown preview script to talk to a remote server - I just want them to be able to talk to one another.
Problem as code
To write the problem as sudo code, I want my markdown preview script to contain something like:
const button = ... // get button element
button.addEventListener('click', () => {
... /*
* Send a message to the vscode extension. Something like:
* `vscode.postMessage('vscode.my-extension.preview-action' + value)`
* (which I can't get to work, I'll discuss why)
*/
});
where then my extension can listen for messages like 'vscode.my-extension.preview-action'.
What I've Tried Already
I have tried acquireVsCodeApi() but because the markdown extension already does that, I can't do it again in the subsequent loaded script. I've also tried registering a uri handler but as far as I can try out the preview script still needs to fetch to that uri, which is still blocked by the default markdown security settings.
Perhaps markdown preview scripts are not the place to do this kind of thing, but I just wanted to leverage as much as possible that's already there with the vscode markdown extension. I want to supplement markdown but not replace it, the functionality I want to add is just icing on markdown documentation.
I've read https://code.visualstudio.com/api/extension-guides/markdown-extension#adding-advanced-functionality-with-scripts and it doesn't tell me much about markdown extension scripts capabilities and limitations.
Thanks to #LexLi I looked at some of the source code in the markdown extension and was able to come up with an ugly hack to make this work in preview scripts. Markdown allows normal clicks. And vscode extensions can handle normal clicks. I've paraphrased the code so there could be small syntax errors.
In the extension I did this:
vscode.window.registerUriHandler({
handleUri(uri: vscode.Uri): vscode.ProviderResult<void> {
console.log(`EXTENSION GOT URL: ${uri.toString()}`);
},
});
Then I made sure my extension/preview script put this in the document
<!-- in the preview script I place a button like this -->
<!-- it even works with hidden :) so I can do more app customization -->
<a
hidden
id="my-extension-messager"
href="vscode://publisher-id.my-extension"
>
cant see me but I'm there
</a>
Then my preview script I can even set href before faking a click:
const aMessager = document.querySelector("#my-extension-messager");
console.log('client is setting attribute and clicking...')
aMessager.setAttribute('href', 'vscode://publisher-id.my-extension?action=do-something');
aMessager.click();
console.log('client clicked');
Logs I saw (trimmed/tweaked from my particular extension to match the contrived example):
client is setting attribute and clicking...
client clicked
[Extension Host] EXTENSION GOT URL: vscode://publisher-id.my-extension?action%3Ddo-something
It's a hack but I can do a lot with this. Within the URL I can encode data back to the extension and kind of pass whatever I want (as long as data is relatively small).

What Framework and Header file contain the constant for kAudioUnitSubType_RemoteIO

I keep seeing samples that use kAudioUnitSubType_RemoteIO for the Apple audio unit api. I am wondering however what framework/header file contains this constant.
The kAudioUnitSubType_RemoteIO file is in the header AUComponent.h. It is in the AudioUnit.framework.
As the comment says, open Xcode and click Help menu in the top bar, select Documentation and API Reference, search kAudioUnitSubType_RemoteIO and you'll see the results.
That's the way to find the sample usage and document for official resource.

DuckDuckGo API - How to get more results?

The default search using the DuckDuckGo API returns only the results on the first page (around 25 I guess). Is there any way to get more results or navigate to the 2nd, 3rd pages of the search results?
Websites like Faroo have a parameter called s (which stands for start) which can be set to 1 if we want the first 10 results, to 11 if we want the next 10 results and so on. Is there something like that for DuckDuckGo, too?
According to DuckDuckGo Search API documentation, all the available parameters are:
q: query
format: output format (json or xml)
If format=='json', you can also pass:
callback: function to callback (JSONP format) pretty: 1 to make JSON
look pretty (like JSONView for Chrome/Firefox)
no_redirect: 1 to skip HTTP redirects (for !bang commands).
no_html: 1 to remove HTML from text, e.g. bold and italics.
skip_disambig: 1 to skip disambiguation (D) Type.
In particular, note that:
This API does not include all of our links, however. That is, it is
not a full search results API or a way to get DuckDuckGo results into
your applications beyond our instant answers.
TL/DR; - Install TamperMonkey, add the short script below (full instructions follow) and the browser will lazy-load the next page(s) automatically as you scroll.
After coming to this answer via Google and not finding the information I was seeking, I wrote this small TamperMonkey script to do the job. I post it here for future googlers.
The below userscript will work with Chrome, Firefox and Opera. Instructions for installation follow below the script, and a brief explanation of what TamperMonkey is follows below that.
This script is inspired by, and named similarly to (in honor of), Endless Google by Tumpio.
// ==UserScript==
// #name Endless DuckDuckGo
// #namespace http://tampermonkey.net/
// #match https://duckduckgo.com/?q=*
// #require http://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js
// #grant none
// ==/UserScript==
(function() {
'use strict';
$(window).scroll(function(){
var els = document.querySelectorAll('.result.result--more');
if (els.length){
var elmore = document.querySelectorAll('.result--more__btn.btn.btn--full');
if (elmore.length){
elmore[0].click();
}
}
});
})(); //
How To Install the Above Script:
Install the TamperMonkey extension for Chrome (or the "add-in" for Firefox).
You will see the TamperMonkey icon appear at the top of the browser
Do a search on DuckDuckGo
Click on the TamperMonkey icon and from the drop-down menu, choose Dashboard
Along the tabs at the top of the Dashboard page, click on the [+] icon at left of the tab strip
The TamperMonkey editor will open up with a blank UserScript template. Delete that entire sample script and replace it with the script from this post.
Save [Ctrl] + [s]
Run another DuckDuckGo search and scroll down the page... True happiness is yours.
What Is TamperMonkey:
A good overview is here.
TamperMonkey is a browser extension, and there is a version of TamperMonkey for each major browser. You probably already use the AdBlock or uBlock browser extensions (if not, WHY NOT?), this is just another extension like those. Anyway, to install for Chrome or Brave, go to the Chrome Web Store and search for TamperMonkey by Jan Binoc. Install it. (Yes, it's safe - there are hundreds of thousands of users, mostly coders). Please consider donating - Jan deserves your support (and no, I don't know him, and yes I donated.)
Before TamperMonkey, there was another extension called GreaseMonkey that did the same thing but only worked on Firefox. However, the GreaseMonkey authors stopped maintaining it or something, and Jan Binoc stepped up to the plate with TamperMonkey.
TamperMonkey allows us to inject our own code into ANY webpage, to programmatically manipulate the web page on our local computers. How does that work? Simplistic Explanation: When you view a web page, you never actually view it "directly from the web server" - your browser first downloads a local copy of the web page code to your browser's cache folder and displays it to you from there. Therefore, TamperMonkey can intercept the page as it loads from cache (on your local hard drive) into the browser and modify it before it is displayed. That explanation is super-simplistic and not fully technically accurate, but in essence that is exactly how it works, and why TamperMonkey works. Most Importantly: The above few lines explain why the page does not change for anyone else - just for you, on your own computer.
TamperMonkey is an excellent reason to learn a bit of javascript/css/html. Using it, you can do stuff like hiding or re-arranging images on a webpage, removing clutter from a page, totally reformatting a page, etc. For example, one of my fav News sites has lots of clutter. So, I go to their RSS feed page, which acts like a great index of articles, but that also has too much stuff I don't want to see (mainly unnecessary thumbnail images and too-narrow columns). I wrote a short TM script to hide all the images and widen the columns and now, instead of seeing 5 or 6 article summaries per screen, I see ~ 20.
The absolute best, most concise, primer for html/css/js that I've ever seen is on Lynda.com. (You might already have access via your local library card - I was greatly surprised to find out that I do.) There is a series by Emma Saunders called D3.js Essential Training for Data Scientists. The course begins with two short tutorials (Recalling HTML Basics (4m) and Understanding HTML5 (3m) ) in html/css/js that are worth a university course tuition by themselves. Why can't everyone teach like this? Anyway, that's all you need - those first two (3 and 4 min) videos. Now, go tweak a webpage.
(Final disclaimer: No, I don't know Emma Saunders either, nor do I have anything to do with either Binoc's or Saunders' products in any way. I'm just a run-of-the-mill user and fan.)

Titanium: Notification with download status

I want to create a notification that will include a download status, such as the photo below (marked in yellow:
Is there a special way of doing these? A code sample would be nice...
There indeed is a special way of doing it. Usually these kind of features require a module to be included. This can easily be done by using Gitt.io.
The module in question is nc.progressnotification
You can find the module on Github, or through Gitt.io.
An example is added to the app.js file in the example folder

Bigcommerce - Side Cart Total always shows $29.00

I am having some issues with a BigCommerce theme. It is an exact copy of a working theme, but on the new site, the mini basket/cart always shows $29.00 no matter what is in the cart (site is also set up to use £)
The issue lies with %%LNG_SideCartTotalCost%%.
Whats odd is that I checked the language file (via the url) and the text for this variable should be:
"Your sub total is <strong>%s</strong>."
Yet its coming through as:
"Total: <strong>%s</strong>."
I'm unsure who this was changed (the site is a clients, who has had work done by other developers)
How would someone change this language variable in BigCommerce? I was under the impression you could only edit themes, and not code?
So, any thoughts on how to fix this?
Thanks!
I work at Bigcommerce. The file you will need to edit is the sidecartcontents.html file. You are able to customize HTML, CSS, Javascript and JQuery. The only thing you don't have access to is any global variables that require PHP files. As a SaaS platform, we don't provide our clients access to the PHP files.
Turns out is was an issue with the language file. The support staff had to update it.