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 / 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 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 / 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 / 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 / not_class.rb
Last active February 27, 2020 22:31
NotClass
class Object
def not
NotClass.new(self)
end
end
class NotClass < BasicObject
instance_methods.grep(/^[^_]/).each { |m| undef_method m }
def initialize(object)
@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';
@davidcelis
davidcelis / zelda-battery.sh
Created December 18, 2012 00:28
Output a Zelda-style heart meter for your MacBook's battery level. On the command line. Based on an idea from @stephencelis, executed by myself. For a tmux version, see https://gist.github.com/4324139
#!/usr/bin/env zsh
#
# Works best with blinking text; the last heart will blink
# when you have less than 25% of your battery life remaining.
BATTERY="$(pmset -g ps | awk 'NR==2' | perl -pe 's/.*?(\d+)%.*/\1/')"
if [[ $BATTERY -lt 25 ]]; then
echo "\e[5;31m♥\e[0;31m♡♡\e[0m"
elif [[ $BATTERY -lt 50 ]]; then
@davidcelis
davidcelis / pagination.rb
Created June 30, 2013 20:14
Consuming Link header pagination in Ruby
# Link: <http://example.com/resources?page=2>; rel="next", <http://example.com/resources?page=5>; rel="last"
links = {}
headers['Link'].split(',').each do |link|
link.strip!
parts = link.match(/<(.+)>; *rel="(.+)"/)
links[parts[2]] = parts[1]
end
@davidcelis
davidcelis / nginx.conf
Last active June 15, 2018 13:11
Nginx configuration to redirect HTTP traffic to HTTPS (Puma)
upstream puma {
server unix:///var/www/app/shared/tmp/sockets/puma.sock fail_timeout=0;
}
server {
listen 80 default deferred;
server_name example.com;
rewrite ^/(.+) https://example.com/$1 permanent;
}
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)