Skip to content

Instantly share code, notes, and snippets.

@cesarandreu
cesarandreu / youtubeSort.js
Created July 3, 2019 03:07
Sort the visible list of videos by views
function youtubeSort () {
const channel = document.querySelector('#channel-title').textContent
const videos = [...document.querySelectorAll('#items > ytd-grid-video-renderer')]
.map(item => {
const metadataLine = item.querySelector('#details #meta #metadata-line')
const metadataViews = metadataLine.querySelector(':nth-child(1)').textContent
const metadataDate = metadataLine.querySelector(':nth-child(2)').textContent
const videoTitle = item.querySelector('#details #meta #video-title')
@cesarandreu
cesarandreu / NegativeZeroExample.js
Created February 27, 2019 21:55
An example of a use-case for negative zero
// An example of a use-case for negative zero
const rtf = new Intl.RelativeTimeFormat('en')
rtf.format(0, 'hours') // 'in 0 hours'
rtf.format(-0, 'hours') // '0 hours ago'
@cesarandreu
cesarandreu / FinderUtils.js
Last active October 1, 2018 00:25
macOS JXA utilities
function getSelection () {
return Application('Finder')
.selection()
.map(item => urlToPath(item.url()))
.join('\n')
}
function getPath () {
const windows = Application('Finder').windows()
if (!windows.length) {
@cesarandreu
cesarandreu / README.md
Last active June 4, 2018 19:31
Resize the active Terminal.app window from the CLI

resize.js

This script lets you resize the active Terminal.app window from the CLI. If no values are specified it'll use the current profile's default size.

Usage

Set width and height:

$ resize 120 24
@cesarandreu
cesarandreu / sensible-defaults.css
Created June 2, 2018 10:04
Sensible css defaults taken from css-layout
div, span {
box-sizing: border-box;
position: relative;
display: flex;
flex-direction: column;
align-items: stretch;
flex-shrink: 0;
align-content: flex-start;
@cesarandreu
cesarandreu / GetSafariTabs.js
Created October 26, 2017 21:00
Get the list of tabs from the frontmost Safari window
const safari = Application('Safari')
const tabs = safari.windows[0].tabs
const list = []
for (let i = 0; i < tabs.length; i++) {
const url = tabs[i].url()
if (url) {
list.push(url)
}
}
test('the data is peanut butter', async () => {
expect(await fetchData()).toBe('peanut butter')
})
/* CommonJS */
// a.js
let a = 1
module.exports = { a }
setTimeout(() => {
a++
}, 100)
// index.js

Keybase proof

I hereby claim:

  • I am cesarandreu on github.
  • I am cesarandreu (https://keybase.io/cesarandreu) on keybase.
  • I have a public key whose fingerprint is 44EB E29B 4041 1369 E499 6BFA C658 4E40 36FC 188B

To claim this, I am signing this object:

import {
cond,
conformsTo,
constant,
eq,
flow,
get,
matches,
replace,
startsWith,