Skip to content

Instantly share code, notes, and snippets.

View kosperera's full-sized avatar
🏠
Working from home

Kosala (KP) Perera kosperera

🏠
Working from home
View GitHub Profile
@kosperera
kosperera / show-ga-data.js
Last active April 30, 2019 08:13
Show Google Analytics Tracker data.
function showmethemoney(asjson) {
var a = ga.getAll();
a.forEach(function(g) {
var json = {
gid: g.get('_gid'),
trackingId: g.get('trackingId'),
clientId: g.get('clientId'),
cookieDomain: g.get('cookieDomain'),
location: g.get('location'),
data: JSON.parse(JSON.stringify(g.b.data.values))
@kosperera
kosperera / awesome-git.md
Last active November 14, 2023 05:04
Awesome Git Commands

Hard Reset Local branch to the origin/remote.

This basically discard all changes, commits, etc. which are not pushed to remote yet, and pull the latest version from the remote.

git fetch origin master
git reset --hard FETCH_HEAD
git clean -df

Managing sub-module repos.

@kosperera
kosperera / vanillajs-kebabcase.md
Last active August 28, 2020 11:15
Vanilla JS Kebab Case

kebabCase

You want to have a look at LoDash or Underscore or Slugify for more reliable version. This is just for fun, and probably might not suitable for any production use 🤓

So, I wanted to kebabCase a string literal without having to refer any of the aboves. After reading few js libraries mentioned above, this is what I ended up.

function kebabCase(value, separator = '_') {
  // Expression to trim trailings
  var defaultToWS = '[' + separator.replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1') + ']';
@kosperera
kosperera / check-grades.js
Last active October 31, 2021 13:49
Using JS conditionals
function ifGrade(marks) {
if (marks > 100) return 'Cheating is bad!';
else if (marks >= 90) return 'A+';
else if (marks >= 80) return 'A';
else if (marks >= 70) return 'B+';
else if (marks >= 60) return 'B';
else if (marks >= 50) return 'C';
else if (marks >= 40) return 'D';
else return 'F';
}