Skip to content

Instantly share code, notes, and snippets.

@basilleaf
basilleaf / gist:0bcb434d59cc7c874bb51b16072d9e15
Created July 23, 2021 17:28
search all git revisions, excluding some files
git rev-list --all | (
while read revision; do
git grep -F 'overrideNwayTestVariants' $revision | grep -v exclude_filename1.js | grep -v exclude_filename1.js;
done;
)
@basilleaf
basilleaf / load.js
Created February 10, 2021 21:07
loading images in background
// load in background js
const animatedGif = new Image()
animatedGif.src = animatedGifSrc
animatedGif.onload = () => {
this.setState({ mobileImgSrc: animatedGif.src })
}
// load via xhr
const xhr = new XMLHttpRequest()
@basilleaf
basilleaf / test.spec.js
Last active January 23, 2021 00:31
mock any browser event
// example for "scroll"
const simulateEvent = (eventType, e) => {
const listeners = window.addEventListener.mock.calls.filter((call) => call[0] === eventType).map((call) => call[1])
listeners.forEach((listener) => listener(e))
}
beforeEach(() => {
jest.spyOn(window, "addEventListener").mockImplementation(noop)
jest.spyOn(window, "removeEventListener").mockImplementation(noop)
})
@basilleaf
basilleaf / mobile_safari_height_adjust.jsx
Last active August 13, 2019 23:54
adjust window height to match mobile safari visible viewport height in React
# height adjust for mobile safari
# for when you sometimes need the window height to be the actual visible viewport
export default class MyComponent extends React.Component {
constructor(props) {
super(props)
this.state = {
height_adjust: 0,
}
https://flaviocopes.com/shell-environment-variables/
@basilleaf
basilleaf / json
Created October 4, 2018 22:58
Karabiner json config ~/.config/karabiner/karabiner.json
{
"global": {
"check_for_updates_on_startup": true,
"show_in_menu_bar": true,
"show_profile_name_in_menu_bar": false
},
"profiles": [
{
"complex_modifications": {
"parameters": {
<div id = "root"></div>
<ul style = "">
<li><img src="images_400x400/ESP_013368_1885.jpg"></li>
<li><img src="images_400x400/ESP_013954_1780.jpg"></li>
<li><img src="images_400x400/ESP_014185_1095.jpg"></li>
<li><img src="images_400x400/ESP_014351_1995.jpg"></li>
@basilleaf
basilleaf / index.html
Created July 10, 2018 04:38
Mars Globes
<script id="template" type="x-tmpl-mustache">
<section class="stage">
<figure class="ball"
style = "background: url('{{ imgUrl }}') repeat-x;"
><span class="shadow"></span></figure>
</section>
</script>
# equivilant of watch command on mac os
while :; do clear; ps 3277; sleep 2; done
@basilleaf
basilleaf / twitter_follow_unfollow.py
Last active March 3, 2018 19:13
twitter maintenance
"""
snippet for twitter bots, follow back all followers, unfollow unfollowers (with exceptions)
"""
import tweepy
from secrets import CONSUMER_KEY, CONSUMER_SECRET, ACCESS_KEY, ACCESS_SECRET
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)