Skip to content

Instantly share code, notes, and snippets.

Cesar Andreu cesarandreu

Block or report user

Report or block cesarandreu

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@cesarandreu
cesarandreu / youtubeSort.js
Created Jul 3, 2019
Sort the visible list of videos by views
View youtubeSort.js
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 Feb 27, 2019
An example of a use-case for negative zero
View NegativeZeroExample.js
// 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 Oct 1, 2018
macOS JXA utilities
View FinderUtils.js
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 Jun 4, 2018
Resize the active Terminal.app window from the CLI
View README.md

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 Jun 2, 2018
Sensible css defaults taken from css-layout
View sensible-defaults.css
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 Oct 26, 2017
Get the list of tabs from the frontmost Safari window
View GetSafariTabs.js
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)
}
}
View test.js
test('the data is peanut butter', async () => {
expect(await fetchData()).toBe('peanut butter')
})
View modules.js
/* CommonJS */
// a.js
let a = 1
module.exports = { a }
setTimeout(() => {
a++
}, 100)
// index.js
View keybase.md

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:

View MetricUtils.js
import {
cond,
conformsTo,
constant,
eq,
flow,
get,
matches,
replace,
startsWith,
You can’t perform that action at this time.