Skip to content

Instantly share code, notes, and snippets.

View alvinkatojr's full-sized avatar

Alvin Kato J.R. alvinkatojr

View GitHub Profile
@alvinkatojr
alvinkatojr / introrx.md
Created October 14, 2018 00:19 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
@alvinkatojr
alvinkatojr / postgres-cheatsheet.md
Created September 19, 2018 19:54 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h):

  • -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)
@alvinkatojr
alvinkatojr / submit.py
Created September 12, 2018 16:28 — forked from musabkilic/submit.py
Nand2Tetris Testing Script
# Copyright Musab Kilic 2018
# Special thanks to Noam Nisan and Shimon Schocken
# Course page: https://www.coursera.org/learn/build-a-computer/
#
# Usage: python submit.py [folder(0-6)/full]
# Example: python submit.py 0
# python submit.py full
from __future__ import division
import os
@alvinkatojr
alvinkatojr / compinit.zsh
Created September 4, 2018 00:55 — forked from ctechols/compinit.zsh
Speed up zsh compinit by only checking cache once a day.
# On slow systems, checking the cached .zcompdump file to see if it must be
# regenerated adds a noticable delay to zsh startup. This little hack restricts
# it to once a day. It should be pasted into your own completion file.
#
# The globbing is a little complicated here:
# - '#q' is an explicit glob qualifier that makes globbing work within zsh's [[ ]] construct.
# - 'N' makes the glob pattern evaluate to nothing when it doesn't match (rather than throw a globbing error)
# - '.' matches "regular files"
# - 'mh+24' matches files (or directories or whatever) that are older than 24 hours.
autoload -Uz compinit
@alvinkatojr
alvinkatojr / lastfm-remove-duplicates.js
Created July 23, 2018 20:57 — forked from sk22/lastfm-remove-duplicates.js
Last.fm duplicate scrobble deleter
var elements = Array.from(document.querySelectorAll('.js-link-block'))
elements.map(function (element) {
var nameElement = element.querySelector('.chartlist-name')
return nameElement && nameElement.textContent.replace(/\s+/g, ' ').trim()
}).forEach(function (name, i, names) {
if (name !== names[i + 1]) return
var deleteButton = elements[i].querySelector('[data-ajax-form-sets-state="deleted"]')
if (deleteButton) deleteButton.click()
location.reload()
})
@alvinkatojr
alvinkatojr / tutorial.md
Created July 20, 2018 18:32 — forked from swalkinshaw/tutorial.md
Designing a GraphQL API

Tutorial: Designing a GraphQL API

This tutorial was created by Shopify for internal purposes. We've created a public version of it since we think it's useful to anyone creating a GraphQL API.

It's based on lessons learned from creating and evolving production schemas at Shopify over almost 3 years. The tutorial has evolved and will continue to change in the future so nothing is set in stone.

require 'rbnacl'
require 'base64'
class Example
attr_reader :secret_box, :index_key
def initialize
key = RbNaCl::Random.random_bytes(RbNaCl::SecretBox.key_bytes)
@index_key = RbNaCl::Random.random_bytes(RbNaCl::SecretBox.key_bytes)
@secret_box = RbNaCl::SecretBox.new(key)
# Author: Pieter Noordhuis
# Description: Simple demo to showcase Redis PubSub with EventMachine
#
# Update 7 Oct 2010:
# - This example does *not* appear to work with Chrome >=6.0. Apparently,
# the WebSocket protocol implementation in the cramp gem does not work
# well with Chrome's (newer) WebSocket implementation.
#
# Requirements:
# - rubygems: eventmachine, thin, cramp, sinatra, yajl-ruby
@alvinkatojr
alvinkatojr / gist:41b4ed86476a6762a1dabde5d36c220d
Created May 16, 2018 01:33 — forked from mcsheffrey/gist:6718840
Init-Time Branching - JavaScript Patterns
// the interface
var utils = {
addListener: null,
removeListener: null
};
// the implementation
if (typeof window.addEventListener === 'function') {
utils.addListener = function (el, type, fn) {
el.addEventListener(type, fn, false);
Warden::Manager.serialize_into_session{|user| user.id }
Warden::Manager.serialize_from_session{|id| User.get(id) }
Warden::Manager.before_failure do |env,opts|
# Sinatra is very sensitive to the request method
# since authentication could fail on any type of method, we need
# to set it for the failure app so it is routed to the correct block
env['REQUEST_METHOD'] = "POST"
end