Skip to content

Instantly share code, notes, and snippets.

View peterbe's full-sized avatar

Peter Bengtsson peterbe

View GitHub Profile
@lahmatiy
lahmatiy / get-selector-parent.js
Created January 1, 2019 21:41
Get a selector parent selector with csstree (an issue https://twitter.com/peterbe/status/1079854825880326144)
const cssTree = require("css-tree@1.0.0-alpha.29");
function getSelectorParent(selector) {
const selectorAst = cssTree.parse(selector, { context: 'selector' });
// solution #1
selectorAst.children.prevUntil(selectorAst.children.tail, (node, item, list) => {
list.remove(item);
return node.type === 'Combinator' || node.type === 'WhiteSpace';
});
@DavidKuennen
DavidKuennen / minimal-analytics-snippet.js
Last active March 28, 2024 01:45
Minimal Analytics Snippet
(function (context, trackingId, options) {
const history = context.history;
const doc = document;
const nav = navigator || {};
const storage = localStorage;
const encode = encodeURIComponent;
const pushState = history.pushState;
const typeException = 'exception';
const generateId = () => Math.random().toString(36);
const getId = () => {
server {
root /Users/peterbe/dev/MOZILLA/BALROG/balrog-ui/dist;
server_name balrog.prod;
proxy_set_header Host $host;
location ^~ /api/ {
proxy_pass http://127.0.0.1:9000;
break;
}
@pstoica
pstoica / OnBlurComponent.jsx
Last active August 1, 2023 21:00
onBlur for entire react element
function OnBlurComponent({ onBlur }) {
const handleBlur = (e) => {
const currentTarget = e.currentTarget;
// Check the newly focused element in the next tick of the event loop
setTimeout(() => {
// Check if the new activeElement is a child of the original container
if (!currentTarget.contains(document.activeElement)) {
// You can invoke a callback or add custom logic here
onBlur();
@acdha
acdha / convert-subtitles.py
Last active July 29, 2016 19:39
Video caption conversion script using the PBS pycaption library
#!/usr/bin/env python
# encoding: utf-8
"""Convert caption files to different formats
One or more caption files will be converted to the specified output format, saved next to the input file
Requires the pycaption library from PBS: https://pypi.python.org/pypi/pycaption/
"""
from __future__ import absolute_import, print_function, unicode_literals