Skip to content

Instantly share code, notes, and snippets.

@nfeldman
nfeldman / dynamic_object.php
Created June 28, 2011 03:41
abusing magic methods to create an object just JS-esque enough to make you nostalgic, if you squint
<?php
/**
* Objects of this class are superficially similar to JavaScript objects
* in that you can dynamically add and overwrite both properties and methods
* the resemblance is not very strong, though.
*/
// Note, there are a few ways to pass functions around
// in arrays is one
// $F = array();
//
@nfeldman
nfeldman / jsObject.php
Created June 29, 2011 02:02
more magic method abuse, more JSesque than ever
<?php
/**
* Objects of this class are superficially similar to JavaScript objects.
While you can never have quite the simplicity of the object literal in PHP
you can get pretty close. We're going to duplicate these two variations in
PHP as closely as we can.
@nfeldman
nfeldman / gist:1057786
Created July 1, 2011 02:58
Utility script for use with Drupal Menus
/**
* Utility to add a className to the menu block menu item that would be the
* current node's parent, based on the url path.
* @param {array} cores, an array containing the 1st parts of url segments
* associated with individual menu blocks where the
* index maps to the id of the menu block such that
* for a[n] there will exist an element with the id
* block-menu_block-n.
* @author Noah Feldman
* @copyright 2011
@nfeldman
nfeldman / gist:1066284
Created July 6, 2011 00:30
CSS used in conjunction with markup checkup script
/** see https://gist.github.com/1066357 for full explanation
* This is mozilla only and was written to be used in conjunction with a greasemonkey script
* the many '!important' are only because I couldn't be sure how specific competing selectors
* were going to be.
*/
body { position: relative !important}
#container { padding-top: 20px !important }
#admin-menu { margin-top: 0 !important; top: 0 !important}
@nfeldman
nfeldman / gist:1066301
Created July 6, 2011 00:48
GreaseMonkey userscript to add a modal "front end" HTML editor to any node on a Drupal site
// ==UserScript==
// @name Front End Editor
// @namespace NSF
// @include http://the.devsite.com/*
// ==/UserScript==
/**
* @copyright 2011 Noah Feldman all rights reserved
* @author Noah Feldman
* @depends a good browser
@nfeldman
nfeldman / gist:1066357
Created July 6, 2011 01:41
markup checkup script
/**
* @copyright 2011 all rights reserved
* @author Noah Feldman
* This was originally written as a greasemonkey script and used to demonstrate to a vendor
* that the markup they'd delivered was worse than inadequate. In addition to being
* so inconsistent that their efforts to style it consistently resulted in bloated,
* unwieldy CSS, they'd also made it impossible to have any confidence in programatic
* manipulation of the documents returned. This file, coupled with a custom stylesheet
* <https://gist.github.com/gists/1066284> made the majority of issues painfully obvious.
* This is far from perfect, but it served its purpose and is useful enough that I
@nfeldman
nfeldman / gist:1072203
Created July 8, 2011 16:31
add/remove class from custom HTML Wibiya 'app' when media queries aren't supported
/**
* A quick and dirty function to apply a className to a custom html snippet
* in the Wibiya toolbar in browsers that do not support media queries, w/out
* bothering to learn the Wibiya API. Include before the closing </body> tag.
*
* Was written specifically to provide IE support for the following snippet
* of html and css:
*/
// <style type="text/css">
// @media screen and (max-width: 740px) {#wibiyaToolbar_support_key span { display:none; padding-left:60px;padding-right:0}}
@nfeldman
nfeldman / gist:1078998
Created July 12, 2011 21:15
short script written for vendor to enhance an complex interface
/**
* For the day job, pay it no mind
*/
(function () {
if (document.getElementById('quicktabs-5')) {
var faculty = $('.faculty-name'),
rootBlock = $('#block-block-12'),
nameOuter = rootBlock.find('> div > div').eq(0),
letters = {}, alpha = '', listItems = '', node,
@nfeldman
nfeldman / gist:1094268
Created July 20, 2011 03:25
javascript 4-bit adder simulator written for Rosetta Code
/**
* ************************************************
* Rosetta Code: Four-Bit Adder Simulation
* http://rosettacode.org/wiki/Four_bit_adder
* ************************************************
* The aim of this task is to "simulate" a four-bit adder "chip". This "chip"
* can be realized using four 1-bit full adders. Each of these 1-bit full
* adders can be with two half adders and an or gate. Finally a half adder can
* be made using a xor gate and an and gate. The xor gate can be made using two
* nots, two ands and one or.
@nfeldman
nfeldman / gist:1096342
Created July 21, 2011 01:46
My HTML5 Bare Template
<!doctype html>
<html lang="en">
<head>
<!--[if IE]><![endif]--> <!-- workaround for: phpied.com/conditional-comments-block-downloads/ -->
<title>UNTITLED</title>
<meta charset="utf-8">
<script>(function(a,c){var b=' ' + a[c] + ' ';a[c]?(b.indexOf('js') > -1 ||(a[c]+=' js'),b.indexOf('jsOff') > -1 ||(a[c]+=' jsOff')):a[c]="js jsOff",setTimeout(function(){a[c]=a[c].replace(/\s*?jsOff\s?/,'')},3e3)}(document.documentElement, 'className'))</script>
<meta name="author" content="Noah Feldman">