Skip to content

Instantly share code, notes, and snippets.

@FranciscoG
FranciscoG / custom-keys-directive.js
Last active May 28, 2020
Vue custom directive that only allows certain keys to be typed into an element that accepts keyboard input
View custom-keys-directive.js
/**
* `v-kesAllowed` directive
*
* This works by blocking keys during onKeyDown by using a whitelist regex and
* testing `event.key`
*/
/**
* these keys should be allowed in all cases because they handle traversing and a11y
*/
@FranciscoG
FranciscoG / hashRouther.js
Created Mar 2, 2020
A super simple hash based router component. Does very basic route path matching
View hashRouther.js
import { Component } from "preact";
class Router extends Component {
constructor() {
super();
this.state = {
previousUrl: null,
currentRoute: window.location.hash.substring(1)
};
}
@FranciscoG
FranciscoG / adbrecord.sh
Last active Dec 13, 2019
Using adb to create screen recordings of all plugged in Android devices
View adbrecord.sh
#!/bin/bash
# TODO:
# - add option to change the time limit
# - add option to change the output folder
# - add option to delete recordings on device once they have been pulled
# - figure out how to kill script when everything is done
# how many seconds to record for
LIMIT=5
@FranciscoG
FranciscoG / convert.sh
Last active May 15, 2019
Convert Video to Image sequence using ffmpeg
View convert.sh
ffmpeg -i input.mov -r 0.25 output_%04d.png
# -i followed by video file sets input stream
# -r set framerat. 1 = 1 frame per second.
# and then set the output file with the number replacement
# more info: https://ffmpeg.org/ffmpeg.html#Main-options
# https://superuser.com/questions/135117/how-to-convert-video-to-images
@FranciscoG
FranciscoG / scrollIt.js
Created Nov 6, 2018
Vanilla JS scroll window to an element
View scrollIt.js
/**
* Source: https://pawelgrzybek.com/page-scroll-in-vanilla-javascript/
*/
function scrollIt(destination, duration = 200, easing = 'linear', callback) {
const easings = {
linear(t) {
return t;
},
View mb-explanation.md

mb explanation

source: https://github.com/burakcan/mb

var mb=p=>o=>p.map(c=>o=(o||{})[c])&&o

// in ES5:
var mb = function(pathArray) { 
  return function(obj) {  
    return pathArray.map(function(c) { 
@FranciscoG
FranciscoG / addSite.sh
Created Sep 20, 2018
Simple shell script to add a new site to my local macOS LAMP stack
View addSite.sh
#!/usr/bin/env bash
if [ "$EUID" -ne 0 ]
then echo "You must use sudo to run this script"
exit
fi
# Colors
# Black 0;30 Dark Gray 1;30
# Blue 0;34 Light Blue 1;34
@FranciscoG
FranciscoG / my-cheatsheet.md
Created Aug 17, 2018
bash and other terminal related things (heavily MacOS leaning)
View my-cheatsheet.md

TODO:

  • variables difference between $VAR and ${VAR}
  • find and replace in a file (sed, tr)
  • conditionals
  • loops
  • reading command line arguments
  • function arguments
  • exiting
@FranciscoG
FranciscoG / logger.js
Last active Jun 27, 2018
wrapper around all the console methods so you can turn enable/disable them.
View logger.js
(function(window){
"use strict";
/**
* Wrap console methods to turn them on/off with a flag
* Plus stub console methods for older browsers without console
*
* @param {boolean} debugFlag
*/
function Logger(debugFlag){
View displayZeroWidthChars.js
/*
Traverse through all the Text Nodes in a page and force them to display hidden characters
Sources:
Hacker news: https://news.ycombinator.com/item?id=16749422
user: tim333's js fiddle https://jsfiddle.net/tim333/np874wae/13/
medium post: https://medium.com/@umpox/be-careful-what-you-copy-invisibly-inserting-usernames-into-text-with-zero-width-characters-18b4e6f17b66
TODO:
You can’t perform that action at this time.