Skip to content

Instantly share code, notes, and snippets.

Avatar

Gokul N K nkgokul

View GitHub Profile
@nkgokul
nkgokul / persistence.js
Last active Aug 24, 2021
Persistence of a number
View persistence.js
function digit_product(number) {
let digit_product = 1;
while (number) {
digit_product *= number % 10;
number = Math.floor(number / 10);
}
return digit_product;
}
function persistence(number) {
@nkgokul
nkgokul / LICENSE
Last active Jun 12, 2021 — forked from yanofsky/LICENSE
A script to download all of a user's tweets into a csv
View LICENSE
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
@nkgokul
nkgokul / api.xony.io-twitter-naval-medium.js
Created Dec 10, 2020
api.xony.io/twitter/naval/medium
View api.xony.io-twitter-naval-medium.js
[
{
"medium": "https://medium.com/@naval"
}
]
View api.xony.io-twitter-naval.js
[
{
"medium": "https://medium.com/@naval"
},
{
"twitter":"https://twitter.com/gokulnk"
}
]
View sentry_fractional_logging.js
const percentateOfErrorsToLog = 30;
const percentateOfErrorsToLogFraction = percentateOfErrorsToLog/100;
const threshold = 1 - percentateOfErrorsToLogFraction;
try {
someErrorCasuingFunction();
}
catch(error) {
if(Math.random() >= threshold) {
Sentry.captureException(error);
}
@nkgokul
nkgokul / check_rand_function_distribution.js
Created Dec 24, 2019
Check rnadom function distribution
View check_rand_function_distribution.js
function checkUniformDistributionOfRandom(percentateOfErrorsToLog = 10) {
const percentateOfErrorsToLogFraction = percentateOfErrorsToLog/100;
const threshold = 1 - percentateOfErrorsToLogFraction;
const numberOfLoops = 1000;
for (let i=1; i<numberOfLoops; i++){
if (Math.random() >= threshold) console.log("This should be printed " + percentateOfErrorsToLogFraction * numberOfLoops + " times");
}
}
[10, 20, 30, 40, 50, 60, 70, 80, 90].map(checkUniformDistributionOfRandom);
@nkgokul
nkgokul / recursive_digit_sum
Last active Sep 14, 2019
Recursive Digit Sum
View recursive_digit_sum
{
function recuresiveDigitSumMaths(number) {
finalRecuresiveDigitSum = 0;
while (number) {
digit = number % 10;
finalRecuresiveDigitSum += digit;
if (finalRecuresiveDigitSum > 9) finalRecuresiveDigitSum -= 9;
number = (number - digit) / 10
}
View recursive_digit_sum
{
function recuresiveSum(number){
finalRecursiveSum = 0;
while(number){
digit = number % 10;
finalRecursiveSum += digit;
if (finalRecursiveSum>9) finalRecursiveSum -=9;
number = (number-digit)/10
}
return (finalRecursiveSum);
View list_of_twitter_username.js
Array.from(document.querySelectorAll('section a span')).filter(function(el){return el.textContent.indexOf("@") > -1}).reduce(function(ac,cv){return ac + cv.textContent + ", "});
@nkgokul
nkgokul / entity_details.php
Created Jul 22, 2019
Entity and Field Details
View entity_details.php
use Drupal\node\Entity\Node;
$entity = Node::load(1183);
$fields = array_keys($entity->getFieldDefinitions());
dpm($fields);
foreach($fields as $field_name) {
dpm("Field Name");
dpm($field_name);
dpm("--------------");
dpm("Field Value");
dpm($entity->get($field_name)->value);