Skip to content

Instantly share code, notes, and snippets.

View hmarr's full-sized avatar
✌️

Harry Marr hmarr

✌️
View GitHub Profile
// Setup instructions
//
// Copy and paste into a Google Apps Script project. Make sure you set the source calendar id constant
// below. It should be set to the email address of the source calendar.
//
// Add a trigger to run the syncUpdatedEventsIncremental function the on the "Calendar - Changed" event
// of the source calendar.
//
// The first time you run this, you might want to select the "resyncEvents" function, and manually run
// it in the Apps Script editor.
@hmarr
hmarr / color-calendar-events.gs
Last active November 8, 2023 23:10
Google Apps Script to automatically color calendar events
// Setup instructions
//
// Copy and paste into a Google Apps Script project. Feel free to change the colors below.
//
// Add a trigger to run the colorUpdatedCalendarEvents function the on the "Calendar updated" event of
// your calendar.
const PERSONAL_COLOR = CalendarApp.EventColor.GRAY;
const IN_PERSON_COLOR = CalendarApp.EventColor.BLUE;
const EXTERNAL_COLOR = CalendarApp.EventColor.RED;
@hmarr
hmarr / tcping
Last active November 6, 2019 14:04
TCP ping in Ruby
#!/usr/bin/env ruby
require "socket"
require "timeout"
if ARGV.length < 2
puts "usage: tcping HOST PORT"
exit 1
end
@hmarr
hmarr / md
Last active December 16, 2015 15:09
Accept Github flavoured markdown on stdin, and render it in the browser
#!/usr/bin/env python
import sys
import urllib2
import json
import webbrowser
import BaseHTTPServer
import threading
markdown = sys.stdin.read()
@hmarr
hmarr / pg_read_only_config.md
Created October 29, 2015 12:02
Safely updating standard_conforming_strings - pg8.1 vs pg8.2

Postgres 8.1

$ ./bin/psql template1
Welcome to psql 8.1.4, the PostgreSQL interactive terminal.

Type:  \copyright for distribution terms
       \h for help with SQL commands
       \? for help with psql commands
       \g or terminate with semicolon to execute query
$ echo "source 'https://rubygems.org'\ngem 'rails', '4.2.0'" > Gemfile && bundle install
[truncated]
Using rails 4.2.0
Your bundle is complete!
It was installed into ./.bundle
$ bundle exec ruby routing_issue.rb
Run options: --seed 9548
# Running:
@hmarr
hmarr / pg-feistel-ids.sql
Last active March 30, 2020 13:45
Random-looking id generation in Postgres
CREATE OR REPLACE FUNCTION base32_encode(n bigint, min_width int DEFAULT 8) RETURNS text AS $$
DECLARE
alphabet CONSTANT text := '0123456789abcdefghjkmnpqrstvwxyz';
output text := '';
BEGIN
IF n < 0 THEN
RAISE EXCEPTION 'base32_encode called with negative value';
END IF;
WHILE n != 0 LOOP
@hmarr
hmarr / gist:c1def5eebf3f084ad775
Last active August 29, 2015 14:05
Google Cloud IO...
$ touch ${HOME}/foobar; time sync
real 0m2.956s
user 0m0.000s
sys 0m0.012s
$ touch ${HOME}/foobar; time sync
real 0m0.286s
user 0m0.000s
sys 0m0.004s
@hmarr
hmarr / life.rs
Last active August 29, 2015 14:03
Conway's Game of Life in Rust
use std::io::{print};
use std::cmp::{min,max};
use std::time::Duration;
#[deriving(Clone,Show,PartialEq)]
enum Cell {
Alive,
Dead,
}
@hmarr
hmarr / profile-after-patch.log
Created June 23, 2014 11:46
elasticsearch-ruby profile
Your Gemfile lists the gem elasticsearch-extensions (>= 0) more than once.
You should probably keep only one of them.
While it's not a problem now, it could cause errors if you change the version of just one of them later.
Starting 2 Elasticsearch nodes.............
--------------------------------------------------------------------------------
Cluster: elasticsearch_test
Status: green
Nodes: 2
+ node-2 | version: 1.1.1, pid: 79902, address: inet[/0:0:0:0:0:0:0:0%0:9251]
- node-1 | version: 1.1.1, pid: 79901, address: inet[/0:0:0:0:0:0:0:0:9250]