Skip to content

Instantly share code, notes, and snippets.

@johnpc
johnpc / App.js
Last active March 7, 2022 17:03
react-exec-and-stop
import {useState} from "react";
window.shouldStopCode = false;
function App() {
// move(); move();
const [workingCode, setWorkingCode] = useState("");
function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
@johnpc
johnpc / ExecComponent.js
Last active February 28, 2022 02:32
exec react component
import {useEffect, useState} from "react";
function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
const move = async () => {
console.log(`Moving at ${Date.now()}`);
await sleep(1000);
};
@johnpc
johnpc / bitcoin.learning.chaincode.py
Created September 1, 2021 20:23
A sample python script created for an exercise provided by https://learning.chaincode.com
#!/usr/bin/env python3
### This snippet is a fork of https://github.com/bitcoin/bitcoin/blob/master/test/functional/example_test.py
### It has been modified for an exercise provided by https://learning.chaincode.com
### Modifications begin on line 223
# Copyright (c) 2017-2020 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""An example functional test
@johnpc
johnpc / cloudSettings
Last active April 13, 2022 20:06
Visual Studio Code Settings Sync Gist
{"lastUpload":"2022-04-13T20:06:35.358Z","extensionVersion":"v3.4.3"}
@johnpc
johnpc / export_safari_passwords_to_csv.applescript
Created November 9, 2019 17:17
Export safari passwords to a CSV file
use AppleScript version "2.5" -- runs on 10.11 (El Capitan) and later
use scripting additions
set csv_filepath to (path to desktop as text) & "pm_export.csv"
set invokedBy to ""
tell application "System Events"
set invokedBy to get the name of the current application
end tell
@johnpc
johnpc / import_safari_passwords_from_csv.applescript
Last active November 9, 2019 17:18
Import safari passwords from csv
tell application "Safari"
activate
end tell
tell application "System Events" to tell application process "Safari"
set frontmost to true
keystroke "," using {command down}
set tb to toolbar 1 of window 1
set buttonName to (name of button 4 of tb as string)
click button 4 of tb
set theResult to display dialog "Please unlock " & buttonName & " and press Continue when unlocked" buttons {"Cancel", "Continue"} default button "Continue"
@johnpc
johnpc / antd-cascader-bug.js
Last active June 20, 2019 20:04
Antd Cascader bug
// Reproduce with the following steps:
// 1. npx create-react-app antd-bug
// 2. cd antd-bug
// 3. npm install antd && yarn add antd
// 4. copy this code into into src/index.js
// 5. npm start
// Navigate to localhost:3000
// Use the search box to search for "option". Use backspace and re-type. You will see lines get duplicated.
// Screen capture video available here: https://www.youtube.com/watch?v=bc9fT4T87ek
// Gif version available here: https://jpc.io/r/antd-bug.gif
@johnpc
johnpc / is_it_up.go
Created March 20, 2019 04:26
Very simple Go program to monitor uptime
package main
import (
"fmt"
"net/http"
"time"
)
func main() {
links := []string{
@johnpc
johnpc / keybase.md
Created February 2, 2019 16:08
Keybase Proof

Keybase proof

I hereby claim:

  • I am johnpc on github.
  • I am johncorser (https://keybase.io/johncorser) on keybase.
  • I have a public key ASCgRRcmi9jc4HSfYHspPxNENCMnbgdSE6ZczSYuLIRWlwo

To claim this, I am signing this object:

@johnpc
johnpc / Android GPS Cordova Plugin
Created October 1, 2014 15:10
This class determines whether android device has an location services (GPS) enabled, called from JavaScript using Cordova.
package org.apache.cordova.plugin;
import org.apache.cordova.api.CordovaPlugin;
import org.apache.cordova.api.PluginResult;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.location.LocationManager;