Skip to content

Instantly share code, notes, and snippets.

View jakiestfu's full-sized avatar
🌺

Jacob Kelley jakiestfu

🌺
View GitHub Profile
@jakiestfu
jakiestfu / index.js
Created May 17, 2024 17:25
Distinct Elements in Streams: An Algorithm for the (Text) Book
// Paper: https://arxiv.org/pdf/2301.10191
// Article: https://www.quantamagazine.org/computer-scientists-invent-an-efficient-new-way-to-count-20240516/
function generateRandomNumbers(c, n) {
let randomNumbers = new Array(c);
for (let i = 0; i < randomNumbers.length; i++) {
let randomNumber = Math.floor(Math.random() * (n + 1));
randomNumbers[i] = randomNumber;
}
return randomNumbers;
function trimSilenceFromBuffer(buffer, threshold = 0.001, minSilenceDuration = 0.1) {
const sampleRate = Tone.context.sampleRate;
const channelData = buffer.getChannelData(0); // Assuming mono audio for simplicity
let endOfAudioIndex = channelData.length - 1;
let silenceDuration = 0;
// Iterate backwards through the buffer
for (let i = channelData.length - 1; i >= 0; i--) {
const sample = Math.abs(channelData[i]); // Get the absolute value of the sample
{
"purchase": {
"id": "i-am-obfuscated",
"cart": {
"lineItems": [
{
"product": {
"sku": "i-am-sku",
"name": "hello world",
"unitPrice": 5,
import React from 'react'
import { compose } from 'redux'
import { connect } from 'react-redux'
import { addToCart } from '../actions'
import { fetchProducts } from '../decorators'
const mapDispatchToProps = (dispatch) => ({
add (product) {
dispatch(addToCart(product))
},
import { BrowserRouter as Router, Route } from 'react-router-dom'
import Upsell from './containers/Upsell'
import AddonsView from './components/AddonsView'
import ExtrasView from './components/Extras'
const Addons = Upsell({
view: AddonsView,
products: ['shave-butter', 'hair-gel', 'butt-wipes'],
})
import React from 'react'
import { compose } from 'redux'
import { connect } from 'react-redux'
import { addToCart } from '../actions'
import { fetchProducts } from '../decorators'
const mapDispatchToProps = (dispatch) => ({
add (product) {
dispatch(addToCart(product))
},
(function() {
// Shim with setTimeout fallback
window.requestAnimationFrame = function() {
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.msRequestAnimationFrame || window.oRequestAnimationFrame || function(f) {
window.setTimeout(f, 1e3 / 60)
}
}();
function num_between(n1, n2) {
import Ember from 'ember';
export default Ember.Component.extend({
classNames: ['foo', 'bar'],
isAwesome: true,
isNotAwesome: false,
});
import DS from 'ember-data';
export default DS.RESTAdapter.extend({
shouldReloadAll: function() {
return true;
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});