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 / delayed_job-rails-4-upgrade-note.md
Last active December 18, 2015 22:49
delayed_job Rails 4 upgrade note

Code change

There was a proposal for an common queuing API for Rails, but was removed as of Rails 4 RC1 and will not be shipped with Rails 4 (FYI https://github.com/rails/rails/commit/f9da785d0b1b22317cfca25c15fb555e9016accb); so there is no change in term of code to user delayed_job in Rails 4.

Deployment change

However, in Rails 4, the script directory was renamed to bin (to update run rake rails:update:bin) so the command to run DelayedJob workers now is:

# Old

RAILS_ENV=production script/delayed_job start

@tungd
tungd / grizzl-completing-read.el
Last active December 19, 2015 16:09
Use `grizzl` as backend for `ido` (WIP)
;; Testing: `grizzl-ubiquitous`
(setq completing-read-function 'completing-read-grizzl)
(defun ->choices (coll pred)
"TODO: more consistence handle of `pred`"
(cond
((eq coll obarray) ;; obarray
smex-ido-cache)
@tungd
tungd / highlight-format-string-spec.el
Last active May 17, 2022 04:15
WIP Highlight `printf` format string specifier token. Used some code from: http://www.emacswiki.org/emacs/AddKeywords#toc7
(defvar font-lock-format-specifier-face
'font-lock-format-specifier-face)
(defface font-lock-format-specifier-face
'((t (:inherit font-lock-preprocessor-face)))
"Font Lock mode face used to highlight format specifiers."
:group 'font-lock-faces)
(defun highlight-format-specifier ()
(font-lock-add-keywords
@tungd
tungd / redir.go
Created October 28, 2013 03:43
Redir replacement written in Go
package main
import (
"net"
"flag"
"fmt"
"io"
"log"
)
@tungd
tungd / react-helper.js
Last active November 30, 2018 06:33
React Helper to initialize the component from HTML, similar to AngularJS.
/**
* react-helper.js
*
* Helper for Facebook's React UI Library. Add support for declare
* component on DOM (similar to AngularJS Directive).
*
* Usage:
* - Register a component:
* ReactHelper.register('MyComponent', MyComponent)
* - Declare the DOM node:
/**
* react-catalyst.js
*
* LinkedState for Facebook's React UI Library. Add support for
* deep path state access.
*
* Author: Tung Dao <[email protected]>
*
* Usage:
*
@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 / td_shortcode.php
Created July 2, 2014 13:38
Shortcode for Presestashop's CMS page.
<?php
if (!defined('_PS_VERSION_')) exit;
class TD_Shortcode extends Module {
protected static $initialized = false;
public function __construct() {
$this->name = 'td_shortcode';
$this->tab = 'front_office_feature';
@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)))