Skip to content

Instantly share code, notes, and snippets.

View shiv19's full-sized avatar
🎯
Focusing

Shiva Prasad shiv19

🎯
Focusing
View GitHub Profile
@shiv19
shiv19 / randColor.js
Last active August 9, 2019 23:03
get random hex color codes
const randColor = () => '#' + ('00000'+(Math.random()*(1<<24)|0).toString(16)).slice(-6);
@shiv19
shiv19 / rangeConvert.js
Last active July 31, 2019 23:17
convert a number from old range to new range
export function RangeConvertFactory({
oldMin, oldMax, newMin, newMax
}) {
const oldRange = oldMax - oldMin;
const newRange = newMax - newMin;
return (val) => (((val - oldMin) * newRange) / oldRange) + newMin;
}
// usage
@shiv19
shiv19 / changeAuthor.sh
Created June 27, 2019 01:30
shell script to change author of old commits
#!/bin/sh
git filter-branch --env-filter '
OLD_EMAIL="[email protected]"
CORRECT_NAME="Your Correct Name"
CORRECT_EMAIL="[email protected]"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
@shiv19
shiv19 / validationFn.js
Created June 13, 2019 21:31
ES 6 argument validation
var isType = (ctor, x) => Object(x) instanceof ctor
var fn = (sig, f) => {
return (...as) => {
// Argument mismatch
if (as.length < sig.length-1) {
throw new TypeError(`Argument ${sig.length-as.length} missing`)
}
// Argument type mismatch
as.forEach((a, i) => {
@shiv19
shiv19 / Cors.plist
Last active February 16, 2019 02:51
Use this to avoid nativescript cors error in ios, add to info.plist
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSExceptionDomains</key>
<dict>
<key>http://yourdomain.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
@shiv19
shiv19 / actionbarPopupColor.md
Last active February 7, 2019 07:02
How to change popup overflow icon color for action bar Android NativeScript

first you have to define the color (or you can use one of those that are already defined)

app\App_Resources\Android\src\main\res\values-v21\colors.xml

<resources>
	. . .
	<color name="my_white">#fff</color>
</resources>
@shiv19
shiv19 / getNavBarHeight.js
Created January 6, 2019 21:56
Get Android Navigation bar height NativeScript
function getNavBarHeight() {
const app = require("application");
if (app.android) {
let navBarHeight = 0;
let windowManager = app.android.context
.getSystemService(android.content.Context.WINDOW_SERVICE);
let d = windowManager.getDefaultDisplay();
let realDisplayMetrics = new android.util.DisplayMetrics();
d.getRealMetrics(realDisplayMetrics);
@shiv19
shiv19 / useful.sh
Created November 5, 2018 19:49 — forked from veggiemonk/useful.sh
Useful commands
# Commands that are useful once in a while but not always for everyday usage
# Remove all node_modules forlder recursively
find . -name "node_modules" -type d -prune -exec rm -rf '{}' +
# List globally installed npm package
npm list -g --depth=0
# Loop over files in the current dir
for f in *; do
@shiv19
shiv19 / git-pull-pr-to-local.md
Created October 16, 2018 12:54
Pulling un-merged pull request to local branch
git fetch origin pull/ID/head:BRANCHNAME
  • ID: ID of the PR,
  • BRANCHNAME: name of the local branch which doesn't exist yet.

example:

@shiv19
shiv19 / ssl.sh
Created October 5, 2018 10:21
How to create ssl cert
openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -keyout key.pem -out cert.pem
after this you can `http-server -S -o` to run it on localhost in https mode.