Skip to content

Instantly share code, notes, and snippets.

@j-
j- / measure-scrollbar.html
Created September 27, 2018 00:22
Easily measure scrollbar width and height
<div id="outer">
<div id="inner">
</div>
</div>
<style>
#outer {
width: 2em;
height: 2em;
overflow: scroll;
@j-
j- / spinner.css
Created September 26, 2018 07:06
Two concentric rotating circles
body {
font-size: 3em;
}
.spinner {
width: 1em;
height: 1em;
position: relative;
color: #09c;
}
@j-
j- / times.js
Created September 18, 2018 06:49
{
function pad (val) {
return (val < 10 ? '0' : '') + val;
}
function getTime (x) {
const h = Math.floor(x) || 12;
const m = Math.floor((x * 60) % 60);
const s = Math.floor((x * 360) % 60);
const mm = pad(m);
[
{
"availHeight": 1080,
"availLeft": 0,
"availTop": -1080,
"availWidth": 1920,
"colorDepth": 24,
"height": 1080,
"orientationAngle": 0,
"orientationType": "landscape-primary",

Separating state and presentation

  • Can migrate applications from one presentation layer (e.g. Angular) to another (e.g. React). Makes migrations less risky, since only the presentation is changing and you know the application logic will continue behaving the same way.

  • Can develop and test application logic independently of the UI. Makes new features quicker to implement since they are smaller changes to make to the app.

/**
* @example
*
* export interface ActionReceiveChatActionParticipantJoined extends Action {
* type: 'ReceiveChatActionParticipantJoined';
* data: {
* sessionId: string;
* result: string;
* entities: EntityMap<{
* actions: ChatActionParticipantJoined;
<!doctype html>
<meta charset="utf-8">
<title>CSS Attribute Selectors</title>
<form id="main">
<label for="html">HTML</label><br />
<textarea id="html" autocomplete="false" spellcheck="false">&lt;a href="/"&gt;Home&lt;/a&gt;</textarea><br />
@j-
j- / index.html
Created March 1, 2018 05:14
Fixed ratio element
<div class="outer">
<div class="middle">
<div class="inner">
Hello world
</div>
</div>
</div>
@j-
j- / main.js
Created February 20, 2018 00:57
Get full year from given month and date
/**
* Splits a string given in the format `31 Jan` into an array of `[0, 31]`.
*/
const parseMonthDate = (input) => {
const [dateString, monthString] = input.split(' ');
const date = Number(dateString);
switch (monthString) {
case 'Jan': return [0, date];
case 'Feb': return [1, date];
case 'Mar': return [2, date];
@j-
j- / expressions.js
Created March 9, 2017 05:20
Impossible Regular Expressions
/* These are regular expressions that will
never be matched by any string ever */
[
// http://stackoverflow.com/a/1845111
/$./,
// http://stackoverflow.com/a/1845097
/(?!x)x/,