Skip to content

Instantly share code, notes, and snippets.

View sachac's full-sized avatar

Sacha Chua sachac

View GitHub Profile
(defun sacha/copy-code-as-org-block-and-gist (beg end)
  (interactive "r")
  (let ((filename (file-name-base))
        (mode (symbol-name major-mode))
        (contents
         (if (use-region-p) (buffer-substring beg end) (buffer-string)))
        (gist (if (use-region-p) (gist-region beg end) (gist-buffer))))
    (kill-new
     (format "\n[[%s][Gist: %s]]\n#+begin_src %s\n%s\n#+end_src\n"

(defun sacha/open-urls-in-region (beg end) “Open URLs between BEG and END.” (interactive “r”) (save-excursion (save-restriction (narrow-to-region beg end) (goto-char (point-min)) (while (re-search-forward org-plain-link-re nil t) (org-open-at-point)))))

**Getting started with Emacs? Empty your cup.**
Struggling with learning Emacs because you're just not as productive as you are with your old editor? Copying configuration snippets from the Web in order to force it to work like what you're used to, but running into problems with conflicting code or obscure error messages?
Here's something I've realized. To learn Emacs well, you need to empty your cup. This is the story as told on the [C2 wiki](http://c2.com/cgi/wiki?EmptyYourCup):
<blockquote>A master was trying to explain something to a student. Now this student was not a brand new student, but a senior student who had learned many things. He had knowledge and experience aplenty to draw upon. But each time the master tried to explain something new to the student, the student kept trying to hold it up against his own notions of the way the world is and how it ought be, and he was unable to see the lessons in what the master was trying to teach him.
Finally, the master poured a full serving of tea into his
/**
* Upload the file to my Flickr sketchbook and then moves it to
* Dropbox/Inbox/To blog. Save the Org Mode links in the clipboard. -
* means the photo already existed, + means it was uploaded.
*/
var async = require('async');
var cp = require('child_process');
var fs = require('fs');
var glob = require('glob');
@sachac
sachac / Sacha.el
Last active August 29, 2015 14:13
(defun sacha/copy-code-as-org-block-and-gist (beg end)
(interactive "r")
(let ((filename (file-name-base))
(mode (symbol-name major-mode))
(contents
(if (use-region-p) (buffer-substring beg end) (buffer-string)))
(gist (if (use-region-p) (gist-region beg end) (gist-buffer))))
(kill-new
(format "\n[[%s][Gist: %s]]\n#+begin_src %s\n%s\n#+end_src\n"
(oref (oref gist :data) :html-url) filename
# key: sbook
# name: Sketched Book
# --
**** TOSKETCH ${1:short title}
:PROPERTIES:
:TITLE: ${2:long title}
:SHORT_TITLE: $1
:AUTHOR: ${3:authors}
:YEAR: ${4:year}
var fs = require('fs');
var cheerio = require('cheerio');
/**
* Process specially-formatted blog post archive and extract image and post URL
*/
function extractInfo(article) {
var prettyLink = article.find("h2 a").attr("href");
var matches = article.find(".permalink a").attr("href").match(/p\/([0-9]+)/);
var postID = matches[1];
var secret = require('./secret');
var flickrOptions = secret.flickrOptions;
var Flickr = require("flickrapi");
var fs = require('fs');
/**
* Matches the image filenames in images.txt with the Flickr titles
* for images that don't yet have "Blogged" in their description.
*/
var fs = require('fs');
var cheerio = require('cheerio');
function extractInfo(article) {
var prettyLink = article.find("h2 a").attr("href");
var matches = article.find(".permalink a").attr("href").match(/p\/([0-9]+)/);
var postID = matches[1];
var title = article.find("h2").text();
var date = article.find(".date").attr("data-date");
return { prettyLink: prettyLink,