Skip to content

Instantly share code, notes, and snippets.

@jgornick
jgornick / gist:0b10798608193ba4fd6d
Last active January 5, 2024 00:02
Nginx: Advanced proxy_pass depending on file exists
server {
listen 443;
server_name my.domain.com;
root /var/www/my.domain.com;
ssl on;
ssl_certificate /usr/local/etc/ssl/star.crt;
ssl_certificate_key /usr/local/etc/ssl/star.key;
@jgornick
jgornick / configure-make-make-install.yaml
Last active June 8, 2023 16:13
Ansible: ./configure, make, make install
# This works
- name: Install unixODBC
command: sudo {{ item }} chdir="/tmp/{{ mysql_odbc_unixodbc_url | basename | replace('.tar.gz', '') }}"
with_items:
- ./configure --prefix=/usr/local
- make
- make install
# This _doesn't_ work
# Why doesn't the chdir option get recognized?
@jgornick
jgornick / gist:3786127
Created September 26, 2012 04:47
JavaScript: Parse multiple JSON documents from string
/**
* Parses a string containing one or multiple JSON encoded objects in the string.
* The result is always an array of objects.
*
* @param {String} data
* @return {Array}
*/
function parseJson(data) {
data = data.replace('\n', '', 'g');
@jgornick
jgornick / .bash_aliases
Last active March 22, 2023 10:13
Bash: Basic Bash Aliases
# List directory contents
alias sl=ls
alias ls='ls -lAF --color=auto'
alias la='ls -AF'
alias ll='ls -al'
alias l='ls -a'
alias l1='ls -1'
alias _="sudo"
@jgornick
jgornick / ping-test.sh
Created March 4, 2016 02:40
Shell (Bash): Ping test and log timestamps when ping fails.
#!/bin/bash
truncate /tmp/ping.log -s 0
while true; do
if ! ping -I ppp0 -s 8 -c 1 8.8.8.8 &> /dev/null; then
date --rfc-3339=ns | tee -a /tmp/ping.log &> /dev/null
fi
sleep 30
done
@jgornick
jgornick / helpers.sh
Last active March 22, 2023 10:10
Bash: Helper Functions
#!/bin/bash
# Returns a UTC timestamp of the current date/time.
# Can provide an optional format that matches date(1) format
now() {
local format="${1:-"%s"}"
echo -n "$(date -u +"$format")"
}
# Extract the first element of a list.
@jgornick
jgornick / countries.json
Created January 5, 2011 18:33
SQL: ISO 3166-1 Country Codes
{
"countries" : [
{
"code": "ZW",
"name": "Zimbabwe"
},
{
"code": "ZM",
"name": "Zambia"
},
@jgornick
jgornick / gist:323115
Created March 5, 2010 20:34
JS: Amortization Calculator
(function(global) {
// Sample Calculators:
// http://www.pine-grove.com/Web%20Calculators/interest.htm
var startingBalance = 10000.00,
totalBalance = startingBalance,
apr = (17.5 / 100),
months = 11,
interest,
customMonthlyPayment = 1000,
@jgornick
jgornick / storybook-ui-wrapper.tsx
Created November 22, 2022 15:19
React Native Storybook UI Wrapper - Support Deep Linking
const { getStorybookUI } = require('@storybook/react-native')
const React = require('react')
const { useEffect, useState } = require('react')
const { Linking } = require('react-native')
const { URL } = require('react-native-url-polyfill')
export const StorybookUIWrapper = () => {
const [config, setConfig] = useState()
const [url, setUrl] = useState()