Skip to content

Instantly share code, notes, and snippets.

Munge a form field into a multiple select (and back!)

This is a sample Drupal module that modifies an existing form field to display it as a multiple select without having to modify the handling code. As far as the form's "owner" is concerned, the user enters a comma-separated list of values.

The goal is, as you can probably tell from the $form_id, to turn a profile field into a multiple select of values from elsewhere. This is probably less than ideal, but I can't figure out a better way to achieve this.

@yyfrankyy
yyfrankyy / download_untar.sh
Created December 29, 2011 08:52
download from github's private repo
curl -sLk --user {username}:{password} https://github.com/{username}/{repo}/tarball/{tagname} | tar -xzf -
module TypeChecker where
type Vname = String
data Vexp = Var Vname
| Lambda Vname Vexp
| Ap Vexp Vexp
| Let [Vname] [Vexp] Vexp
| Letrec [Vname] [Vexp] Vexp
@dln
dln / inotify-cmake.sh
Created July 17, 2012 10:36
Continuous build on the cheap, using inotify, cmake and a terminal
#!/bin/bash
# Watch paths (given as arguments), automatically build when something changes.
# The script does a couple opinionated things to make my life easier:
#
# * Terminal scrollbuffer is reset before each iteration, simplifying scrolling.
# * I use a filter script to colorize gcc output (clang errors would be nicer).
# * Output is copied to a log file (/tmp/build.log).
# - I open this file in Sublime or vim, which reloads the file on change (each build).
#
# Usage:
@LegoStormtroopr
LegoStormtroopr / Example_use.txt
Created February 20, 2013 10:20
A demonstration of how to read Excel files using xlrd - http://www.lexicon.net/sjmachin/xlrd.htm
Using: http://www.abs.gov.au/ausstats/meisubs.NSF/log?openagent&634501.xls&6345.0&Time%20Series%20Spreadsheet&D22A58332C098EE7CA257B17000D3976&0&Dec%202012&20.02.2013&Latest
>>> data = abs.xlrdDemo('634501 (1).xls')
>>> print data.keys()
[u'Index', u'Data1', u'Inquiries']
>>> print data['Data1'][10,5]
64.7
>>> print data['Inquiries']
{(9, 1): u'I N Q U I R I E S', (3, 0): '', (8, 0): '', (2, 1): '', (5, 1): u'Table 1. Total Hourly Rates of Pay Excluding Bonuses: Sector, Original, Seasonally Adjusted and Trend', (4, 0): '', (9, 0): '', (8, 1): '', (11, 1): u'Referral Service on 1300 135 070 or Luci Burrage on Perth (08) 9360 5151.', (5, 0): '', (10, 0): '', (4, 1): u'6345.0 Wage Price Index, Australia', (1, 1): u'Time Series Workbook', (0, 0): '', (7, 1): '', (6, 0): '', (11, 0): '', (10, 1): u'For further information about these and related statistics, contact the National Information and', (1, 0): '', (0, 1): '', (7, 0): '', (6, 1): '', (3, 1): '', (2, 0): ''}
@NathanHowell
NathanHowell / curry.hs
Created May 31, 2013 23:36
A proof-of-concept demonstrating the use of Z3 to solve Cabal version constraints for Haskell packages
{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE StandaloneDeriving #-}
@pthariensflame
pthariensflame / IndexedCont.md
Last active April 3, 2022 00:30
An introduction to the indexed continuation monad in Haskell, Scala, and C#.

The Indexed Continuation Monad in Haskell, Scala, and C#

The indexed state monad is not the only indexed monad out there; it's not even the only useful one. In this tutorial, we will explore another indexed monad, this time one that encapsulates the full power of delimited continuations: the indexed continuation monad.

Motivation

The relationship between the indexed and regular state monads holds true as well for the indexed and regular continuation monads, but while the indexed state monad allows us to keep a state while changing its type in a type-safe way, the indexed continuation monad allows us to manipulate delimited continuations while the return type of the continuation block changes arbitrarily. This, unlike the regular continuation monad, allows us the full power of delimited continuations in a dynamic language like Scheme while still remaining completely statically typed.

@ncoghlan
ncoghlan / Crazy namespace, Python 2
Last active December 19, 2015 03:38
Python namespaces with side effects
>>> class Madness(dict):
... def __setitem__(self, attr, value):
... if isinstance(value, type):
... value.__name__ = attr
... dict.__setitem__(self, attr, value)
...
>>> code = """\
... class Example(object): pass
... NewName = Example
... print(Example.__name__)
@plentz
plentz / nginx.conf
Last active July 2, 2024 13:20
Best nginx configuration for improved security(and performance)
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
@saltednut
saltednut / ho-ho-ho.make
Last active December 31, 2015 16:48
CKEditor 4.3.1 & Latest Media for Drupal - Christmas 2013 Edition
projects[ckeditor][version] = "1.x-dev"
projects[ckeditor][type] = "module"
projects[ckeditor][subdir] = "contrib"
projects[ckeditor][download][type] = "git"
projects[ckeditor][download][revision] = "57245a9"
projects[ckeditor][download][branch] = "7.x-1.x"
; Integration with Media 2.x
; http://drupal.org/node/1504696
projects[ckeditor][patch][1504696] = "http://drupal.org/files/issues/ckeditor-accomodate-latest-media-changes-1504696-120.patch"
; External plugin declarations are redundant.