Skip to content

Instantly share code, notes, and snippets.

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

Lakshman lakshmankashyap

🏠
Working from home
View GitHub Profile
@lakshmankashyap
lakshmankashyap / js
Created January 22, 2018 16:37
Mongo push error
const userSchema = new mongoose.Schema({
email: {
type: String,
unique: true,
trim: true,
required: true
},
name: {
type: String,
trim: true,
Security - the elephant in the room. Everyone agrees that it is very important but few takes it seriously. We at RisingStack want you to do it right - this is why we have put together this checklist to help you guide through the must have security checks before your application is enabled to thousands of users/customers.
Most of these items are general and applies to all languages and frameworks not just Node.js - however some of the tools presented are Node.js specific. You should also check our introductory Node.js security blogpost.
Configuration Management
Security HTTP Headers
There are some security-related HTTP headers that your site should set. These headers are:
@lakshmankashyap
lakshmankashyap / inactivity.js
Created February 6, 2018 17:38 — forked from gerard-kanters/inactivity.js
Inactivity timeout javascript
<script type="text/javascript">
function idleTimer() {
var t;
//window.onload = resetTimer;
window.onmousemove = resetTimer; // catches mouse movements
window.onmousedown = resetTimer; // catches mouse movements
window.onclick = resetTimer; // catches mouse clicks
window.onscroll = resetTimer; // catches scrolling
window.onkeypress = resetTimer; //catches keyboard actions
@lakshmankashyap
lakshmankashyap / inactivity.js
Created February 6, 2018 17:38 — forked from gerard-kanters/inactivity.js
Inactivity timeout javascript
<script type="text/javascript">
function idleTimer() {
var t;
//window.onload = resetTimer;
window.onmousemove = resetTimer; // catches mouse movements
window.onmousedown = resetTimer; // catches mouse movements
window.onclick = resetTimer; // catches mouse clicks
window.onscroll = resetTimer; // catches scrolling
window.onkeypress = resetTimer; //catches keyboard actions
@lakshmankashyap
lakshmankashyap / nodejs
Last active February 14, 2018 19:29
Et quis nulla sed nulla qui
===========memory use ==============
process.memoryUsage()
const used = process.memoryUsage().heapUsed / 1024 / 1024;
sails.log(`The script uses approximately ${Math.round(used * 100) / 100} MB`);
-L <a href="https://www.dynatrace.com/news/blog/understanding-garbage-collection-and-hunting-memory-leaks-in-node-js/">Link</a>
=====================
@lakshmankashyap
lakshmankashyap / gist:8d5eda3974613927b8e3df24929411ac
Created February 26, 2018 08:03 — forked from chad3814/gist:2924672
deleting array items in javascript with forEach() and splice()
// This is from my comment here: http://wolfram.kriesing.de/blog/index.php/2008/javascript-remove-element-from-array/comment-page-2#comment-466561
/*
* How to delete items from an Array in JavaScript, an exhaustive guide
*/
// DON'T use the delete operator, it leaves a hole in the array:
var arr = [4, 5, 6];
delete arr[1]; // arr now: [4, undefined, 6]
@lakshmankashyap
lakshmankashyap / recover.js
Created March 9, 2018 11:31
Recover Ethereum keystore using the private key and keystore password
#!/bin/node
// https://github.com/ethereumjs/ethereumjs-wallet
// -> npm install ethereumjs-wallet
var Wallet = require('ethereumjs-wallet');
var privateKey = '-> your private key here <-'; // in hex format
var keystorePassword = '-> your keystore password here <-';
var wallet = Wallet.fromPrivateKey(Buffer.from(privateKey, 'hex'));
@lakshmankashyap
lakshmankashyap / recover.md
Last active March 14, 2018 19:21
Recover Ethereum keystore using the private key and keystore password

/bin/node

// https://github.com/ethereumjs/ethereumjs-wallet
// -> npm install ethereumjs-wallet
var Wallet = require('ethereumjs-wallet');

var privateKey = '-> your private key here <-'; // in hex format
var keystorePassword = '-> your keystore password here <-';

var wallet = Wallet.fromPrivateKey(Buffer.from(privateKey, 'hex'));
var Bitcore = require('bitcore');
var Address = Bitcore.Address;
var HDPrivateKey = Bitcore.HDPrivateKey;
var hdPrivateKey = new HDPrivateKey.fromSeed("bf8e06fd8c0dafbc831933422895ad68c0874439e177f136f8f756b360de94f8");
var hdPublicKey = hdPrivateKey.hdPublicKey;
var address = new Address(hdPublicKey.derive( Math.floor(Date.now() / 1000) ).publicKey);
var derivedAddress = new Address(hdPublicKey.derive( Math.floor(Date.now() / 1000) ).publicKey);
@lakshmankashyap
lakshmankashyap / createDefaultAccounts.js
Created March 16, 2018 18:43 — forked from pau1m/createDefaultAccounts.js
Handy script for generating Ethereum accounts (json files) from Mnemonic
//const argv = require('minimist')(process.argv.slice(2));
const Web3 = require("web3")
let web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"))
console.log(web3)
let bip39 = require("bip39")
let hdkey = require('ethereumjs-wallet/hdkey')
let mnemonic = "weather cancel symptom owner lumber bitter bread butter dice trial shrug glance"
let hdwallet = hdkey.fromMasterSeed(bip39.mnemonicToSeed(mnemonic))
// Set to m/44'/60'/0' for ledger nano s hardware wallet compatibilty