Skip to content

Instantly share code, notes, and snippets.

View timhugh's full-sized avatar

Tim Heuett timhugh

View GitHub Profile
@hivehand
hivehand / qrenc-wifi
Last active May 17, 2024 18:09
Scriptlet for creating QR codes that let people join a WiFi network just by scanning the code.
#! /usr/bin/env ruby
# Take a network SSID as an argument, and prompt for the corresponding
# password. Generate a WiFi-network credential set suitable for QR
# encoding as defined in:
#
# https://github.com/zxing/zxing/wiki/Barcode-Contents#wi-fi-network-config-android-ios-11
#
# then generate that QR code and save it to `<SSID>-QR.png`.
#
@bradfitz
bradfitz / sqlplay.go
Created June 23, 2021 17:23
sqlplay.go
package main
import (
"database/sql"
"flag"
"fmt"
"html"
"io"
"io/ioutil"
"log"
@adam-hanna
adam-hanna / systemd-cloudwatch-logs-tutorial.md
Last active June 12, 2024 04:04
Forward systemd service logs to AWS Cloudwatch

Introduction

I often find myself ssh'ing into my servers and checking my systemd service logs with $ journalctl -f -u {name}.service. One day I got tired of this and wanted all of my important logs in once place (Amazon AWS Cloudwatch). To my dismay, there weren't any real good tutorials on how to do so. So, voilà.

Steps

Overall, it's a fairly simple process consisting of the following few steps.

1. Modify the service file

Open the service file with $ sudo vi /lib/systemd/system/{name}.service

Modify the [Service] section:

@simonmichael
simonmichael / envelope-budgeting.journal
Last active October 15, 2023 08:12
envelope budgeting example
; An example of YNAB-ish envelope budgetting with hledger/ledger
; cf https://github.com/simonmichael/hledger/issues/315
; Using accounts like the following:
;
; assets
; business
; bank
; wf
; bchecking
@need12648430
need12648430 / ago.py
Last active August 29, 2015 14:27
User friendly representation of times in 12 lines of Python.
def ago(elapsed):
o = []
for unit, size in [("yr",365*24*60*60),("mo",30*24*60*60),("wk",7*24*60*60),("d",24*60*60),("hr",60*60),("min",60),("sec",1)]:
if size > elapsed: continue
total = int(elapsed / size)
elapsed = elapsed % size
o.append(str(total) + unit)
@Kartones
Kartones / postgres-cheatsheet.md
Last active June 18, 2024 15:09
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
@schickling
schickling / Rakefile
Last active January 31, 2024 23:00
Activerecord without Rails
require "active_record"
namespace :db do
db_config = YAML::load(File.open('config/database.yml'))
db_config_admin = db_config.merge({'database' => 'postgres', 'schema_search_path' => 'public'})
desc "Create the database"
task :create do
ActiveRecord::Base.establish_connection(db_config_admin)
@willurd
willurd / web-servers.md
Last active June 21, 2024 13:36
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
@Chase-san
Chase-san / index.php
Last active December 12, 2015 02:18
A very tiny image gallery.
<?php /* Copyright(c) 2013 Robert Maupin. Released under the ZLIB License. */
if(count($_FILES) > 0) {
extract($_FILES['file']);
list($w,$h,$type)=getimagesize($tmp_name);
/*see exif-imagetype() documentation :) */
if(!$type||$type>3||filesize($tmp_name)>1024*200)
exit();
$ext=image_type_to_extension($type,false);
$md5=md5_file($tmp_name);
move_uploaded_file($tmp_name,$n="img/$md5.$ext");
@paneq
paneq / rails.rb
Created April 9, 2012 17:34
My fix for local database definition in rails
namespace :db do
def local_database?(config, &block)
if config['host'].in?(['127.0.0.1', 'localhost', '192.168.30.1']) || config['host'].blank?
yield
else
$stderr.puts "This task only modifies local databases. #{config['database']} is on a remote host."
end
end
end