Skip to content

Instantly share code, notes, and snippets.

View DanSnow's full-sized avatar

David Peng DanSnow

View GitHub Profile
@DanSnow
DanSnow / workspace_prev_or_focus_left.py
Last active July 3, 2019 11:40
[i3][Experimental] Focus left window if exists, or switch to previous workspace
#!/usr/bin/env python3
import subprocess
import json
def workspace_prev():
subprocess.run(["i3-msg", "workspace", "prev"])
@DanSnow
DanSnow / circle.yml
Created December 22, 2016 05:32
Use Crystal on CircleCI
machine:
environment:
CRYSTAL_VERSION: "0.20.1" # Replace version to which you're using
PATH: "${PATH}:${HOME}/.crystal/bin"
CRYSTAL_URL: "https://github.com/crystal-lang/crystal/releases/download/${CRYSTAL_VERSION}/crystal-${CRYSTAL_VERSION}-1-linux-x86_64.tar.gz"
dependencies:
cache_directories:
- ~/.crystal
- lib
- .shards
@DanSnow
DanSnow / dbus-wifi-connect.js
Last active December 10, 2016 10:37
DBus: Receive singal and get wifi SSID
import DBus from 'dbus'
import Promise from 'bluebird'
const dbus = new DBus()
const bus = dbus.getBus('system')
const NM_SERVICE = 'org.freedesktop.NetworkManager'
const NM_OBJECT = '/org/freedesktop/NetworkManager'
const NM_INTERFACE = NM_SERVICE
@DanSnow
DanSnow / jest-env.js
Created November 16, 2016 05:33
Wrapper for jasmine-immutable-matchers to make it work on jest > 17
import * as jasmineImmutable from 'jasmine-immutable-matchers'
import mapValues from 'lodash/mapValues'
const jestImmutable = mapValues(jasmineImmutable, (matcherFactory) => {
const matcher = matcherFactory()
return function () {
const { isNot } = this
const { pass, message } = matcher[isNot ? 'negativeCompare' : 'compare'](...arguments)
return {
pass: Boolean(pass),
@DanSnow
DanSnow / command-not-found.sh
Created November 18, 2015 01:45
Trollor your friend, make a command "command not found"
#!/bin/bash
# Usage: bash command-not-found.sh <command>
# Eample: bash command-not-found.sh ls
# Then if you type ls it will act like ls is not install.
if [[ -z $1 ]]; then
return
fi
current_shell="$(rev <<< "$SHELL" | cut -d '/' -f 1 | rev)"
@DanSnow
DanSnow / twd97_to_wgs84.rb
Created August 9, 2015 02:52
convert twd97 to wgs84
def convert(input_x, input_y)
dx = 250000
dy = 0
k0 = 0.9999
a = 6378137.0
b = 6356752.314245
e = (1 - b ** 2 / a ** 2) ** 0.5
lon0 = 121 * Math::PI / 180
x = input_x.to_f - dx
y = input_y.to_f - dy
@DanSnow
DanSnow / signal.hpp
Last active August 29, 2015 14:22
Like boost signal implement with c++11
#ifndef SIGNAL_HPP_INCLUDE
#define SIGNAL_HPP_INCLUDE
#include <functional>
template<typename Signature>
class Signal {
public:
typedef typename std::function<Signature> Function;
@DanSnow
DanSnow / nasm.vim
Created October 20, 2014 13:42
vim nasm indent
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
setlocal indentexpr=GetNasmIndent(v:lnum)
setlocal indentkeys+=<:>
if exists("*GetNasmIndent")
finish