Show HN: I created a Github profile widget (learning to code)
github.com
github.com
If you need $(".stats") four times, don't repeat that four times, but do:
var stats = $('.stats')
and use the variable. Especially when using class selectors.End result looks good; keep on hacking :)
N.B.
Same is true for indexers (and allows you to refactor the code easier later on);
Instead of:
for (var i = 0; i < repos.length; i++) {
var language = repos[i].language ? repos[i].language : "Unknown";
$(".repositories").append('<div class="container"><div class="item names"><div><a href="' + repos[i].repoUrl + '">' + repos[i].name + '</a></div></div><div class="item language"><div>' + language + '</div></div><div class="item stars"><div>★' + repos[i].stars + '</div></div></div>');
}
Consider: for (var i = 0; i < repos.length; i++) {
var repo = repos[i];
var language = repo.language ? repo.language : "Unknown";
$(".repositories").append('<div class="container"><div class="item names"><div><a href="' + repo.repoUrl + '">' + repo.name + '</a></div></div><div class="item language"><div>' + language + '</div></div><div class="item stars"><div>★' + repo.stars + '</div></div></div>');
} const reposInfoHTML = repos
.map(repo =>
`<div class="container">
<div class="item names">
<div>
<a href="${repo.repoUrl}">${repo.name}</a>
</div>
</div>
<div class="item language">
<div>${repo.language || "Unknown"}</div>
</div>
<div class="item stars">
<div>★${repo.stars}</div>
</div>
</div>`);
$(".repositories").append(reposInfoHTML.join(''));I've experienced this in many web apps, which had major benefit from these changes. The same applies to managed code (C#), where just being mindful about how and what you write, makes everything faster.
I think it took several years before I started doing that. Maybe the new age of having everything shared on GitHub makes one focus earlier on maintainability and readability for others?
If you're not 100% sure that the GitHub data fields (bio, name, etc) are stripped of markup, please ensure that your widget isn't vulnerable to cross-site scripting (XSS).
There are GitHub users whose bios, names, etc contain HTML fragments. The way that your code inserts those fields is likely to be vulnerable. It's better to explicitly treat the fields as text, e.g. by using jQuery's text() method.
If you aren't getting a lot of use out of the features it provides then you are better off without such a heavyweight dependency.
It would be very handy to know what is a 'must have list' when implementing those kind of widgets, does anyone came across anything like this? I mean what I shall be aware in terms of XSS, security in overall and best practises.
Tip: Rather than repeating .append several times, concatenate your result in a variable, then at the end append the complete result. That way you just make one append call (performance). Referring to: https://github.com/surbhioberoi/github-widget/blob/master/sr...
- Use a tool like EsLint to lint your code. It will make it more readable and cleaner than it is right now. Maybe integrate your editor with Eslint and it will guide you to write cleaner code.
- You can use underscore templating to inject variables in the template and it will be much more cleaner and maintainable. http://underscorejs.org/
Lesson learned : Don't delete your old creative memories even if they are ridiculous.
note: I haven't filed it as bug yet, as I am unsure about the reason yet. But when I user data-username="gbraad" I do not see the correct Top repositories. At the top should have been 'gauth' (with 582 stars). When using the widget I see `blog` (with 7 stars). Might be because pinned repositories has been customized?
Suggestion: you're getting a lot of good feedback here. Might be good to create issues on the project. You'll likely get some takers too.
I remember creating something similar ( not as polished as this ) at a Yahoo! Hack Day, when I was new to coding.
I wanted to have a GitHub timeline on my personal website, instead of the Twitter timeline. After some hacking, I came out with this: https://github.com/todvora/gh-events-widget
Do you find this idea to be that revolutionary? (I guess not as someone linked other similar project (and you downvoted him))
Do you find this project in particular to be that interesting? (Doubt it with the scope of this project)
Not to take anything away from the effort that went into creating this, but judging from the history of (Show HN) posts that reach the front page, this is HIGHLY unusual.
Also of interest is the number of emoticons /:)/ in here - 25% of comments contain one, compared to other Show HN posts with 8.3%, 6% or general posts with 1.5%, 0.5%, 0%, ...
To answer these questions, we must only look into the mirror.
Also, please don't create many obscure throwaway accounts on HN. This forum is a community. Anonymity is fine, but users should have some consistent identity that other users can relate to. Otherwise we may as well have no usernames and no community, and that would be an entirely different forum.
Personally I flagged this - there are good sites for codereview e.g. http://codereview.stackexchange.com/ but I don't think HN is, or should be one of them.
I'm afraid it's your comment that's out of line. I don't think you intended it this way (and we appreciate your concern for the quality of HN), but in this context it comes across as squashing someone for their work, which combined with the automatic upvotes that negative comments sadly get, gives a rude and unpleasant impression of this community. Who would want to be part of a place that disses beginners?
wrt "dissing beginners", the post explicitly says: "Not to take anything away from the effort that went into creating this".
The reason posts like this are upvoted is to protect discourse from the neg-police.
And it's not getting anything away from the post, rather from the praise it got. The post itself is perfectly fine (and as such I didn't flag it).
Quality is multi-dimensional.
To HN community: good to see that people here are humans. It's amazing how a cool pic can trigger so many comments and upvotes :)
- I have another friend that is responsible for HR on a small business (not rocket science kind of job). While bachelor he used to select possible hires by photo. His boss was aware of it and wouldn't oppose, treating it as a kind of 'perk' for my friend..
TLDR: Humans seem to be more helpful to potential attractive mates.