Skip to content

Instantly share code, notes, and snippets.

View johnteee's full-sized avatar

John Lee johnteee

  • Taipei
View GitHub Profile
@johnteee
johnteee / new_gist_file.js
Created September 12, 2019 08:40 — forked from nmsdvid/new_gist_file.js
Simple JavaScript Debounce Function
// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
// N milliseconds. If `immediate` is passed, trigger the function on the
// leading edge, instead of the trailing.
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
clearTimeout(timeout);
@johnteee
johnteee / timeout_and_tick.go
Created August 29, 2019 06:22 — forked from ngauthier/timeout_and_tick.go
Golang timeout and tick loop
// keepDoingSomething will keep trying to doSomething() until either
// we get a result from doSomething() or the timeout expires
func keepDoingSomething() (bool, error) {
timeout := time.After(5 * time.Second)
tick := time.Tick(500 * time.Millisecond)
// Keep trying until we're timed out or got a result or got an error
for {
select {
// Got a timeout! fail with a timeout error
case <-timeout:
@johnteee
johnteee / golang_job_queue.md
Created August 13, 2019 02:41 — forked from harlow/golang_job_queue.md
Job queues in Golang
@johnteee
johnteee / find-rls-preview.sh
Created June 16, 2019 15:50 — forked from MadratJerry/find-rls-preview.sh
Find the latest rust nightly version with rls-preview
#!/bin/bash
MAC=false
date -r "$now" +%Y-%m-%d &> /dev/null
if [ "$?" -ne "0" ]; then echo "LINUX"; MAC=false; else echo 'MAC'; MAC=true; fi
now=`date +%s`
while true
do
if [ "$MAC" == "true" ]; then data=`date -r "$now" +%Y-%m-%d`; else data=`date -d @"$now" +%Y-%m-%d`; fi
@johnteee
johnteee / nearby-coordinates.sql
Created May 10, 2019 06:20 — forked from statickidz/nearby-coordinates.sql
Ordering with SQL by nearest latitude & longitude coordinates (MySQL & SQLite)
---
METHOD 1
This should roughly sort the items on distance in MySQL, and should work in SQLite.
If you need to sort them preciser, you could try using the Pythagorean theorem (a^2 + b^2 = c^2) to get the exact distance.
---
SELECT *
FROM table
ORDER BY ((lat-$user_lat)*(lat-$user_lat)) + ((lng - $user_lng)*(lng - $user_lng)) ASC
// Add a 401 response interceptor
window.axios.interceptors.response.use(function (response) {
return response;
}, function (error) {
if (401 === error.response.status) {
swal({
title: "Session Expired",
text: "Your session has expired. Would you like to be redirected to the login page?",
type: "warning",
showCancelButton: true,
@johnteee
johnteee / curl.md
Created April 16, 2019 03:42 — forked from subfuzion/curl.md
curl POST examples

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.

@johnteee
johnteee / PageViewController.swift
Created April 7, 2019 03:52 — forked from miguelfermin/PageViewController.swift
Demonstrates how to add a UIPageViewController to a UIViewController
//
// ViewController.swift
// PageViewController
//
// Created by Miguel Fermin on 5/8/17.
// Copyright © 2017 MAF Software LLC. All rights reserved.
//
import UIKit
@johnteee
johnteee / server.js
Created January 15, 2019 10:03 — forked from bencentra/server.js
An HTTPS server for static content (Node.js)
/*
This module creates an HTTPS web server and serves static content
from a specified directory on a specified port.
To generate a new cert:
openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365
To remove the passphrase requirement:
@johnteee
johnteee / sampletokenSpec.rb
Created December 10, 2018 03:39 — forked from dallasjohnson/sampletokenSpec.rb
Unit Test for EOS.IO contracts using rspec
require 'rspec_command'
require "json"
# 1. A recent version of Ruby is required
# 2. Ensure the required gems are installed with `gem install rspec json rspec-command`
# 3. Run this from the command line with rspec sampletokenSpec.rb
# Optionally output the test results with -f [p|d|h] for required views of the test results.
# For debugging I added a clear action to the contract which clears everything in the tables