Skip to content

Instantly share code, notes, and snippets.

View tryggvigy's full-sized avatar
🌚
Web developer at Spotify working on Web Player and Desktop clients

Tryggvi Gylfason tryggvigy

🌚
Web developer at Spotify working on Web Player and Desktop clients
  • Spotify
  • Stockholm, Sweden
View GitHub Profile
@tryggvigy
tryggvigy / foo
Created August 11, 2021 21:17
Visualize git repo evolution with gource
gource --start-date '2019-01-01' -1280x720 --seconds-per-day 0.05 --auto-skip-seconds 0.5 --title "open/web-player" --dir-name-depth 2 --file-idle-time 0 --hide filenames --file-show-filter open/web-player,shared --output-ppm-stream - --output-framerate 30 --camera-mode overview --stop-at-end | ffmpeg -y -r 30 -f image2pipe -vcodec ppm -i - -b 65536K offline2.mp4
@tryggvigy
tryggvigy / app_scripts_cephes.js
Created May 4, 2020 13:52
Version of https://github.com/nearform/node-cephes that works standalone in Google Apps Script
const TOTAL_STACK = 1024 * 1024; // 1MB
const TOTAL_MEMORY = 2 * 1024 * 1024; // 1MB
const WASM_PAGE_SIZE = 64 * 1024; // Defined in WebAssembly specs
/**
* Implementation of atob() according to the HTML and Infra specs, except that
* instead of throwing INVALID_CHARACTER_ERR we return null.
*/
function atobb(data) {
// Web IDL requires DOMStrings to just be converted using ECMAScript
@tryggvigy
tryggvigy / react-virtualized-framerate-test.js
Last active June 24, 2020 22:10 — forked from bvaughn/react-virtualized-framerate-test.js
Quick demonstration of a way to measure scrolling performance for react-virtualized in an automated way
/** Measures framerate for the time between start() and stop() calls */
function FramerateMeasurer () {
this.start = () => {
this._beginTime = ( performance || Date ).now()
this._frames = 0
this._animationFrameId = requestAnimationFrame(this._loop)
}
this.stop = () => {
const endTime = ( performance || Date ).now()
@tryggvigy
tryggvigy / OnDemandLiveRegion.test.ts
Last active February 29, 2020 16:02
On demand live region
import { OnDemandLiveRegion } from './OnDemandLiveRegion';
describe('OnDemandLiveRegion', () => {
beforeEach(() => {
document.body.innerHTML = '';
jest.useFakeTimers();
});
test('works with defaults', () => {
const liveRegion = new OnDemandLiveRegion();
@tryggvigy
tryggvigy / autoCorrelation.diff
Last active July 25, 2019 19:40
autoCorrelation optimization
function autoCorrelation(arr) {
var ac = new Float32Array(2048);
for (var lag = 0; lag < arr.length; lag++) {
var value = 0;
for (var index = 0; index < arr.length - lag; index++) {
let a = arr[index];
- let b = arr[index-lag];
+ let otherindex = index - lag;
+ let b = otherindex >= 0 ? arr[index-lag] : 0;
value = value + a * b;
@tryggvigy
tryggvigy / withRetries.js
Last active March 6, 2020 18:18
Promise retries with exponential backoff
// paste this in any JS REPL to see the execution!
// Note that the fakeAPI is simulated to be flaky so try executin this a few times
// to see both the success and failure case
(() => {
/**
* Wrap a promise API with a function that will attempt the promise over and over again
* with exponential backoff until it resolves or reaches the maximum number of retries.
* - First retry: 500 ms + <random> ms
* - Second retry: 1000 ms + <random> ms
* - Third retry: 2000 ms + <random> ms
header.all: 'جميعها بجوار {0}'
header.popular: 'حفلات موسيقية شعبية بجوار {0}'
header.near_you: بجوارك
header.near_location: 'بجوار {0}'
@tryggvigy
tryggvigy / krass.js
Created January 10, 2018 23:33
Krass
const users = [<User name="Fannar"/>, <User name="Tryggvi"/>]
before
<div>
{users.map((user, index) => <User key={index} name={user.name} />)}
</div>
after
@tryggvigy
tryggvigy / main.js
Created January 9, 2018 21:24
More components!
import React, { Component } from 'react';
import data from '../../data/data'
import Header from './header';
import EducationList from './EducationList';
import SkillList from './SkillList';
class Main extends Component {
@tryggvigy
tryggvigy / Card.js
Created January 9, 2018 21:15
react bem
import React, { Component } from 'react';
class Card extends Component {
render() {
return (
<div className = "Card">
<div style= {{backgroundColor : this.props.color}}className = "Card__title-container">
<h6 className = "Card__title">