Skip to content

Instantly share code, notes, and snippets.

View linktohack's full-sized avatar

Quang-Linh LE linktohack

View GitHub Profile
@linktohack
linktohack / *scratch*.el
Created April 20, 2015 17:20
emacs helper to open current file in Sublime Text and Lyx
(defun link/subl-file ()
"Edit current file in subl."
(interactive)
(shell-command (format "subl -n %s:%s"
(buffer-file-name)
(line-number-at-pos))))
(evil-define-operator link/subl-line (beg end type)
"Edit current region in subl."
:motion evil-line
(interactive "<R>")
@linktohack
linktohack / tangle.sh
Created April 28, 2015 14:23
Emacs tangle file command line
/opt/homebrew-cask/Caskroom/emacs-mac/emacs-24.5-z-mac-5.7/Emacs.app/Contents/MacOS/Emacs -Q --batch --eval "(progn (require 'org) (setq org-src-preserve-indentation t) (org-babel-tangle-file \"/Users/link/Dropbox/Researchs/Thesis/simple_thesis.org\"))"
;; Map CapsLock to LCtrl
;; LAtl to RCtrl
;; LCtrl to RAlt
;; using SharpKeys first
>^Tab::AltTab
>^q::Send, !{F4}
;; Not Emacs, not Console
#IfWinNotActive ahk_class Emacs
@linktohack
linktohack / .Xmodmap
Last active August 29, 2015 14:21
CapsLock as LCtrl, LCtrl as RAtl and LAlt as RCtrl
clear lock
clear control
clear mod1
clear mod4
! Caps_Lock
keycode 66 = Control_L
! Control_L
keycode 37 = Super_L
! Super_L
@linktohack
linktohack / subl.sh
Created May 28, 2015 14:36
subl for linuxmacs
#!/bin/sh
if [ $1 = "-" ]; then
shift
TEMP=$(mktemp)
cat > $TEMP
/opt/sublime_text/sublime_text -w $TEMP "$@"
cat $TEMP
rm -rf $TEMP
else
exec /opt/sublime_text/sublime_text "$@"
@linktohack
linktohack / waitFor.js
Created July 21, 2015 11:53
waitFor as a Promise
function waitFor(testFx, onReady, timeOutMillis) {
return new Promise(function (resolve, reject) {
var maxtimeOutMillis = timeOutMillis ? timeOutMillis : 3000,
start = new Date().getTime(),
condition = false,
interval = setInterval(function() {
if ((new Date().getTime() - start < maxtimeOutMillis) && !condition) {
condition = (typeof(testFx) === "string" ? eval(testFx) : testFx());
} else {
if(!condition) {
@linktohack
linktohack / promise.js
Last active August 29, 2015 14:25
Promise in 50 lines of code
var Promise = (function() {
var Promise = function(callback) {
this._done = [];
this._fail = [];
this.state = 'pending';
this.value = undefined;
callback && callback(this.resolve.bind(this), this.reject.bind(this));
};
Promise.prototype = {
resolve: function(value) {
@linktohack
linktohack / init.el
Created August 3, 2015 08:06
Helm in Popwin
(setq popwin:special-display-config
(append '(("^\*helm .+\*$" :regexp t :position right :width 60)
("^\*helm-.+\*$" :regexp t :position right :width 60))
popwin:special-display-config))
(add-hook 'helm-after-initialize-hook (lambda ()
(popwin:display-buffer helm-buffer t)
(popwin-mode -1)))
(add-hook 'helm-cleanup-hook (lambda () (popwin-mode 1)))
@linktohack
linktohack / lighttpd.conf
Created September 29, 2015 07:48
Lighttpd simple configuration
server.document-root = "/home/link/Downloads"
server.port = 3000
mimetype.assign = (
".html" => "text/html",
".txt" => "text/plain",
".jpg" => "image/jpeg",
".png" => "image/png"
)
@linktohack
linktohack / lastpass.sh
Created September 29, 2015 15:50
Another password manager
function lastpass () {
url=""
username=""
password=""
function fill() {
pb=$(pbpaste)
osascript -e 'tell application "System Events" to keystroke tab using command down'
echo "$username" | pbcopy
osascript -e 'tell application "System Events" to keystroke "v" using command down'
osascript -e 'tell application "System Events" to keystroke tab'