Skip to content

Instantly share code, notes, and snippets.

View privateOmega's full-sized avatar
🎮
Focusing

Kiran Mathew Mohan privateOmega

🎮
Focusing
  • Hinge Health
  • Bangalore, India
  • 08:52 (UTC +05:30)
View GitHub Profile
@privateOmega
privateOmega / find-git-changes-file.sh
Created November 11, 2021 05:32
find all git changes related to a file including renamings
git log --follow -p -- /Users/mathew/filters.js
@privateOmega
privateOmega / truthy-filter.js
Created November 10, 2021 12:33
truthy-filter.js
['a', 1, 0, false, true, '', null, undefined].filter(Boolean)
@privateOmega
privateOmega / normalize-css.js
Created October 7, 2021 09:29
Normalize CSS units
// Ref: https://stackoverflow.com/a/5652573/3672474
function normalizeCSSUnits( inputString ) {
const n = parseFloat( inputString );
const p = inputString.match( /%|em/ );
// eslint-disable-next-line no-nested-ternary
const outputString = isNaN( n ) ? '' : p ? n + p : Math.round( n ) + 'px';
return outputString;
}
@privateOmega
privateOmega / .gitlab-ci.yml
Created August 30, 2021 06:25
.gitlab-ci.yml for makensis
stages:
- build-installer
Build Installer:
stage: build-installer
image:
name: sirgallifrey/nsis
entrypoint: [""]
script:
- |
@privateOmega
privateOmega / pr.md
Created July 17, 2021 19:17 — forked from piscisaureus/pr.md
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@privateOmega
privateOmega / commarize.js
Created November 28, 2019 13:10
commarize numbers with 2 digit precision
function commarize(number, min) {
min = min || 1e3;
// Alter numbers larger than 1k
if (number >= min) {
let units = ["k", "M", "B", "T"];
let order = Math.floor(Math.log(number) / Math.log(1000));
let unitname = units[order - 1];
let num = Number((number / 1000 ** order).toFixed(2));
// output number remainder + unitname
return num + unitname;
@privateOmega
privateOmega / interval-creator.js
Created April 11, 2019 09:17
JS code to generate intervals between date
const createIntervals = (from, to, interval) => {
let time = new Date(from),
intervals = [];
do {
intervals.push(new Date(+time));
time.setMinutes(time.getMinutes() + interval);
} while (time <= new Date(to));
return intervals;
};
@privateOmega
privateOmega / knex-migration.js
Created March 22, 2019 03:54
Knex Migration failure test code.
'use strict';
exports.up = async knex => {
// Create Schema
await knex.raw('CREATE SCHEMA IF NOT EXISTS meraki');
// Load Extensions
await knex.raw('CREATE EXTENSION IF NOT EXISTS "uuid-ossp"');
// Roles
await knex.schema.withSchema('meraki').createTable('roles', table => {
table
@privateOmega
privateOmega / streams.js
Last active March 8, 2019 09:03
Stream Implementation Node.js
const { Duplex } = require('stream');
const duplexStream = new Duplex({
objectMode: true,
read() { },
write(chunk, encoding, callback) {
console.log('pull');
// Emulating slower write process compared to read speed.
setTimeout(() => {
console.log(`Write out: ${JSON.stringify(chunk)}`);
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Page Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@yaireo/tagify@2.10.1/dist/tagify.css">
<script src="https://cdn.jsdelivr.net/npm/@yaireo/tagify@2.10.1/dist/tagify.min.js"></script>