Skip to content

Instantly share code, notes, and snippets.

View vithalreddy's full-sized avatar
🔥

Vithal Reddy vithalreddy

🔥
View GitHub Profile
@vithalreddy
vithalreddy / node-walk.es6
Created January 15, 2025 05:08 — forked from lovasoa/node-walk.es6
Walk through a directory recursively in node.js.
// ES6 version using asynchronous iterators, compatible with node v10.0+
const fs = require("fs");
const path = require("path");
async function* walk(dir) {
for await (const d of await fs.promises.opendir(dir)) {
const entry = path.join(dir, d.name);
if (d.isDirectory()) yield* walk(entry);
else if (d.isFile()) yield entry;
function formatFileSize(bytes,decimalPoint) {
if(bytes == 0) return '0 Bytes';
var k = 1000,
dm = decimalPoint || 2,
sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
}
//You only need to use the formatFileSize() function in JavaScript to convert file size units.
@vithalreddy
vithalreddy / rules_of_trade.md
Last active March 22, 2024 06:18
Rules of Trade -> FnO Options selling

✨ Rules of Trade ✨

  • Entry is free, Exit is not 🙅‍♂️
    • Don't enter, if you do enter follow the rules of engagement
    • Wait for SL and TP
    • One sec away from screen can blow your account 💯
  • Strike Selection and RR ratio Matters📊
    • Before entering any trade, please check it's strike price, delta and RR ratio
  • RRR: Your Key to Success🔑
    • Only Risk management is the real edge, everything else is just the smoke
/*
JSON-to-Go
by Matt Holt
https://github.com/mholt/json-to-go
A simple utility to translate JSON into a Go type definition.
*/
function jsonToGo(json, typename) {
let data;
let scope;
@vithalreddy
vithalreddy / pandas.py
Created August 4, 2019 05:52
Inverse of pandas json_normalize or json_denormalize – python pandas
# more at https://stackfame.com/inverse-of-pandas-json_normalize-or-json_denormalize-python-pandas
def make_formatted_dict(my_dict, key_arr, val):
"""
Set val at path in my_dict defined by the string (or serializable object) array key_arr
"""
current = my_dict
for i in range(len(key_arr)):
key = key_arr
if key not in current:
@vithalreddy
vithalreddy / listFiles.js
Created June 30, 2018 13:46
list of all files in a directory in Node.js
//requiring path and fs modules
const path = require('path');
const fs = require('fs');
//joining path of directory
const directoryPath = path.join(__dirname, 'Documents');
//passsing directoryPath and callback function
fs.readdir(directoryPath, function (err, files) {
//handling error
if (err) {
return console.log('Unable to scan directory: ' + err);
@vithalreddy
vithalreddy / cursortable.js
Created May 6, 2022 10:10 — forked from nmoinvaz/cursortable.js
Antd Cursor Paginated Table Component
import React, { useEffect, useState } from "react";
import { Table, Button, Space, Row, Col } from "antd";
import { LeftOutlined, RightOutlined } from "@ant-design/icons";
const CursorPagination = ({ lastEvaluatedKey, onChange, size }) => {
/* Use stack to keep track of which evaluated keys have been previously seen */
const [ prevEvaluatedKeys, setPrevEvaluatedKeys ] = useState([]);
/* Keep track of the current evaluated key */
const [ currentEvaluatedKey, setCurrentEvaluatedKey ] = useState(null);
@vithalreddy
vithalreddy / mysql - kill all sleeping connections
Created January 11, 2022 07:33 — forked from lucashungaro/mysql - kill all sleeping connections
MySQL - kill command for all idle queries
SELECT GROUP_CONCAT('kill ',id SEPARATOR '; ') AS kill_list
FROM INFORMATION_SCHEMA.PROCESSLIST
WHERE command='Sleep';
@vithalreddy
vithalreddy / cloudwatch_log_insights_mysql_slow_query_examples.md
Created November 8, 2021 12:15 — forked from grocky/cloudwatch_log_insights_mysql_slow_query_examples.md
CloudWatch Log Insights query examples for MySQL slow query log.

Filtering queries

Find slowest write queries

parse @message /Query_time: (?<queryTime>.*?) Lock_time: (?<lockTime>.*?) Rows_sent: (?<rowsSent>.*?) Rows_examined: (?<rowsExamined>.*?)\s(?<query>.*?)$/
  | filter @message like /(?i)insert/
  | sort queryTime desc
  | limit 10

Keybase proof

I hereby claim:

  • I am vithalreddy on github.
  • I am vithalreddy (https://keybase.io/vithalreddy) on keybase.
  • I have a public key whose fingerprint is 6293 F1F2 EC2D DC04 FD04 A909 8259 DCE2 BE2F C760

To claim this, I am signing this object: