Skip to content

Instantly share code, notes, and snippets.

@badri
badri / leanpub-preview.el
Created June 10, 2016 01:45
leanpub-preview
(defun leanpub-preview ()
"Generate a preview of your book @ Leanpub."
(interactive)
(request
"https://leanpub.com/<YOUR-BOOK-SLUG>/preview.json" ;; or better yet, get the book slug from the buffer
:type "POST" ;; and construct the URL
:data '(("api_key" . "53cr3t"))
:parser 'json-read
:success (function*
(lambda (&key data &allow-other-keys)
@badri
badri / leanpub-export.el
Created June 10, 2016 01:43
leanpub-export
(defun leanpub-export ()
"Export buffer to a Leanpub book."
(interactive)
(if (file-exists-p "./Book.txt")
(delete-file "./Book.txt"))
(if (file-exists-p "./Sample.txt")
(delete-file "./Sample.txt"))
(org-map-entries
(lambda ()
(let* ((level (nth 1 (org-heading-components)))
@badri
badri / field-info.txt
Created March 26, 2016 09:17
ascii table
|----------------+---------------------------------------------------------------------------------------------------------------------|
| id | field id |
| field_name | field machine name |
| type | field type |
| module | The module that implements this field |
| active | Whether the module above is enabled |
| storage_type | The storage backend for this field. This is almost always field_sql_storage |
| storage_module | The module that implements the storage backend
@badri
badri / py.py
Created March 8, 2016 09:56
ansible 2.0 run
#!/usr/bin/python2
from collections import namedtuple
from ansible.parsing.dataloader import DataLoader
from ansible.vars import VariableManager
from ansible.inventory import Inventory
from ansible.playbook.play import Play
from ansible.executor.task_queue_manager import TaskQueueManager
Options = namedtuple('Options', ['connection', 'module_path', 'forks', 'become', 'become_method', 'become_user', 'check', 'remote_user', 'private_key_file', 'ssh_common_args', 'sftp_extra_args', 'scp_extra_args', 'ssh_extra_args', 'verbosity'])
@badri
badri / Dockerfile
Last active March 8, 2016 07:18
buildpack doccker image
FROM progrium/cedarish:cedar14
RUN curl https://github.com/gliderlabs/herokuish/releases/download/v0.3.1/herokuish_0.3.1_linux_x86_64.tgz \
--silent -L | tar -xzC /bin
# install herokuish supported buildpacks and entrypoints
RUN /bin/herokuish buildpack install \
&& ln -s /bin/herokuish /build \
&& ln -s /bin/herokuish /start \
&& ln -s /bin/herokuish /exec
@badri
badri / decoupal.make.yaml
Created February 24, 2016 11:11
decoupal make yaml first cut
core: 7.x
api: '2'
projects:
drupal:
version: ~
cdn:
type: module
subdir: contrib
version: ~
WITH data AS(
select array_to_json(array_agg(row_to_json(t))) as data
from (
SELECT id, name, COALESCE(get_children(id), '[]') as children from genres
) t
) SELECT get_tree(data) from data;
CREATE OR REPLACE FUNCTION get_tree(data json) RETURNS json AS $$
var root = [];
for(var i in data) {
build_tree(data[i]['id'], data[i]['name'], data[i]['children']);
}
function build_tree(id, name, children) {
var exists = getObject(root, id);
CREATE OR REPLACE FUNCTION test_func(data json) RETURNS json AS $$
return JSON.stringify(data);
$$ LANGUAGE PLV8;
SELECT test_func('{"a": {"b":"foo"}}'::json);
test_func
-------------------
{"a":{"b":"foo"}}
[
{
"id": 1,
"name": "Arts & Photography",
"children": [
{
"id": 2,
"name": "Architecture",
"children": [