Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / AngularJS Provider Test Example
Last active February 6, 2018 17:59
Example of how you can test your AngularJS providers.
Look at the README.
@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)
}
}
@cesarandreu
cesarandreu / Gemfile
Created November 15, 2014 00:25
FakeS3 automation for rspec
# Make sure you have the fakes3 gem installed
group :test do
gem 'fakes3'
end
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