Skip to content

Instantly share code, notes, and snippets.

function convert_to(n, base) {
if (base < 2 || base > 16) {
throw new Error("Invalid base '" + base + "'. Base must be >= 2 or <= 16");
}
if (n === 0) {
return 0;
}
var length = Math.floor(Math.log10(n) / Math.log10(base)) + 1;
@lamchau
lamchau / git-metrics.py
Last active November 8, 2016 22:57
requested by management that judges productivity by PRs
#!/usr/bin/env python
import subprocess
import collections
import re
from prettytable import PrettyTable
from datetime import timedelta, date
from dateutil.parser import parse
from subprocess import PIPE, STDOUT
$pip_file = "requirements.txt"
try {
pip freeze > $pip_file
# PowerShell creates UTF16 LE with Windows line endings so we must convert
# for pip to consume
# http://stackoverflow.com/questions/8852682/convert-file-from-windows-to-unix-through-powershell-or-batch
Get-ChildItem $pip_file | ForEach-Object {
$contents = [IO.File]::ReadAllText($_) -replace "`r`n?", "`n"
export function deferredResolve(response, milliseconds = 250) {
milliseconds = _.isInteger(milliseconds) ? milliseconds : 0;
return new Ember.RSVP.Promise((resolve, reject) => {
Ember.run.later(() => {
resolve(response);
}, milliseconds);
});
}
export function deferredReject(response, milliseconds = 250) {
#!/usr/bin/env bash
buffers=($(tmux list-buffer | cut -f1 -d ":"))
for i in "${buffers[@]}"; do
tmux delete-buffer -b "$i"
done
@lamchau
lamchau / script.js
Last active March 7, 2016 08:25
wip: tamper-monkey script for package control
// bug https://packagecontrol.io/browse/popular
var parent = $("ul.packages");
var toggle_st3 = $('<label><input type="checkbox" style="-webkit-appearance:checkbox !important"/>&nbsp;Hide ST3</label>')
.click(function() {
var checked = $(this).find("input").is(":checked");
var versions = $(".versions").parent();
if (checked) {
versions.hide();
} else {
versions.show();
#!/usr/bin/env bats
load 'test_helper/bats-support/load'
load 'test_helper/bats-assert/load'
print_horizontal_rule () {
let width="$(tput cols)"
# echo -n '─' | hexdump -C
printf -v dash "%b" "\xe2\x94\x80" && printf "%*s\n" "$width" | sed "s/ /${dash}/g"
}
@lamchau
lamchau / colortrans.py
Created February 29, 2016 15:33 — forked from MicahElliott/colortrans.py
Convert values between RGB hex codes and xterm-256 color codes.
#! /usr/bin/env python
""" Convert values between RGB hex codes and xterm-256 color codes.
Nice long listing of all 256 colors and their codes. Useful for
developing console color themes, or even script output schemes.
Resources:
* http://en.wikipedia.org/wiki/8-bit_color
* http://en.wikipedia.org/wiki/ANSI_escape_code
@lamchau
lamchau / delete-dir.ps1
Created February 26, 2016 05:00
multithreaded large folder delete on windows
# for deleting large directories (e.g. node_modules)
function purge($target_dir) {
if (Test-Path -Path $target_dir) {
$uuid = [guid]::NewGuid().toString()
$empty_dir = "$env:temp$uuid.tmp"
New-Item -ItemType directory -Path $empty_dir | Out-Null
# delete using robocopy /NFL ... (options to suppress stdout)
robocopy $empty_dir $target_dir /MIR /MT | Out-Null
Remove-Item $empty_dir | Out-Null