Skip to content

Instantly share code, notes, and snippets.

const axios = require('axios').default;
let callCounter = {};
const displayCalls = () => {
console.log(callCounter);
};
function makeInterceptor(keyName, returns) {
callCounter[keyName] = 0;
return (r) => {
callCounter[keyName]++;
@barakplasma
barakplasma / hannukah-custom-elements.markdown
Created December 13, 2020 18:08
Hannukah Custom Elements
@barakplasma
barakplasma / hannukah-custom-elements.markdown
Created December 13, 2020 17:44
Hannukah Custom Elements
@barakplasma
barakplasma / hannukah-custom-elements.markdown
Created December 13, 2020 17:01
Hannukah Custom Elements
@barakplasma
barakplasma / script.js
Created December 13, 2020 15:39
Vanilla Menorah
class Candle extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: "open" });
const wrapper = document.createElement("span");
wrapper.setAttribute("class", "candle");
const candleFlicker = document.createElement("img");
candleFlicker.setAttribute(
@barakplasma
barakplasma / index.html
Created December 13, 2020 15:32
Menorah
<div class="menorah">
<candle-el lit></candle-el>
<candle-el lit></candle-el>
<candle-el lit></candle-el>
<candle-el></candle-el>
<candle-el lit shamesh></candle-el>
<candle-el></candle-el>
<candle-el></candle-el>
<candle-el></candle-el>
<candle-el></candle-el>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
@barakplasma
barakplasma / Keyboard shortcut for like button on tiktok.user.js
Last active October 9, 2020 07:42
Tampermonkey hit like on tiktok
// ==UserScript==
// @name Keyboard shortcut for like button on tiktok
// @namespace http://tampermonkey.net/
// @version 0.2
// @description hit "l" to like a video
// @author You
// @match https://www.tiktok.com/*
// @grant none
// ==/UserScript==
package main
import (
"fmt"
)
func main() {
fmt.Println(Divisors_simple(10)) // should equal 4
fmt.Println(Divisors_pointers(10)) // should equal 4
fmt.Println(Divisors_channels(10)) // should equal 4

We want to approximate the length of a curve representing a function y = f(x) with a <= x <= b. First, we split the interval [a, b] into n sub-intervals with widths h1, h2, ... , hn by defining points x1, x2 , ... , xn-1 between a and b. This defines points P0, P1, P2, ... , Pn on the curve whose x-coordinates are a, x1, x2 , ... , xn-1, b and y-coordinates f(a), f(x1), ..., f(xn-1), f(b) . By connecting these points, we obtain a polygonal path approximating the curve.

Our task is to approximate the length of a parabolic arc representing the curve y = x * x with x in the interval [0, 1]. We will take a common step h between the points xi: h1, h2, ... , hn = h = 1/n and we will consider the points P0, P1, P2, ... , Pn on the curve. The coordinates of each Pi are (xi, yi = xi * xi).

The function len_curve (or similar in other languages) takes n as parameter (number of sub-intervals) and returns the length of the curve. You can truncate it to 9 decimal places.