Skip to content

Instantly share code, notes, and snippets.

@davidsm
davidsm / kv
Created July 9, 2014 18:15
yasnippet for variable number of key-value pairs (concept shamefully stolen from https://github.com/capitaomorte/yasnippet/issues/348)
# -*- mode: snippet -*-
# name: keyvalue
# key: kv
# type: command
# --
(let ((yas-good-grace nil)
(count (* 2 (read-number "Number of elements: "))))
(yas-expand-snippet
(concat "{\n"
"\t"
## .tmux.conf
set -g status-bg default
set -g status-fg white
set -g status-left "#[fg=green]#H"
set-window-option -g window-status-current-bg blue
set -g status-interval 10
bind M-w run-shell "tmux save-buffer - | xclip -i"
@davidsm
davidsm / .emacs
Last active September 9, 2016 08:25
;; Useful stuff for .emacs
;;;;;
;; Key-bindings
;;;;;
(global-set-key (kbd "C-x C-b") 'ibuffer)
(global-set-key (kbd "C-c C-q") 'comment-or-uncomment-region)
;;;;;
@davidsm
davidsm / replace-all.el
Created July 24, 2015 07:10
Emacs string replace function that works on the entire buffer regardless of cursor position
(provide 'mystuff)
(defun replace-all (from to)
(interactive "sReplace: \nsWith: ")
(save-excursion
(goto-char (point-min))
(replace-string from to)
)
)
@davidsm
davidsm / ws.js
Created December 16, 2015 08:13
Simple wrapper for a Websocket connection that accepts and sends JSON data
exports.websocket = {
connect: function (address) {
var ws = new WebSocket(address);
var promise = new Promise(function (resolve, reject) {
ws.onopen = function (e) {
var wsObj = {
socket: ws,
handlers: {}
};
function counterstring(length) {
var curNum = length;
var outLen = 0;
var numbers = [];
var curStr;
while (outLen < length) {
curStr = curNum.toString() + "*";
curNum -= curStr.length;
if (outLen + curStr.length <= length) {
@davidsm
davidsm / Dockerfile
Created March 21, 2017 19:02
mysql-python
FROM alpine:latest
ENV MYSQL_CONNECTOR_VERSION 2.1.3
ENV MYSQL_CONNECTOR_ARCHIVE mysql-connector-python-${MYSQL_CONNECTOR_VERSION}.tar.gz
ENV MYSQL_KEYID 5072E1F5
COPY ${MYSQL_CONNECTOR_ARCHIVE}.asc ${MYSQL_CONNECTOR_ARCHIVE}.asc
RUN apk add --no-cache --virtual .deps curl mysql-dev gnupg file gcc python-dev musl-dev g++ && \
apk add --no-cache python && \