Skip to content

Instantly share code, notes, and snippets.

@DeanThompson
DeanThompson / ecb.go
Last active February 12, 2023 05:10
Golang AES ecb mode
package utils
import "crypto/cipher"
type ecb struct {
b cipher.Block
blockSize int
}
func newECB(b cipher.Block) *ecb {
@DeanThompson
DeanThompson / latlng_distance.go
Last active August 29, 2015 14:08
calculate distance in meters between two given location point
package main
import (
"math"
)
const (
RAD_FACTOR = math.Pi / 180.0
EARTH_RADIUS = 6371000
)
@DeanThompson
DeanThompson / defer_test.go
Created December 18, 2014 07:19
A simple test case to measure the additional time taken by defer in golang
package test
import (
"sync"
"testing"
)
type SyncedStruct struct {
a int
mutex sync.RWMutex
@DeanThompson
DeanThompson / youdao.py
Last active July 30, 2023 16:36
命令行版本的有道词典
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
命令行版本的有道词典,调用有道翻译的 API 实现
用法一:
% python youdao.py search
原文: search
发音: sɜːtʃ
@DeanThompson
DeanThompson / load_outfile.sql
Created July 20, 2015 06:28
Load data from outfile in mysql server.
LOAD DATA INFILE 'path/to/file.txt' REPLACE INTO TABLE tablename CHARACTER SET UTF8 FIELDS TERMINATED BY '|' IGNORE 1 LINES;
@DeanThompson
DeanThompson / haversine.py
Last active July 29, 2021 14:18
Haversine Formula in Python (Bearing and Distance between two GPS points)
from math import radians, cos, sin, asin, sqrt
def haversine(lon1, lat1, lon2, lat2):
"""
Calculate the great circle distance between two points
on the earth (specified in decimal degrees)
"""
# convert decimal degrees to radians
lon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2])
@DeanThompson
DeanThompson / setup_vim.sh
Last active August 31, 2016 03:37
Shell script to setup vim configure.
#!/bin/bash
cd ~
# Backup your own vim files.
mv .vim .vim.bak
mv .vimrc .vimrc.bak
# Clone this repository
git clone https://github.com/DeanThompson/vimfiles.git .vim
@DeanThompson
DeanThompson / install_gevent.sh
Created December 23, 2015 12:51
Command to install gevent using pip
CFLAGS='-std=c99' pip install gevent
#!/bin/sh
git filter-branch --env-filter '
OLD_EMAIL="[email protected]"
CORRECT_NAME="Your Correct Name"
CORRECT_EMAIL="[email protected]"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
#!/usr/bin/env python
import sys, os, time, atexit
from signal import SIGTERM
class Daemon:
"""
A generic daemon class.
Usage: subclass the Daemon class and override the run() method