Skip to content

Instantly share code, notes, and snippets.

@ivanalejandro0
ivanalejandro0 / counter.sh
Created October 18, 2019 14:59
Spawn and kill a bash script from js. Handle signal from bash.
#!/bin/bash
trap 'handle_signal SIGINT' SIGINT
trap 'handle_signal SIGQUIT' SIGQUIT
trap 'handle_signal SIGTERM' SIGTERM
trap 'handle_signal SIGHUP' SIGHUP
trap 'handle_signal SIGKILL' SIGKILL # we can't handle this
handle_signal() {
echo "received: $1. Exiting..."
@ivanalejandro0
ivanalejandro0 / use-query.js
Created July 8, 2019 17:58
Temporary useQuery hook implementation
/**
* React hook to execute an Apollo query and keep the data up to date according
* what's newest on the cache.
*
* @param { DocumentNode } query: the GraphQL query you want to run
* @param { Object } variables: the variables you want to interpolate on the query
* Note: you may want to memoize your object to prevent the query to run multiple times.
*
* Read more about param types on Apollo's watchQuery docs:
* https://www.apollographql.com/docs/react/api/apollo-client/#ApolloClient.watchQuery
@ivanalejandro0
ivanalejandro0 / notes.sh
Created October 22, 2018 21:09 — forked from junegunn/notes.sh
Managing notes with fzf
#!/usr/bin/env bash
#
# Managing notes with fzf (https://github.com/junegunn/fzf)
# - CTRL-L: List txt files in descending order by their modified time
# - CTRL-F: Search file contents
NOTE_DIR="${NOTE_DIR:-$(dirname "${BASH_SOURCE[0]}")}"
TRASH_DIR="$NOTE_DIR/trash"
export NORENAME=1
cd "$NOTE_DIR"
@ivanalejandro0
ivanalejandro0 / fetch-api-cancellation-test.js
Created July 26, 2018 19:00
A simple snippet on how to use the fetch cancellation api.
// For more information see:
// https://developers.google.com/web/updates/2017/09/abortable-fetch
// https://developer.mozilla.org/en-US/docs/Web/API/AbortController/abort
// https://caniuse.com/#search=fetch
const url = 'https://parrot.live';
const controller = new AbortController();
const signal = controller.signal;
@ivanalejandro0
ivanalejandro0 / toggle-mic-mute.applescript
Created January 25, 2018 17:44
Toggle mic mute on OSX
-- Thanks to:
-- https://coolaj86.com/articles/how-to-control-os-x-system-volume-with-applescript/
-- https://robservatory.com/silently-mute-the-mic-input-via-applescript/
-- https://macscripter.net/viewtopic.php?id=16588
--
-- For integration with the system see: http://eddmann.com/posts/creating-a-mac-microphone-mute-keyboard-shortcut/
--
-- In order to keep the `storedInputLevel` value you need to use it compiled:
-- $ osacompile -o toggle-mic.scpt toggle-mic.applescript
-- And then run:
@ivanalejandro0
ivanalejandro0 / test-react-antd-page.html
Created January 25, 2018 03:52
React + Ant Design single page/file example
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Hello World</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/antd/3.1.4/antd.css">
<script src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/[email protected]/babel.min.js"></script>
@ivanalejandro0
ivanalejandro0 / react-single-page-example.html
Created January 24, 2018 19:07
React single page example
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Hello World</title>
<script src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/[email protected]/babel.min.js"></script>
</head>
<body>
@ivanalejandro0
ivanalejandro0 / PackageApplication
Last active July 26, 2017 18:43
PackageApplication script from Xcode 8.2.1. This was removed on Xcode 8.3 and not handled yet by cordova, see https://stackoverflow.com/a/43935071
#!/usr/bin/perl
#
# PackageApplication
#
# Copyright (c) 2009-2012 Apple Inc. All rights reserved.
#
# Package an iPhone Application into an .ipa wrapper
#
use Pod::Usage;
@ivanalejandro0
ivanalejandro0 / clipboard.sh
Last active March 19, 2017 22:30
Multi platform clipboard helper
#!/bin/bash
# Credit:
# original idea from https://github.com/rfairburn
clipboard() {
case "${OSTYPE}" in
linux*)
if which xsel &>/dev/null; then
xsel --input --clipboard
@ivanalejandro0
ivanalejandro0 / copy-config.sh
Created August 10, 2016 22:52
PostgreSQL 9.5 script to run a dockerized psql locally.
#!/bin/sh
# file: docker-entrypoint-initdb.d/copy-config.sh
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cp $SCRIPT_DIR/postgresql.conf /var/lib/postgresql/data/postgresql.conf