Skip to content

Instantly share code, notes, and snippets.

View craigs's full-sized avatar

Craig Sullivan craigs

  • Melbourne, Australia
  • 18:03 (UTC +11:00)
View GitHub Profile
@craigs
craigs / drop-all-tables.sql
Last active October 22, 2025 01:44
Drop all tables in a Postgres database
-- This script will generate drop statements for
-- all tables in a Postgres database
select 'drop table if exists "' || tablename || '" cascade;' as "statement"
from pg_tables
where schemaname = 'public'
order by "statement";
@craigs
craigs / create_uuid_generate_v7.sql
Last active October 20, 2025 23:44
Postgres uuid_generate_v7 function
CREATE OR REPLACE FUNCTION uuid_generate_v7() RETURNS uuid AS $$
DECLARE
unix_ts_ms bytea;
uuid_bytes bytea;
BEGIN
unix_ts_ms = substring(int8send((extract(epoch from clock_timestamp()) * 1000)::bigint) from 3);
uuid_bytes = uuid_send(gen_random_uuid());
uuid_bytes = overlay(uuid_bytes placing unix_ts_ms from 1 for 6);
uuid_bytes = set_bit(set_bit(uuid_bytes, 53, 1), 52, 1);
RETURN encode(uuid_bytes, 'hex')::uuid;

Keybase proof

I hereby claim:

  • I am craigs on github.
  • I am craigs0 (https://keybase.io/craigs0) on keybase.
  • I have a public key ASC3y-nEhSPlBBliP_ULEAIaig25p8ForNXYhJnjhiUxOQo

To claim this, I am signing this object:

@craigs
craigs / Placeholder for static images
Created March 27, 2020 03:31
Gist for stackblitz react-message-id-card
// static image in the comments
@craigs
craigs / launch.ly twitter cards snippet
Last active December 19, 2015 06:58
How to implement twitter cards for launch.ly
{% if items.size == 1 %}
{% if item.product? %}
<!-- twitter product card -->
<meta name="twitter:card" content="product">
<meta name="twitter:label1" content="Price">
<meta name="twitter:data1" content="{{ item.variants.first.price | currency_clean }}">
<meta name="twitter:label2" content="{{ item.variants.first.name_a }}">
<meta name="twitter:data2" content="{{ item.variants.first.name_b }}">
{% else %}
@craigs
craigs / chartbeat.js
Created November 4, 2010 08:51
Chart Beat Installation
<script type="text/javascript">var _sf_startpt=(new Date()).getTime()</script>
<script type="text/javascript">
var _sf_async_config={uid:12798,domain:"{{ current_account.domain }}"};
(function(){
function loadChartbeat() {
window._sf_endpt=(new Date()).getTime();
var e = document.createElement('script');
e.setAttribute('language', 'javascript');
e.setAttribute('type', 'text/javascript');
e.setAttribute('src',
@craigs
craigs / aus_post.rb
Created October 29, 2010 03:15
Australia Post's DRC rate calculator
# Interface to Australia Post's DRC rate calculator
#
# Merchant’s web site must display statements re DRC
# It is a condition of use of the DRC that certain statements are prominently displayed on the Merchant’s web site.
# These statements can be found at web site http://www.edeliver.com.au/Templates/ifs/IFS_DRC_Terms.htm in the section headed "Your representations".
class AusPost
AUSPOST_DRC_URL = "http://drc.edeliver.com.au/ratecalc.asp"