Skip to content

Instantly share code, notes, and snippets.

@leesei
leesei / prompt2.js
Last active December 22, 2015 17:18
#js #snippet #prompt2 Generic function that extends `window.prompt()`.
/**
`result = prompt2([prompt , options|default]);`
Generic function that extends `window.prompt()`.
If `options.validate()` is provided, this function will loop until the function return true on user's input.
Empty string (`''`) will be used instead of passing `undefined` for `prompt` and `default`.
If an non-Object is passed for options, it will be used as default value
(compatible with `window.prompt()`, no validation is performed). Use
@leesei
leesei / clone.sh
Created September 19, 2013 04:02
#bash #git repo manifest of cm42semc is broken, pull bluetooth related repo to Android tree structure
#/bin/bash
REPOS_PREFIX="https://github.com"
REPOS=( \
"cm42semc/android_build" \
"cm42semc/android_external_bluetooth_bluedroid" \
"cm42semc/android_external_bluetooth_bluez" \
"cm42semc/android_external_bluetooth_glib" \
"cm42semc/android_external_bluetooth_hcidump" \
@leesei
leesei / cd.bash
Last active December 23, 2015 13:09
#bash #cd 'cd' replacement function capable keeping up to 10 visited directories
# This function defines a 'cd' replacement function capable of keeping,
# displaying and accessing history of visited directories, up to 10 entries.
# To use it, uncomment it, source this file and try 'cd --'.
# acd_func 1.0.5, 10-nov-2004
# Petar Marinov, http:/geocities.com/h2428, this is public domain
cd_func ()
{
local x2 the_new_dir adir index
local -i cnt
@leesei
leesei / uri_parser.sh
Last active February 1, 2018 16:16
#bash #uri_parser bash uri parser
#!/bin/bash
#
# URI parsing function
#
# The function creates global variables with the parsed results.
# It returns 0 if parsing was successful or non-zero otherwise.
#
# [schema://][user[:password]@]host[:port][/path][?[arg1=val1]...][#fragment]
#
@leesei
leesei / openN
Last active December 25, 2015 21:39
#bash #openN open the N-th line of piped input
#!/bin/bash
[[ ${COLORS_SOURCE} ]] && source ${COLORS_SOURCE}
EXEC_CMD=
SCRIPT=$(basename $0)
_BSCRIPT=${_BLD}${SCRIPT}${_RST_}
function _help()
{
@leesei
leesei / powershell.reg
Created October 20, 2013 10:04
#powershell #registry #windows
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\powershell]
@="Open &PowerShell Here"
[HKEY_CLASSES_ROOT\Directory\shell\powershell\command]
@="C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%L'"
[HKEY_CLASSES_ROOT\Directory\Background\shell\powershell]
@="Open &PowerShell Here"
@leesei
leesei / sublime-text-3.reg
Created October 20, 2013 10:07
#sublime #registry #windows
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\sublime]
@="Open Folder as &Sublime Project"
[HKEY_CLASSES_ROOT\Directory\shell\sublime\command]
@="\"B:\\Program Files\\Sublime Text 3\\sublime_text.exe\" \"%1\""
[HKEY_CLASSES_ROOT\Directory\Background\shell\sublime]
@="Open Folder as &Sublime Project"
@leesei
leesei / notepad2.reg
Created October 20, 2013 10:07
#notepad2 #registry #windows
Windows Registry Editor Version 5.00
# replaces notepad
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe]
"Debugger"="\"B:\\Program Files\\Notepad2\\Notepad2.exe\" /z"
# context menu shortcut
[HKEY_CLASSES_ROOT\*\shell\Open with Notepad2]
@="Open with &Notepad2"
@leesei
leesei / path_parser
Created October 20, 2013 19:45
#bash #path_parser
#!/bin/bash
#
# path parsing function built purely from bash
# http://stackoverflow.com/a/18455930/665507
#
function path() {
SAVEIFS=$IFS; IFS="" # stash IFS for safe-keeping, etc.
[[ $# != 2 ]] && echo "usage: path <path> <dir|name|fullname|ext>" && return # demand 2 arguments
[[ $1 =~ ^(.*/)?(.+)?$ ]] && { # regex parse the path
@leesei
leesei / mdtoc.rb
Last active November 1, 2017 10:04 — forked from pyro2927/toc.rb
#ruby #markdown Generate TOC for markdown file
#!/usr/bin/env ruby
# sanity checks
if ARGV.count == 0
puts "You must provide a file name"
return
elsif File.exist?(ARGV.first) == false
puts "That file doesn't exist"
return
end