Skip to content

Instantly share code, notes, and snippets.

@jsuryahyd
jsuryahyd / react.gradle
Created September 14, 2019 14:37
react-native : working react.gradle with hermes-engine for 0.60.x
//0.60.x, enableHermes-true : replace hermesvm with hermes-engine(npm install hermes-engine)
// and include this file in app folder change react.gradle path to this filepath
// in app/build.gradle
import org.apache.tools.ant.taskdefs.condition.Os
def config = project.hasProperty("react") ? project.react : [];
def cliPath = config.cliPath ?: "node_modules/react-native/cli.js"
def composeSourceMapsPath = config.composeSourceMapsPath ?: "node_modules/react-native/scripts/compose-source-maps.js"
def bundleAssetName = config.bundleAssetName ?: "index.android.bundle"
@jsuryahyd
jsuryahyd / exif-data.html
Last active October 9, 2019 06:11
Extract metadata from image using exif-js; has drag-drop box to drop image into, and shows metadata if any exists.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>EXIF example with inline EXIF info</title>
</head>
<body>
<br />
void main() {
// //1
// final List<dynamic> myNums = ["1", "whatever", {}];
// // final List<dynamic> myNums = const ["1","whatever",{}];
// myNums.add("lskf");
// // myNums = [...myNums,"lskf"];
// print(myNums);
// //2
// List<int> nums = List(5);
@jsuryahyd
jsuryahyd / dbUtils.js
Created January 27, 2020 05:11
promisifying transaction related functions of node mysql library
getPromisifiedConnection(pool) {
return util.promisify(pool.getConnection).bind(pool);
}
getPromisifiedBeginTransaction(connection) {
return util.promisify(connection.beginTransaction.bind(connection));
}
getPromisifiedQuery(connection) {
util.promisify((sql, options, cb) =>
@jsuryahyd
jsuryahyd / helpers.js
Last active August 17, 2023 06:44
Utils
export function uniqueItems(objArray, key) {
if (!objArray || !key) {
console.error("no args", objArray, key);
return objArray;
}
return objArray.reduce((result, obj) => {
if (result.find((o) => o[key] == obj[key])) {
return result;
}
@jsuryahyd
jsuryahyd / encrypt_decrypt.js
Created April 19, 2020 10:34
Encrypt and Decrypt in nodejs using crypto module
// https://gist.github.com/vlucas/2bd40f62d20c1d49237a109d491974eb
"use strict";
const { errorLog } = require("./logger");
const crypto = require("crypto");
const ENCRYPTION_KEY =
process.env.ENCRYPTION_KEY || "Dw-3]v,#FX@1gerbSAC4Jhn2=$!q/K.Z"; // Must be 256 bits (32 characters)
const IV_LENGTH = 16; // For AES, this is always 16
@jsuryahyd
jsuryahyd / logger.js
Created April 19, 2020 10:35
Create log files date wise using log4js in nodejs
//log
const log4js = require("log4js");
const path = require("path");
log4js.configure({
appenders: {
errors: {
type: "dateFile",
filename: path.join(__dirname, "../../logs", "errors.log")
}
},
@jsuryahyd
jsuryahyd / debounce.js
Created July 14, 2020 13:21
Some utils for frontend
/**
const myInput = document.getElementById("myInput");
function helloInput() {
console.log( "You typed:", myInput.value );
}
myInput.addEventListener(
"keyup",
debounce( helloInput, 1000 )
@jsuryahyd
jsuryahyd / clipboard-helpers.js
Last active August 13, 2020 09:48
Clipboard reading with browser js
/*
- https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/read
- https://stackoverflow.com/a/23024504/7314900
- https://stackoverflow.com/a/54132144/7314900
*/
function getTextFromBlob(blob){
var reader = new FileReader();
reader.onload = function() {
console.log(reader.result);
}
@jsuryahyd
jsuryahyd / snip.js
Created October 24, 2020 07:11
Algorithm/snippet to get odd item in two arrays
function removal(cA,bA) {
var count = 0;
for (var i = 0; i < cA.length; i++) {
if (i < 0) continue;
for (var j = 0; j < bA.length; j++) {
if (i < 0 || j < 0) continue;
count++;
console.log('comparing', i, j, cA[i], bA[j]);
if (cA[i] == bA[j]) {
console.log('removed', i, j, cA[i], bA[j]);