Skip to content

Instantly share code, notes, and snippets.

View lebensterben's full-sized avatar
🤌
Never half-ass two things, whole-ass one thing.

Lucius Hu lebensterben

🤌
Never half-ass two things, whole-ass one thing.
View GitHub Profile
@chrisdone
chrisdone / DBAPI.hs
Last active April 10, 2022 07:26
Defaulting fields in a record in Haskell
{-# LANGUAGE DataKinds #-}
-- | My database API.
module DBAPI where
import Data.Defaults
data ConnSpec p = ConnSpec
{ username :: !(Required p String)
# 1. Register an application with the Github API here https://github.com/settings/applications.
# Access the API to get information on your instructors repositories (hint: this is the url you want "https://api.github.com/users/jtleek/repos").
# Use this data to find the time that the datasharing repo was created. What time was it created?
# see https://medium.com/@GalarnykMichael/accessing-data-from-github-api-using-r-3633fb62cb08#.z0z07ph5h for more details.
#install.packages("jsonlite")
library(jsonlite)
#install.packages("httpuv")
library(httpuv)
#install.packages("httr")
@tiann
tiann / alfred-pinyin.py
Last active April 5, 2024 14:59
make alfred support pinyin search
#! /usr/bin/python
# -*- coding: utf-8 -*-
# @author weishu @2015/12/7
import subprocess
import os
import re
import json
@matthewmueller
matthewmueller / osx-for-hackers.sh
Last active April 21, 2024 03:30
OSX for Hackers (Mavericks/Yosemite)
# OSX for Hackers (Mavericks/Yosemite)
#
# Source: https://gist.github.com/brandonb927/3195465
#!/bin/sh
# Some things taken from here
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
# Ask for the administrator password upfront
@lifthrasiir
lifthrasiir / c11-to-rust.md
Last active September 16, 2021 13:30
C11 standard library to Rust standard library (as of 2014-07-19 nightly)

As a response to Issue #15753. Not yet complete.

Some notes:

  • All Rust translations assume the crate root (so the reference to std is freely available). The use of any other crates is noted.
  • Every string or vector argument is assumed to be a slice (&str or &[T]). Otherwise you need to convert String or Vec<T> to a slice with .as_slice() method.

<assert.h>

  • assert(cond): assert!(cond) macro. Note that it's always enabled; if you need to selectively disable the assertions, use debug_assert!(cond) macro.
@syzdek
syzdek / ipv6-regex-test.sh
Last active March 20, 2024 11:09
Simple script to test my IPv6 regular expression.
#!/bin/sh
#
# Use posixregex CLI tool from: https://github.com/syzdek/dmstools/blob/master/src/posixregex.c
RE_IPV4="((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])"
posixregex -r "^(${RE_IPV4})$" \
127.0.0.1 \
10.0.0.1 \
192.168.1.1 \
@dfalster
dfalster / addNewData.R
Last active February 19, 2023 00:29
The function addNewData.R modifies a data frame with a lookup table. This is useful where you want to supplement data loaded from file with other data, e.g. to add details, change treatment names, or similar. The function readNewData is also included. This function runs some checks on the new table to ensure it has correct variable names and val…
##' Modifies 'data' by adding new values supplied in newDataFileName
##'
##' newDataFileName is expected to have columns
##' c(lookupVariable,lookupValue,newVariable,newValue,source)
##'
##' Within the column 'newVariable', replace values that
##' match 'lookupValue' within column 'lookupVariable' with the value
##' newValue'. If 'lookupVariable' is NA, then replace *all* elements
##' of 'newVariable' with the value 'newValue'.
##'