Skip to content

Instantly share code, notes, and snippets.

View leikahing's full-sized avatar
🧧
Chaining the blocks

William Lee leikahing

🧧
Chaining the blocks
View GitHub Profile
@leikahing
leikahing / wunderground.py
Created May 25, 2012 15:38
Weather Underground API usage
import json
import requests
key = '<your key goes here>'
# the following is the base URL for all API requests
base_url = 'http://api.wunderground.com/api/{0}/'.format(key)
location = '02169'
@leikahing
leikahing / gitlab_errors.md
Last active July 14, 2022 21:20
Examples of Gitlab errors

This is one form of the error JSON. The message field is mapped to a String.

{
    "message":"400 (Bad request) \"title\" not given"
}

The error JSON can also take a more general form:

{

@leikahing
leikahing / Dockerfile
Created June 22, 2022 17:58
Dockerfile for Facebook Detectron2
FROM nvidia/cuda:11.1.1-cudnn8-devel-centos8
RUN cd /etc/yum.repos.d/ && \
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-* && \
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-* && \
dnf check-update; dnf install -y ca-certificates python38 python38-devel git sudo which gcc-c++ mesa-libGL && \
dnf clean all
RUN alternatives --set python /usr/bin/python3 && alternatives --install /usr/bin/pip pip /usr/bin/pip3 1
@leikahing
leikahing / json-to-hash.ps1
Created December 14, 2016 16:21
JSON to Hashtable
$headers = @{}
$jsoncontent = Get-Content -Raw -path jsonfile.json | ConvertFrom-Json
$jsoncontent.psobject.properties | foreach { $headers[$_.Name] = $_.Value }
@leikahing
leikahing / find_java.fs
Created August 25, 2015 19:07
Finding Java in the registry using F#
let rec findWorkingJava registryKeys =
match registryKeys with
| [] -> ""
| x::xs ->
let value = Registry.GetValue(x, "JavaHome", String.Empty)
match value with
| null -> findWorkingJava xs
| _ -> value.ToString()
let findJavaInRegistry registryPath =
@leikahing
leikahing / gdb-trace.log
Created August 1, 2020 20:51
HHVM core debugging
// Hunting down an issue stemming from https://github.com/facebook/hhvm/blob/master/hphp/runtime/base/string-data.cpp#L84
(gdb) bt
#0 raise (sig=11) at ../sysdeps/unix/sysv/linux/raise.c:50
#1 0x00000000049eca29 in HPHP::bt_handler(int, siginfo_t*, void*) (sigin=<optimized out>, info=<optimized out>)
at hphp/runtime/base/crash-reporter.cpp:270
#2 0x00007faf1f091b80 in <signal handler called> () at /usr/local/fbcode/platform007/lib/libpthread.so.0
#3 0x00000000008ecc55 in HPHP::StringData::MakeShared<true>(folly::Range<char const*>) (sl=...)
at buck-out/opt-hhvm-lto/gen/hphp/runtime/headers#header-mode-symlink-tree-only,headers,v5c9e8e3/hphp/runtime/base/header-
kind.h:233
@leikahing
leikahing / migratool.clj
Created February 21, 2018 18:45
A really quick Clojure program that validates the existence of files in S3
(ns migratool.core
(:gen-class)
(:require [clojure.string :as string]
[amazonica.core :refer :all]
[amazonica.aws.s3 :as s3]
[com.climate.claypoole :as cp]))
(def access-key "")
(def secret-key "")
(def bucket "")
@leikahing
leikahing / project.clj
Created January 7, 2018 17:01
project.clj
(defproject crane "1.0.0"
:description "High-throughput s3+dynamodb data crane"
:url "https://example.com"
:min-lein-version "2.0.0"
:dependencies [[org.clojure/clojure "1.8.0"]
[org.clojure/tools.logging "0.4.0"]
[ch.qos.logback/logback-classic "1.2.3"]
[amazonica "0.3.117"]
[cheshire "5.8.0"]
[compojure "1.6.0"]
@leikahing
leikahing / depth_sum.py
Last active October 31, 2017 18:42
Nested list summation
def depthSum(nestedList):
"""
:type nestedList: List[Things] where Things can be an int or more List[Things]
:rtype: int
"""
# This is a depth-first search as we need to find the deepest level and return sum
# at each depth
return dfs(nestedList, 1)
@leikahing
leikahing / heap.py
Created October 30, 2017 14:48
A really basic Heap implementation
class MaxHeap(object):
def __init__(self):
self.data = [0]
self.size = 0
def left_child(self, index):
if 2 * index <= self.size:
return 2*index
return None