Skip to content

Instantly share code, notes, and snippets.

View tungd's full-sized avatar
🐳
Back to normal

Tung Dao tungd

🐳
Back to normal
View GitHub Profile
@tungd
tungd / copy-as-html-for-paste.el
Last active August 29, 2015 13:57
Copy region or buffer as HTML for paste (preserve styles)
;;; copy-as-html-for-paste.el
;;
;; I wanted some code highlighting to paste into Google Docs,
;; and people suggest `htmlize' the buffer, open the HTML file
;; in browser then copy-paste the content into the docs. This
;; works, but it is not pragmatic.
;;
;; Then I have free time after the lunch, I set out to really
;; understand the process. Emacs can do this, for sure, since Chrome
;; is already able to set rich clipboard, just need to figure out
@tungd
tungd / squaro.clj
Last active August 29, 2015 14:00
(ns logic-puzzle.core
(:refer-clojure :exclude [==])
(:require [clojure.core.logic :refer :all]))
(defn squaro [q]
(let [colors [:red :green :blue :yellow]]
(fresh [a1 a2 a3 a4
b1 b2 b3 b4]
(all
(permuteo colors [a1 a2 a3 a4])
@tungd
tungd / vc-git-extension.el
Created October 26, 2014 17:10
Some add-ons for vc-git.el. The code is mostly from: https://snarfed.org/emacs-vc-git-tweaks, I only added the `amend` command.
(use-package vc
:defer t
:config
(progn
(setq vc-follow-symlinks t)
(defun td/vc-git-command (verb fn)
(let* ((args (vc-deduce-fileset nil t))
(backend (car args))
(files (nth 1 args)))
@tungd
tungd / sml-tramp.txt
Created December 28, 2014 23:25
Smart Mode Line/Tramp profile. Open with `profiler-find-profile`.
[profiler-profile "24.3" cpu #s(hash-table size 730 test equal rehash-size 1.5 rehash-threshold 0.8 data ([nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil] 359 [tramp-dissect-file-name tramp-file-name-method string= tramp-smb-file-name-p tramp-find-foreign-file-name-handler tramp-file-name-handler file-name-directory ange-ftp-file-attributes apply byte-code ange-ftp-hook-function apply tramp-ftp-file-name-handler apply byte-code byte-code] 1 [byte-code ange-ftp-wait-not-busy ange-ftp-raw-send-cmd ange-ftp-send-cmd ange-ftp-file-modtime ange-ftp-file-attributes apply byte-code ange-ftp-hook-function apply tramp-ftp-file-name-handler apply byte-code byte-code tramp-file-name-handler file-attributes] 99 [byte-code ange-ftp-wait-not-busy ange-ftp-raw-send-cmd "#<compiled 0x411a05d1>" apply ange-ftp-call-cont ange-ftp-process-filter accept-process-output byte-code ange-ftp-wait-not-busy ange-ftp-raw-send-cmd ange-ftp-send-cmd ange-ftp-file-modtime ange-ftp-file-attributes apply byte-code] 112 [byte
@tungd
tungd / neocomplecache-snipmate.diff
Created March 5, 2011 16:06
Fix tab completion with Neocomplecache and SnipMate
diff --git a/plugin/snipMate.vim b/plugin/snipMate.vim
index ef03b12..b1738c6 100644
--- a/plugin/snipMate.vim
+++ b/plugin/snipMate.vim
@@ -159,8 +159,10 @@ fun! TriggerSnippet()
if exists('SuperTabKey')
call feedkeys(SuperTabKey) | return ''
endif
- call feedkeys("\<esc>a", 'n') " Close completion menu
- call feedkeys("\<tab>") | return ''
@tungd
tungd / extras_templatetags.py
Created September 1, 2011 16:33
Sample Cactus template tags support
from django import template
from django.utils.safestring import mark_safe
from django.utils.encoding import force_unicode
# pip install markdown
from markdown import markdown
register = template.Library()
class MarkdownNode(template.Node):
@tungd
tungd / symbol_table.c
Created September 20, 2011 13:35
Symbol table example
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define LEN 80
#define INIT_SIZE 30
typedef struct Entry {
void* key;
void* value;
@tungd
tungd / snippets_complete.diff
Created November 4, 2011 13:29
Fix neocomplcache snippet expand when gdefault is set
diff --git a/autoload/neocomplcache/sources/snippets_complete.vim b/autoload/neocomplcache/sources/snippets_complete.vim
index f229823..87e9cc7 100644
--- a/autoload/neocomplcache/sources/snippets_complete.vim
+++ b/autoload/neocomplcache/sources/snippets_complete.vim
@@ -528,7 +528,11 @@ function! s:expand_newline()"{{{
while match >= 0
let end = getline('.')[matchend(getline('.'), '<\\n>') :]
" Substitute CR.
- silent! s/<\\n>//
+ if &gdefault
@tungd
tungd / ch.vim
Created November 11, 2011 15:55
vim-ref ch source
" A ref source for ch. https://github.com/visionmedia/ch
" Version: 0.0.1
" Heavily based on man source by:
" Author : thinca <thinca+vim@gmail.com>
let s:save_cpo = &cpo
set cpo&vim
scriptencoding utf-8
@tungd
tungd / AATest.java
Created November 30, 2011 16:46
Antialias function plotting test
package com.tungd;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.Line2D;
import java.awt.geom.QuadCurve2D;
import javax.swing.JFrame;