Skip to content

Instantly share code, notes, and snippets.

CREATE TABLE 'AcademicSubjectAssociation' (
'login' char(40) NOT NULL default '',
'subject' char(7) NOT NULL default '',
'year' int(11) NOT NULL default '2000',
'semester' char(10) NOT NULL default 'autumn', /* enum('autumn','winter','spring','summer') NOT NULL default 'autumn', */
'association' char(10) NOT NULL default 'tutor', /*enum('coordinator','assessor','lecturer','tutor','liaison','marker','admin','markedit','other','listowner','proposer','propadmin') NOT NULL default 'tutor',*/
UNIQUE ('login','subject','year','semester','association')
);
CREATE INDEX 'asa_login2' ON 'AcademicSubjectAssociation' ('login','subject','year','semester');
CREATE INDEX 'asa_login3' ON 'AcademicSubjectAssociation' ('login','subject');
<?
....
//Build and load the design into an object
echo "Building staging design...";
chdir('../install/couchapp');
$ddocstr = shell_exec('couchapp push --export');
$ddoc = json_decode($ddocstr);
$ddoc_staging = clone $ddoc;
@MrTrick
MrTrick / gist:958570
Created May 6, 2011 07:42
Updating the design document without blocking other users
[minion@minion cgm]$ php tools/update_couch_design.php
Access granted.
Building staging design...done.
Uploading staging design...done.
Rebuilding all views (this may take a long time, you can track progress in the futon status window) ... done. Elapsed time: 12 seconds
Rebuilding lucene views (this may take a long time, too) ... done. Elapsed time: 8 seconds
Uploading production design...done.
Checking view signatures...done. Both signatures are: 7bfe586167ab93ee5c5320833b336201
Testing a production view (this should be immediate) ...done. Elapsed time: 0 seconds
Testing a production lucene view (this should be immediate) ...done. Elapsed time: 8 seconds
@MrTrick
MrTrick / gist:1011791
Created June 7, 2011 06:51
Mark Miller's sealer / unsealer code
function makeBrand() {
var key = {};
class Envelope(payload) {
protected const contents = payload;
function open(k) {
if (k === key) { return this.contents; }
}
}
return {
sealer: function(payload) { return new Envelope(payload); },
@MrTrick
MrTrick / gist:1064300
Created July 5, 2011 05:40
17x17 max solution
+V----------------+
| # # # <
| # # # # # ######|
| # # # # # |
| # # # # ########|
| # # # # # |
| # # # # # ######|
| # # # |
|######## ####### |
| |
<?
set_time_limit(0);
function usage($msg) {
echo $msg."\n";
echo "Usage: update_couch_design ADMIN_PASSWORD\n";
echo "Updates the configured couchdb database's design doc and views without blocking any other users.\n";
exit;
}
//Must run as a standalone script.
@MrTrick
MrTrick / *with* optimisation.c
Created July 19, 2011 03:48
AVRGCC Generated ASM code
if (PORTB&(1<<USER_SOL_PIN)) {
48e: c0 9b sbis 0x18, 0 ; 24
490: 02 c0 rjmp .+4 ; 0x496 <main+0x12>
PORTD|=(1<<UV_LAMP_PIN);
492: 97 9a sbi 0x12, 7 ; 18
PORTB&=~(1<<BW_PUMP_PIN);
494: c6 98 cbi 0x18, 6 ; 24
496: ff cf rjmp .-2 ; 0x496 <main+0x12>
Same code generated with macros:
<?
//Given MSA files, report for each the semesters.
array_shift($argv);
if (!$argv) $argv = array('php://stdin');
foreach ($argv as $file) {
$in = new SplFileObject($file, 'r');
$semesters = array();
foreach($in as $l)
if (preg_match('/\d{5}_([^_]+)_.*\|(\d{4})$/',$l,$m))
<?
...
$select = new Zend_Db_Select($db=Zend_Db_Table::getDefaultAdapter());
$select->from(array('a'=>'tutors_applicant_application'));
//Filter on area?
if (isset($query['area']) and $query['area']!='all') {
$area = $query['area'];
$select->where('area=?',$area);
}
@MrTrick
MrTrick / gist:1498931
Created December 19, 2011 21:21
Parallel Troll Circuit
http://www.youtube.com/watch?feature=player_embedded&v=OoPCDiMF108
1. In the battery or inside the battery plug, the current is converted to AC.
2. The LEDs are attached in opposite polarity, but are normal LEDs.
3. The switches are labelled in reverse - '0' is short, '1' is open.
4. Each switch has an internal diode in series, with the same polarity as their LED.
When both switches are '0':
Each switch conducts when the AC cycle forward-biases its diode, so the LED sees insufficient voltage (only 0.7V to light)