Skip to content

Instantly share code, notes, and snippets.

View Goku-kun's full-sized avatar
:octocat:
Totally available to code!

Dharmarajsinh Jethva Goku-kun

:octocat:
Totally available to code!
View GitHub Profile
@Goku-kun
Goku-kun / 1-setup.md
Created November 1, 2023 05:23 — forked from troyfontaine/1-setup.md
Signing your Git Commits using GPG on MacOS

Methods of Signing with a GPG Key on MacOS

Last updated September 21, 2022

This Gist explains how to do this using gpg in a step-by-step fashion. Previously, krypt.co was heavily mentioned, but I've only recently learned they were acquired by Akamai and no longer update their previous free products. Those mentions have been removed.

For using a GUI-based GIT tool such as Tower or Github Desktop, follow the steps here for signing your commits with GPG.

There has been a number of comments on this gist regarding some issues around the pinentry-program and M1 Macs. I've finally gotten a chance to try things out on an M1 and I've updated the documentation in 2-using-gpg.md to reflect my findings.

@Goku-kun
Goku-kun / useFetch.js
Created May 26, 2022 09:34
This gist contains a useFetch hook to fetch something asynchronously using the uri.
import { useState, useEffect } from "react";
export function useFetch(uri) {
const [data, setData] = useState();
const [loading, setLoading] = useState(true);
const [state, setState] = useState(null);
useEffect(
function () {
if (uri == undefined) return;
@Goku-kun
Goku-kun / with_context_manager.py
Created February 22, 2022 16:27
This gist explains how to create a custom context manager(using the example of a timing mechanism for some code) in python.
from contextlib import contextmanager
import time
class MeasureTime:
def __init__(self) -> None:
pass
def __enter__(self):
@Goku-kun
Goku-kun / boiledDownReduxImplementation.js
Last active January 13, 2022 04:04
This gist is a very stripped out implementation of the redux library.
function createStore(reducer) {
let state;
let subscribers = [];
function getState() {
return state;
}
function dispatch(action) {
state = reducer(state, action);
@Goku-kun
Goku-kun / globalObjectPolyfill.js
Last active March 21, 2021 04:48
This is a reliable cross environment global object reference polyfill which allows access to the global object of any JS environment using the identifier called theGlobalScopeObject.
const theGlobalScopeObject =
(typeof globalThis != "undefined") ? globalThis :
(typeof global != "undefined") ? global :
(typeof window != "undefined") ? window :
(typeof self != "undefined") ? self :
(new Function("return this"))();
// globalThis is a standardized object as of ES2020 which can be used to access the global scope.
// To find the reference of the global of any environment, the following script can be used:
@Goku-kun
Goku-kun / infiniteNodeServer.sh
Created February 22, 2021 15:55
If the node server crashes because of some minor bug which can be ignored, then start the node server using this bash script. Or else, use Nodemon.
while true; do node server.js; done
@Goku-kun
Goku-kun / generateObjectToString.js
Created February 15, 2021 13:03
This function is a better way to generate object in my opinion since when an object is stringified, it's string representation is the object instead of the "[object Object]".
function genObject() {
return {
toString() {
return JSON.stringify(this);
}
}
}
@Goku-kun
Goku-kun / intersection.js
Last active January 29, 2021 13:23
This gist contains JS code for finding an intersection of many arrays
function intersection(arrays) {
return arrays.reduce((array, nextArray) => {
return nextArray.filter(input => {
return array.includes(input)
})
}).reverse()
}
console.log(intersection([[1,2,3], [2,3,4], [3,4,5]]))
@Goku-kun
Goku-kun / script.js
Created November 22, 2020 11:03
Solution to the DNA pAequor problem
// Returns a random DNA base
const returnRandBase = () => {
const dnaBases = ['A', 'T', 'C', 'G']
return dnaBases[Math.floor(Math.random() * 4)]
}
// Returns a random single stand of DNA containing 15 bases
const mockUpStrand = () => {
const newStrand = []
for (let i = 0; i < 15; i++) {
@Goku-kun
Goku-kun / main.js
Created November 21, 2020 16:39
solution to the credit card checker project
// All valid credit card numbers
const valid1 = [4, 5, 3, 9, 6, 7, 7, 9, 0, 8, 0, 1, 6, 8, 0, 8];
const valid2 = [5, 5, 3, 5, 7, 6, 6, 7, 6, 8, 7, 5, 1, 4, 3, 9];
const valid3 = [3, 7, 1, 6, 1, 2, 0, 1, 9, 9, 8, 5, 2, 3, 6];
const valid4 = [6, 0, 1, 1, 1, 4, 4, 3, 4, 0, 6, 8, 2, 9, 0, 5];
const valid5 = [4, 5, 3, 9, 4, 0, 4, 9, 6, 7, 8, 6, 9, 6, 6, 6];
// All invalid credit card numbers
const invalid1 = [4, 5, 3, 2, 7, 7, 8, 7, 7, 1, 0, 9, 1, 7, 9, 5];
const invalid2 = [5, 7, 9, 5, 5, 9, 3, 3, 9, 2, 1, 3, 4, 6, 4, 3];