Skip to content

Instantly share code, notes, and snippets.

View lunaroyster's full-sized avatar

Arnav Bansal lunaroyster

View GitHub Profile
const isMounted = React.useRef(false);
React.useEffect(() => {
isMounted.current = true;
return () => {
isMounted.current = false;
};
}, []);
@prefix p: <http://example.org/person/> .
@prefix rel: <http://example.org/relation/> .
@prefix book: <http://example.org/book/> .
p:Nassim_Taleb rel:author book:The_Black_Swan,
book:Antifragile,
book:Skin_in_the_Game.
<http://example.org/person/Nassim_Taleb> <http://example.org/relation/author> <http://example.org/books/The_Black_Swan> .
<http://example.org/person/Nassim_Taleb> <http://example.org/relation/author> <http://example.org/books/Antifragile> .
<http://example.org/person/Nassim_Taleb> <http://example.org/relation/author> <http://example.org/books/Skin_in_the_Game> .
const fs = require('fs');
const path = require('path');
async function walk(dir) {
return new Promise((resolve, reject) => {
fs.readdir(dir, (error, files) => {
if (error) return reject(error);
Promise.all(files.map((file) => {
return new Promise((resolve, reject) => {
const filepath = path.join(dir, file);
// Paste into the console (F12)
(()=> {
let removeN = (element)=>{
if(!element.textContent) return;
element.textContent = element.textContent.split('n').join('');
element.textContent = element.textContent.split('N').join('');
}
let elements = [...document.body.children];
while(elements.length>0) {
@lunaroyster
lunaroyster / ExtensionsAndAnalytics.md
Last active February 16, 2018 18:06
Things to remember if you're writing an extension and trying to get Google Analytics working.
  • When setting up your Analytics property, you can pick any domain. You could go with example.org, if you don't have one.
  • There are multiple variants of Google Analytics scripts. You want to pick analytics.js: https://www.google-analytics.com/analytics.js
    Pick analytics.js
  • Add the domain to your content security policy in the manifest { "content_security_policy": "script-src 'self' https://www.google-analytics.com; object-src 'self'" }
  • This code works. It's intended for a background/event page:
    window.onload = ()=>{  
        window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;   

ga('create', 'UA--', 'auto');

@lunaroyster
lunaroyster / messageContent.md
Last active February 1, 2018 16:36
Select message content from copied messages.

Regex: /^\[.+] (.+): /gm

Original text:

[16:30, 2/1/2018] Sender 1 Name: <Message>
[16:31, 2/1/2018] Sender 2 Name: <Message>

Selection (delete this):

[16:30, 2/1/2018] Sender 1 Name:

// List all files in a directory in Node.js recursively in an asynchronous fashion
let walkAsync = async(dir, filelist)=> {
if( dir[dir.length-1] != '/') dir=dir.concat('/')
let fse = fse || require('fs-extra'),
files = await fse.readdir(dir);
filelist = filelist || [];
for (let file of files) {
if ((await fse.stat(dir + file)).isDirectory()) {
@lunaroyster
lunaroyster / Vector.js
Created November 25, 2017 19:37
A minimalist (amateur) implementation of 'Vector', along with cosineSimilarity
class Vector {
constructor(VectorArray) {
//TODO: Check things?
this._values = VectorArray;
}
toArray() {
return this._values;
}
get length() {
return this._values.length;
var cosineSimilarity = (A, B)=> {
let dotProduct = (a, b)=> {
if(a.length!=b.length) throw Error("Bad vector");
let sum = 0;
for(let i = 0; i<a.length; i++) {
sum+=(a[i]*b[i]);
}
return sum;
};
let magnitude = (a)=> {