Skip to content

Instantly share code, notes, and snippets.

@jianyuan
jianyuan / keybase.md
Created August 8, 2023 10:40 — forked from sinewalker/keybase.md
How to import pub/sec PGP keys from keybase to your local GPG keyring.

Import Keybase PGP to GPG

After installing the keybase command-line tool onto a new / fresh computer, you may want to import your PGP key to the local keyring so that you may use the keys with GPG.

Import your PUBLIC PGP key:

keybase pgp export|gpg --import -
# Search term parser from https://gist.github.com/1477730
# Modified to allow periods (and other non-letter chars) in unquoted field values
# and field names.
#
# Helper class to help parse out more advanced saerch terms
# from a form query
#
# Note: all hash keys are downcased, so ID:10 == {'id' => 10}
# you can also access all keys with methods e.g.: terms.id = terms['id'] = 10
# this doesn't work with query as thats reserved for the left-over pieces

Scaling your API with rate limiters

The following are examples of the four types rate limiters discussed in the accompanying blog post. In the examples below I've used pseudocode-like Ruby, so if you're unfamiliar with Ruby you should be able to easily translate this approach to other languages. Complete examples in Ruby are also provided later in this gist.

In most cases you'll want all these examples to be classes, but I've used simple functions here to keep the code samples brief.

Request rate limiter

This uses a basic token bucket algorithm and relies on the fact that Redis scripts execute atomically. No other operations can run between fetching the count and writing the new count.

Keybase proof

I hereby claim:

  • I am jianyuan on github.
  • I am jianyuan (https://keybase.io/jianyuan) on keybase.
  • I have a public key ASDlhMh0dZKWgIPT_AHgpE5GLtw5VNbCZA3S0J8Q5Y4dGAo

To claim this, I am signing this object:

@jianyuan
jianyuan / ReflectionSugars.scala
Last active January 10, 2016 11:32 — forked from piotrga/gist:5928581
Scala 2.10 ReflectionSugars
trait ReflectionSugars{
import scala.reflect.runtime.{universe => ru}
private lazy val universeMirror = ru.runtimeMirror(getClass.getClassLoader)
def companionOf[T](implicit tt: ru.TypeTag[T]) = {
val companionMirror = universeMirror.reflectModule(ru.typeOf[T].typeSymbol.companionSymbol.asModule)
companionMirror.instance
}
}
@echo off
SET st2Path=C:\Program Files\Sublime Text 2\sublime_text.exe
rem add it for all file types
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 2" /t REG_SZ /v "" /d "Open with Sublime Text 2" /f
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 2" /t REG_EXPAND_SZ /v "Icon" /d "%st2Path%,0" /f
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 2\command" /t REG_SZ /v "" /d "%st2Path% \"%%1\"" /f
rem add it for folders
@reg add "HKEY_CLASSES_ROOT\Folder\shell\Open with Sublime Text 2" /t REG_SZ /v "" /d "Open with Sublime Text 2" /f
@jianyuan
jianyuan / scraper.rb
Created December 26, 2013 18:36
wallbase.cc scraper
require 'typhoeus'
require 'nokogiri'
require 'uri'
Typhoeus::Config.verbose = true
response = Typhoeus.get("http://wallbase.cc/toplist/index/?ts=1", headers: { 'X-Requested-With' => 'XMLHttpRequest' })
def download_wallpaper(wallpaper_url)
puts "Downloading #{wallpaper_url}"
@jianyuan
jianyuan / gist:8089508
Last active January 1, 2016 04:08
Setting up Ubuntu servers
# Copy my ssh public key to the server
ssh-copy-id root@<ip>
# Log into server
ssh root@<ip>
# Create new user
adduser app
usermod -a -G sudo app
su - app
@jianyuan
jianyuan / gist:2019410
Created March 12, 2012 02:49
MSoc Manifesto
class MSoc {
committee President;
committee Vice_President;
committee Secretary;
committee Treasurer;
committee Communications_Secretary;
committee Sports_Secretary;
committee Committee_Members[4];
};
# --------------------------------------------
# General
# --------------------------------------------
set :shared_children, %w(cache logs) # Shared directories, these directories contain generated content which should not be wiped out during deployments.
set :application, "domain.com" # Application name
set :deploy_to, "/var/www/#{application}/#{stage}" # Path where files are deployed to ...
# --------------------------------------------
# Server
# --------------------------------------------