Skip to content

Instantly share code, notes, and snippets.

View davidcelis's full-sized avatar
Verified account

David Celis davidcelis

Verified account
View GitHub Profile
@davidcelis
davidcelis / snowflake-id.sql
Last active November 6, 2022 00:58 — forked from beginor/snowflake-id.sql
Twitter Snowflake ID for PostgreSQL
CREATE SEQUENCE public.snowflake_id_seq;
ALTER SEQUENCE public.snowflake_id_seq OWNER TO postgres;
CREATE OR REPLACE FUNCTION public.snowflake_id()
RETURNS bigint
LANGUAGE 'plpgsql'
AS $BODY$
DECLARE
epoch bigint := 1288834974657;
seq_id bigint;
@davidcelis
davidcelis / README.md
Last active May 23, 2023 07:41
Watch for changes in a slow monorepo and update a `git status` cache for your prompt to read from 😬

A git prompt hack for the impatient amongst us

Maybe you have a big ol' monorepo, and git operations are pretty slow in it. For those of us who like to show information about the repository's dirty status in our prompt, that means a slow prompt. Waiting 1s every time you hit the return key can really add up! Instead of just giving up and eschewing the dirty status entirely, why not just cache it in the background have your prompt read from the cache?

Prerequisites

First, install fswatch:

brew install fswatch
@davidcelis
davidcelis / ariake-dark.js
Created May 25, 2019 20:55
A port of the Ariake Dark theme for Blink shell.
black = '#2a2d37';
red = '#85b1e0';
green = '#9aefea';
yellow = '#dda2f6';
blue = '#f5faff';
magenta = '#7e7edd';
cyan = '#4d8acb';
white = '#b9bed5';
lightBlack = '#2a2d37';
user system total real
Forwardable 0.170000 0.000000 0.170000 ( 0.167711)
Send 0.110000 0.000000 0.110000 ( 0.106545)
Simple call 0.070000 0.000000 0.070000 ( 0.070068)
@davidcelis
davidcelis / blame.graphql
Created December 6, 2016 19:28
An example GraphQL query to get `git blame` data from the GitHub GraphQL API
query {
repositoryOwner(login: "github") {
repository(name: "linguist") {
object(expression: "master") {
... on Commit {
blame(path: "github-linguist.gemspec") {
ranges {
startingLine
endingLine
age
@davidcelis
davidcelis / README.md
Last active April 18, 2016 23:14
I have a jpg in me

I have a JPG

$ ghi -vv show 273 -- stephencelis/ghi
===> GET /repos/stephencelis/ghi/issues/273
<=== 200: {
"url": "https://api.github.com/repos/stephencelis/ghi/issues/273",
"repository_url": "https://api.github.com/repos/stephencelis/ghi",
"labels_url": "https://api.github.com/repos/stephencelis/ghi/issues/273/labels{/name}",
"comments_url": "https://api.github.com/repos/stephencelis/ghi/issues/273/comments",
"events_url": "https://api.github.com/repos/stephencelis/ghi/issues/273/events",
"html_url": "https://github.com/stephencelis/ghi/issues/273",
"id": 129930467,
HOMEBREW_VERSION: 0.9.5
ORIGIN: https://github.com/Homebrew/homebrew
HEAD: 6db36f608fcb534a119ea229b33a95daae61ee6f
Last commit: 20 minutes ago
HOMEBREW_PREFIX: /usr/local
HOMEBREW_REPOSITORY: /usr/local
HOMEBREW_CELLAR: /usr/local/Cellar
HOMEBREW_BOTTLE_DOMAIN: https://homebrew.bintray.com
CPU: 8-core 64-bit haswell
OS X: 10.11.2-x86_64
@davidcelis
davidcelis / metronome.rb
Last active March 6, 2020 10:19
A simple metronome in Ruby
class Metronome
def self.start(bpm: 120)
loop do
print "\a"
sleep (60 / bpm.to_f)
end
rescue Interrupt
puts "Exiting."
end
end
@davidcelis
davidcelis / bad.rb
Last active August 29, 2015 14:19
Stop Validating Email Addresses With Regex
class User < ActiveRecord::Base
validates_format_of :email, :with => /^(|(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6})$/i
end