Skip to content

Instantly share code, notes, and snippets.

@jboner
jboner / latency.txt
Last active July 17, 2024 03:12
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@paulirish
paulirish / gist:5558557
Last active April 18, 2024 14:32
a brief history of detecting local storage

A timeline of the last four years of detecting good old window.localStorage.


Jan Lenhart, bless his heart contributed the first patch for support:

October 2009: 5059daa

@andycjw
andycjw / uao_decode.py
Last active September 22, 2017 08:24
Big5 UAO decode usage: just do 'import uao_decode.py' unicode_string = big5_string.decode('uao_decode')
import codecs
import struct
class Codec(codecs.Codec):
def encode(self,input,errors='strict'):
pass
def decode(self,input,errors='strict'):
unistr = u''
@sfan5
sfan5 / mkapng.py
Last active May 28, 2016 21:13
Creates an APNG from PNGs (all PNGs need to have the same IHDR checksum for this to work)
#!/usr/bin/env python
import sys
import struct
import binascii
def mkchunk(tp, data):
return struct.pack("!L", len(data)) + tp + data + struct.pack("!L", binascii.crc32(tp + data) & 0xffffffff)
def getchunk(f, tp):
f.seek(0)
@pbastowski
pbastowski / README.md
Last active March 13, 2018 10:16
Brackets syntax coloring for AngularJS inline-templates

Brackets syntax coloring for AngularJS inline-templates

In the Brackets editor, have you noticed that the HTML within <SCRIPT type="text/ng-template"> is not syntax-colored? Here is how to fix it.

Background

AngularJS has support for inline HTML templates. I am going to explain here only how to get the syntax coloring working, not what inline-templates actually are. To create an inline-template, you put the template's HTML into a SCRIPT tag like this:

    <SCRIPT type="text/ng-template" id="/path/to/your/template.html">template: {{HTML}} here</SCRIPT>
from tkinter import *
import asyncio
from functools import wraps
import websockets
def runloop(func):
'''
This decorator converts a coroutine into a function which, when called,
runs the underlying coroutine to completion in the asyncio event loop.
'''
@rikukissa
rikukissa / POST.md
Last active June 12, 2024 02:39
Unit testing Angular.js app with node.js, mocha, angular-mocks and jsdom #angular.js #testing
title slug createdAt language preview
Unit testing Angular.js app with node.js, mocha, angular-mocks and jsdom
unit-testing-angular-js-app-with-node
2015-07-05T18:04:33Z
en
Majority of search result about unit testing Angular.js apps is about how to do it by using test frameworks that run the tests in a real browser. Even though it's great to be able to test your code in multiple platforms, in my opinion it creates a lot of boilerplate code and makes it hard to run the tests in, for instance a CI-server.

Testing Angular.js app headlessly with node.js + mocha

Lean unit tests with minimal setup

@paulirish
paulirish / what-forces-layout.md
Last active July 17, 2024 00:51
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent

@kangax's ES6 quiz, explained

@kangax created a new interesting quiz, this time devoted to ES6 (aka ES2015). I found this quiz very interesting and quite hard (made myself 3 mistakes on first pass).

Here we go with the explanations:

Question 1:
(function(x, f = () =&gt; x) {
@developit
developit / Rollup Automatic External Dependencies.md
Last active June 29, 2021 15:33
Rollup Automatic External Dependencies

Hi!

This is an example of how to use [Rollup] with external dependencies, without hard-coding them.

It reads your installed NPM dependencies and treats them as external to Rollup. They still get bundled, but not as ES2015.

Make sure you have a .babelrc or a "babel":{} section in your package.json.