Skip to content

Instantly share code, notes, and snippets.

View yihong0618's full-sized avatar
🏃‍♂️
Running

yihong yihong0618

🏃‍♂️
Running
View GitHub Profile
@MartinThoma
MartinThoma / btree.py
Created July 22, 2012 13:30 — forked from teepark/btree.py
a pure-python B tree implementation
import bisect
import itertools
import operator
class _BNode(object):
__slots__ = ["tree", "contents", "children"]
def __init__(self, tree, contents=None, children=None):
self.tree = tree
self.contents = contents or []
@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active November 14, 2024 09:13
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@cobyism
cobyism / gh-pages-deploy.md
Last active November 11, 2024 00:02
Deploy to `gh-pages` from a `dist` folder on the master branch. Useful for use with [yeoman](http://yeoman.io).

Deploying a subfolder to GitHub Pages

Sometimes you want to have a subdirectory on the master branch be the root directory of a repository’s gh-pages branch. This is useful for things like sites developed with Yeoman, or if you have a Jekyll site contained in the master branch alongside the rest of your code.

For the sake of this example, let’s pretend the subfolder containing your site is named dist.

Step 1

Remove the dist directory from the project’s .gitignore file (it’s ignored by default by Yeoman).

@ramalho
ramalho / coro_life.py
Last active October 16, 2024 16:54
John Conway's Game of Life implemented with coroutines, by Brett Slatkin
#!/usr/bin/env python3
# Copyright 2014 Brett Slatkin, Pearson Education Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
@dabeaz
dabeaz / aecho.py
Last active October 17, 2023 03:26
Live-coded examples from my PyCon Brasil 2015 Keynote
# aecho.py
from socket import *
import asyncio
loop = asyncio.get_event_loop()
async def echo_server(address):
sock = socket(AF_INET, SOCK_STREAM)
sock.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
@claymcleod
claymcleod / pycurses.py
Last active October 13, 2024 16:45
Python curses example
import sys,os
import curses
def draw_menu(stdscr):
k = 0
cursor_x = 0
cursor_y = 0
# Clear and refresh the screen for a blank canvas
stdscr.clear()
# To print a str variable.
x/s ((PyStringObject*)str_var)->ob_sval
define ppstr
printf "%s\n", ((PyStringObject*)$arg0)->ob_sval
end
define ppr
printf "%s\n", ((PyStringObject*)PyObject_Repr($arg0))->ob_sval
end
@kofemann
kofemann / dcache-on-linux.md
Last active April 8, 2022 01:09
dtrace on linux

#Get started with DTrace on linux ####(with CentOS7/SL7/RHEL7)

  1. add YUM repo
$ cd /etc/yum.repos.d
$ wget http://public-yum.oracle.com/public-yum-ol7.repo
$ rpm --import http://public-yum.oracle.com/RPM-GPG-KEY-oracle-ol7
1980
1998
2000
2003
2004
2005
2006
2007
2008
2009
@niw
niw / fetch_nike_puls_all_activities.bash
Last active November 11, 2024 19:54
A simple NikePlus API description to fetch past run metrics
#!/usr/bin/env bash
# fetch_nike_puls_all_activities.bash
# A simple bash script to fetch all activities and metrics from NikePlus.
# See `nike_plus_api.md` for the API details.
readonly bearer_token="$1"
if [[ -z "$bearer_token" ]]; then
echo "Usage: $0 bearer_token"
exit