Skip to content

Instantly share code, notes, and snippets.

View krrishd's full-sized avatar
🤯

Krish Dholakiya krrishd

🤯
View GitHub Profile
@krrishd
krrishd / parseSlackArchive.js
Created July 26, 2018 18:27
get nice data from a slack archive
'use strict';
const fs = require('fs');
const path = require('path');
const async = require('async');
const getUserFromMessage = (messageObject, userList) => {
const relevantUser = userList.filter(user => {
return (user.id == messageObject.user);
})[0];
@krrishd
krrishd / write-word-frequency-counter.js
Last active February 7, 2017 05:53
Word frequency counter for content in your write.surge.sh savefile.
'use strict';
const obviousWords = ["a", "able", "about", "across", "after", "all", "almost", "also", "am", "among", "an", "and", "any", "are", "as", "at", "be", "because", "been", "but", "by", "can", "cannot", "could", "dear", "did", "do", "does", "either", "else", "ever", "every", "for", "from", "get", "got", "had", "has", "have", "he", "her", "hers", "him", "his", "how", "however", "i", "if", "in", "into", "is", "it", "its", "just", "least", "let", "like", "likely", "may", "me", "might", "most", "must", "my", "neither", "no", "nor", "not", "of", "off", "often", "on", "only", "or", "other", "our", "own", "rather", "said", "say", "says", "she", "should", "since", "so", "some", "than", "that", "the", "their", "them", "then", "there", "these", "they", "this", "tis", "to", "too", "twas", "us", "wants", "was", "we", "were", "what", "when", "where", "which", "while", "who", "whom", "why", "will", "with", "would", "yet", "you", "your", "ain't", "aren't", "can't", "could've", "couldn't", "didn't", "doesn't", "don'
@krrishd
krrishd / localStore.js
Last active December 30, 2016 22:18
A basic localStorage ORM
class LocalStore {
constructor(storeName) {
this.storeName = storeName;
localStorage[storeName] = JSON.stringify([]);
}
getAll() {
return JSON.parse(
localStorage[this.storeName]
);
// This is what I ran in the console of the browser to scrape the data:
function tableToJson(table) {
var data = [];
// first row needs to be headers
var headers = [];
for (var i=0; i<table.rows[0].cells.length; i++) {
headers[i] = table.rows[0].cells[i].innerHTML.toLowerCase().replace(/ /gi,'');
}
// go through cells

What impact do you want to have on the world and why? (500 words maximum)

I'd like my impact on the world to be socially meaningful while simultaneously leveraging technology. There are a lot of social issues to which technology isn't the immediate solution: a mobile app isn't going to cure racism or poverty. Inversely, there's a lot of technology that isn't aimed at solving anything of social importance (a lot of which I'm an avid consumer of). There does exist a sweet spot where technology and social good do intersect (even if unintentional). I'm thinking of Periscope bringing instant awareness to police brutality. I'm thinking of Uber ensuring that getting a ride somewhere isn't harder based on the color of your skin. I'm thinking of computers/smartphones/etc decreasing paper wastage by orders of magnitude. It's a difficult goal, especially when aiming for the social impact to be a natural byproduct rather than a contrived attempt at charity; being a "byproduct" eliminates any procedural approach to ach

[
{
"lower": "250,000.01",
"upper": "251,000.00",
"sale": "1,655.00"
},
{
"lower": "251,000.01",
"upper": "252,000.00",
"sale": "1,660.00"

_sv2json

_sv2json is a simple tool to convert files delimited by certain characters/breaks into JSON files.

For example, it allows you to convert CSV or TSV (tab separated values) into JSON.

Usage

First, install _sv2json to your project:

@krrishd
krrishd / getRegistrants.js
Created November 8, 2014 04:20
Get the # of CodeDay registrants by pasting this into your console on Clear
(function getRegistrants() {
NodeList.prototype.forEach = Array.prototype.forEach;
registrants = 0;
document.querySelectorAll('.registrants .number').forEach(function(d) {
registrants += Number(d.innerHTML)
});
return registrants;
})();
@krrishd
krrishd / textToHTML.js
Last active August 29, 2015 14:07
Simple JS to convert a string of valid HTML to an HTMLDocument object (that you can interact with as you would with the DOM)
/* Usage:
* var html = '<!DOCTYPE html><html><head></head><body></body></html>';
* var htmlDocument = html.toHTML();
* HTMLDocument.prototype.isPrototypeOf(htmlDocument) => returns true
*/
String.prototype.toHTML = (function() {
function toHTML(str) {
var dom = new DOMParser();
var doc = dom.parseFromString(str, 'text/html');
@krrishd
krrishd / csv2json.js
Last active May 4, 2022 08:38
converting csv to json
var csv2json = (function() {
function convert(data) {
var json = [];
var d = data.split('\n');
var keys = d[0].split(',');
d = d.splice(1);
d.forEach(function(data) {
var keyVal = data.split(',');
var obj = {};
keys.forEach(function(keyData, n) {