New Styleized Photo's
I was playing around with some pictures from my trip to Denver last month and posted some new stylized photo's on my flicker page. Check them out here. The original photos are also available here.
This is my personal blog and mainly contains technical solutions, open source code, and other projects I have worked on. Much of the technical solutions are very niche so your milage may vary.
web-history.js
makeSearchCommand({
name: "web-history",
homepage: "http://pynej.blogspot.com/",
author: { name: "Jeremy Pyne", email: "jeremy.pyne@gmail.com"},
url: "http://www.google.com/history/find?q={QUERY}",
icon: "http://www.google.com/favicon.ico",
description: "Searches Google Web History."
});
about_config.js
CmdUtils.CreateCommand({
name: "about_config",
homepage: "http://pynej.blogspot.com/",
author: { name: "Jeremy Pyne", email: "jeremy.pyne@gmail.com"},
description: "Open the firefox about:config page.",
execute: function() {
Utils.openUrlInBrowser("about:config");
}
})
open_in_new_tab.js
CmdUtils.CreateCommand({
name: "open_in_new_tab",
homepage: "http://pynej.blogspot.com/",
author: { name: "Jeremy Pyne", email: "jeremy.pyne@gmail.com"},
description: "Open the selected url in a new tab.",
takes: {"URL": noun_type_url},
preview: function( pblock, url ) {
pblock.innerHTML = "Will open: " + url.text;
},
execute: function( url ) {
Utils.openUrlInBrowser(url.text);
}
})
note-in-reader.js
CmdUtils.CreateCommand({
name: ["note-in-reader", "add-to-reader", "share-to-reader"],
homepage: "http://pynej.blogspot.com/",
author: { name: "Jeremy Pyne", email: "jeremy.pyne@gmail.com"},
description: "Note this page in Google Reader.",
arguments: [ {role: 'object', nountype: noun_arb_text, label: 'note'} ],
execute: function( note ) {
var document = Application.activeWindow.activeTab.document;
var gc = "var b=document.body;var GR________bookmarklet_domain='https://www.google.com';if(b&&!document.xmlVersion){void(z=document.createElement('script'));void(z.src='https://www.google.com/reader/ui/link-bookmarklet.js');void(b.appendChild(z));}else{}";
void(z=document.createElement('script'));
z.appendChild(document.createTextNode(gc));
document.body.appendChild(z);
if(note.text)
{
var timer = Components.classes["@mozilla.org/timer;1"]
.createInstance(Components.interfaces.nsITimer);
timer.initWithCallback(
function() {
document.getElementById("GR________link_bookmarklet_frame").contentDocument.getElementById("annotation").innerHTML= note.text;
},
1500,
Components.interfaces.nsITimer.TYPE_ONE_SHOT);
}
}
})
rm ~/Library/Mail/IMAP-*/.OfflineCache/*
private const myGroups:ArrayCollection = new ArrayCollection(
[{groupid: 1, name: "Admin"},
{groupid: 2, name: "User"},
{groupid: 3, name: "Guest"}]);
<mx:DataGrid dataProvider="{}">
<mx:columns>
<mx:DataGridColumn headerText="User Name" dataField="username"/>
<LookupColumn headerText="Group" dataField="groupid" labelField="name" source="{myGroups}"/>
</mx:columns>
</mx:DataGrid>
LookupColumn.as
package hines
{
import flash.events.Event;
import mx.collections.ArrayCollection;
import mx.controls.dataGridClasses.DataGridColumn;
[Exclude(name="dataTipField", kind="property")]
/**
* This class is a custom DataGridColumn taht will look up each item in another array and fill in a field from the found item in its place.
*
* Example:
* private const myGroups:ArrayCollection = new ArrayCollection(
* [{groupid: 1, name: "Admin"},
* {groupid: 2, name: "User"},
* {groupid: 3, name: "Guest"}]);
*
* <hines:LookupColumn headerText="Group" dataField="groupid" labelField="groupname" source="{myGroups}"/>
*
* This will cause and rows with a groupid of 1 to render as "Admin" and so on.
*
* This will also work with a xml source and the lookupField can be used if the field names differ.
*
* <hines:LookupColumn headerText="Users Group" dataField="usersgroupid" lookupField="groupid" labelField="groupname" source="{myGroups}"/>
*
* @author jpyne
*/
public class LookupColumn extends DataGridColumn
{
public function LookupColumn(columnName:String=null)
{
super(columnName);
// Set up the internal lableFunction.
labelFunction = LookupColumn.doLookup;
}
//----------------------------------
// labelField
//----------------------------------
private var _labelField:String;
/**
* Field to display in the destination record. If this is not set it will default to "label".
*/
[Inspectable(category="General", defaultValue="")]
[Bindable("labelFieldChanged")]
public function get labelField():String
{
return _labelField ? _labelField : "label";
}
/**
* @private
*/
public function set labelField(value:String):void
{
_labelField = value;
dispatchEvent(new Event("labelFieldChanged"));
}
//----------------------------------
// lookupField
//----------------------------------
private var _lookupField:String;
/**
* Field to search for in the source ArrayCollection. If unset then datafield will be used.
*/
[Inspectable(category="General", defaultValue="")]
[Bindable("lookupFieldChanged")]
public function get lookupField():String
{
return _lookupField ? _lookupField : dataField;
}
/**
* @private
*/
public function set lookupField(value:String):void
{
_lookupField = value;
if(source)
prepSource();
dispatchEvent(new Event("lookupFieldChanged"));
}
//----------------------------------
// source
//----------------------------------
private var _source:ArrayCollection;
/**
* Field to display in the destination record. If this is not set it will default to "label".
*/
[Inspectable(category="General", defaultValue="")]
[Bindable("sourceChanged")]
public function get source():ArrayCollection
{
return _source;
}
/**
* @private
*/
public function set source(value:ArrayCollection):void
{
_source = value;
if(lookupField)
prepSource();
dispatchEvent(new Event("sourceChanged"));
}
//----------------------------------
// hashSource
//----------------------------------
private var _hashSource:Object;
public function get hashSource():Object
{
return _hashSource;
}
private function prepSource():void
{
_hashSource = new Object();
for each (var item:Object in source)
{
_hashSource[item[lookupField]] = item;
}
}
/**
* Override the dataTipFiled and change it to the dataField as that will be hidden.
*/
override public function get dataTipField():String
{
return dataField;
}
/**
* Look for a item in a source and display its labelField. This is an internal method and will be called for each item in teh DataGrid.
*
* @param row
* @param control
* @return
*/
static private function doLookup(row:Object, control:LookupColumn):String
{
if(control.hashSource && control.hashSource[row[control.dataField]])
return control.hashSource[row[control.dataField]][control.labelField];
// If no match was found, just return the original value.
return row[control.dataField];
}
}
}
/usr/local/bin/isomnt
#!/bin/bash
if [ -e "$*" ]; then
if [ -d /media/"$*" ]; then
echo "Unmounting '$*'..."
sudo umount -d /media/"$*"
sudo rmdir /media/"$*"
else
echo "Mounting '$*'..."
sudo mkdir /media/"$*"
sudo mount -o loop "$*" /media/"$*"
fi
else
echo "No image found to mount."
fi
~/.gnome2/nautilus-scripts/(Un)Mount ISO
#!/bin/bash
if [ -d /media/"$*" ]; then
gksudo ls /media
sudo umount -d /media/"$*"
sudo rmdir /media/"$*"
else
gksudo mkdir /media/"$*"
wd=${NAUTILUS_SCRIPT_CURRENT_URI#file://}
sudo mount -o loop "$wd/$*" /media/"$*"
fi
include_once("extensions/blacklist.php");
$wgWhitelist['sysop']['read'] = $wgBlacklist['*']['read'] = array("Special:Export", "Special:Listusers", "Special:Ipblocklist", "Special:Log", "Special:Allmessages");
$wgBlacklistOps["useRegex"] = true;
$wgWhitelist['sysop']['read'] = $wgBlacklist['*']['read'] = array("^Special:(Export|Listusers|Ipblocklist|Log|Allmessages)$");
blacklist.php
<?php
/*
Blacklist Mediawiki Extension
By Jeremy Pyne jeremy.pyne@gmail.com
This extension adds support for a $wgBlacklist array, layed out like $wgGroupPermissions, to support overrides.
For example I can set $wgBlacklist['*']['read'] to diable specific special pages or
make some pages of the site only visible for special groups.
This blacklisting is done from lowest to highest powered groups and is implisit. IE if you deny Main Page to User, it also denies it for all parent's of user.
To override a blacklist at a higher level ou have to add an entry to $$wgWhitelist['sysop']['read'] to re-enable the pages if you are a sysop.
Options:
$wgBlacklistOps["useRegex"] = true;
This setting dictates whether to tread the page lists as regular expressions or not. Though turning regular expressions off is much faster, you can not
mark page groups, partial page titles, or variations of title formating.
Example: To block some special pages for normal users, but not sysops do this.
$wgWhitelist['sysop']['read'] = $wgBlacklist['*']['read'] = array("Special:Export", "Special:Listusers", "Special:Ipblocklist", "Special:Log", "Special:Allmessages");
Or wth a RegEx
$wgBlacklistOps["useRegex"] = true;
$wgWhitelist['sysop']['read'] = $wgBlacklist['*']['read'] = array("^Special:(Export|Listusers|Ipblocklist|Log|Allmessages)$");
Note: This is not flawless method as page inclusions and such can get around this.
*/
if (!defined('MEDIAWIKI')) die();
$wgExtensionCredits['other'][] = array(
'name' => 'blacklist',
'description' => 'adds $wgBlacklist array to provide blacklist overrides',
'url' => 'http://www.mediawiki.org/wiki/Extension:Blacklist',
'author' => 'Jeremy Pyne',
'version' => '1.0'
);
$wgHooks['userCan'][] = 'checkBlacklist';
/**
* Is this page blacklisted
* @param &$title the concerned page
* @param &$wgUser the current mediawiki user
* @param $action the action performed
* @param &$result (out) true or false, or null if we don't care about the parameters
*/
function checkBlacklist(&$title, &$wgUser, $action, &$result) {
global $wgBlacklist;
global $wgWhitelist;
global $wgBlacklistOps;
$hideMe = false;
$groupPower = array(
0 => "*",
1 => "user",
2 => "autoconfirmed",
3 => "emailconfirmed",
4 => "bot",
5 => "sysop",
6 => "bureaucrat");
$myGroups = array_intersect($groupPower, $wgUser->getEffectiveGroups());
foreach($myGroups as $myGroup) {
if(array_key_exists($myGroup, $wgBlacklist) && array_key_exists($action, $wgBlacklist[$myGroup]) && is_array($wgBlacklist[$myGroup][$action]))
{
if($wgBlacklistOps["useRegex"]) {
foreach($wgBlacklist[$myGroup][$action] as $myBlacklist)
if(preg_match("/$myBlacklist/", $title->getPrefixedText()))
{
$hideMe = true;
break;
}
} else {
$myBlacklist = array_flip($wgBlacklist[$myGroup][$action]);
if(array_key_exists($title->getPrefixedText(), $myBlacklist))
$hideMe = true;
}
}
if(array_key_exists($myGroup, $wgWhitelist) && array_key_exists($action, $wgWhitelist[$myGroup]) && is_array($wgWhitelist[$myGroup][$action]))
{
if($wgBlacklistOps["useRegex"]) {
foreach($wgWhitelist[$myGroup][$action] as $myWhitelist)
if(preg_match("/$myWhitelist/", $title->getPrefixedText()))
{
$hideMe = false;
break;
}
} else {
$myWhitelist = array_flip($wgWhitelist[$myGroup][$action]);
if(array_key_exists($title->getPrefixedText(), $myWhitelist))
$hideMe = false;
}
}
}
if($hideMe)
$result = false;
return !$hideMe;
}
?>
{case 1 break} Code 1 {case 2} Code 2 {default break} Code 3 {case 1} Code 1 {break} {case 2} Code 2 {default} Code 3 {break}
Before:
http://my.domain.com/wiki/index.php?title=Main_Page&action=view
After:
http://my.domain.com/wiki/Main_Page/view
LocalSettings.php
$wgScriptPath = "/wiki";
$wgArticlePath = "$wgScriptPath/$1";
$actions = array('view', 'edit', 'watch', 'unwatch', 'delete','revert', 'rollback', 'protect',
'unprotect','info','markpatrolled','validate','render','deletetrackback','print',
'dublincore','creativecommons','credits','submit','viewsource','history','purge');
foreach ($actions as $a)
$wgActionPaths[$a] = "$wgScriptPath/$1/$a";
LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so
RewriteCond %{REQUEST_URI} /(view|edit|watch|unwatch|delete|revert|rollback|protect|unprotect|info|markpatrolled|validate|render|deletetrackback|print$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/wiki/(.*)/([a-z]*)$ /wiki/index.php?title=$1&action=$2 [L,QSA]
RewriteCond %{REQUEST_URI} !/wiki/images
RewriteCond %{REQUEST_URI} !/wiki/skins
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/wiki/(.*)$ /wiki/index.php?title=$1 [PT,L,QSA]
DateUtil.clone(StartDate.selectedDate).date;
[Bindable]
private var prevDate:Date;
prevDate.hours = prevDate.minutes = prevDate.seconds = prevDate.milliseconds = 0;
prevDate.date--;
// Update the DateField.
dtDate.selectedDate = prevDate;
dtDate.dispatchEvent(new CalendarLayoutChangeEvent(CalendarLayoutChangeEvent.CHANGE));
<mx:datefield id="dtDate" change="" selecteddate="{prevDate}">
<hines:DateField id="dtDate" change="" selectedDate="{DateUtil.now.subtract(DateUtil.DATE, 1).date}"/>
var time:Date = DateUtil.now.time;
var monday:Date = DateUtil.now.assign(DateUtil.DAY, 1).date;
var then:Date = DateUtil.now.add(DateUtil.HOURS, 2).datetime;
var day:Number = DateUtil.now.fetch(DateUtil.Day);
DateUtil.as
package
{
/**
* DateUtil class for simple date manipulation.
*
* You can do simple time alterations with this calss. Here are some samples.
*
* Subtract a day:
* DateUtil.now.subtract(DateUtil.DATE, 1).date;
*
* Add a month:
* DateUtil.now.add(DateUtil.MONTH, 1).date;
*
* Go to Monday:
* DateUtil.now.assign(DateUtil.DAY, 1).date
*
* @author Jeremy Pyne jeremy.pyne@gmail.com
*/
public class DateUtil
{
/**
* Date storage object.
*/
private var _date:Date;
public static const MILLISECONDS:String = "milliseconds";
public static const SECONDS:String = "seconds";
public static const MINUTES:String = "minutes";
public static const HOURS:String = "hours";
public static const DAY:String = "day";
public static const DATE:String = "date";
public static const MONTH:String = "month";
public static const YEAR:String = "fullYear";
/**
* Create a new DateUtil class.
*
* @param date
*/
public function DateUtil(date:Date)
{
_date = date;
}
/**
* Add some value to a variable.
*
* @param variable
* @param value
* @return
*/
public function add(variable:String, value:Number):DateUtil
{
if(variable == DateUtil.DAY)
variable = DateUtil.DATE;
_date[variable] += value;
return this;
}
/**
* Subtract some value to a variable.
*
* @param variable
* @param value
* @return
*/
public function subtract(variable:String, value:Number):DateUtil
{
if(variable == DateUtil.DAY)
variable = DateUtil.DATE;
_date[variable] -= value;
return this;
}
/**
* Set some value to a variable.
*
* @param variable
* @param value
* @return
*/
public function assign(variable:String, value:Number):DateUtil
{
if(variable == DateUtil.DAY)
{
variable = DateUtil.DATE;
value = _date.date + value - _date.day;
}
_date[variable] = value;
return this;
}
/**
* Get a variable.
*
* @param variable
* @return
*/
public function fetch(variable:String):Number
{
return _date[variable];
}
/**
* Get only the current date.
*
* @return
*/
public function get date():Date
{
var date:Date = new Date(_date.time);
date.hours = date.minutes = date.seconds = date.milliseconds = 0;
return date;
}
/**
* Get only the current time.
*
* @return
*/
public function get time():Date
{
var date:Date = new Date(_date.time);
date.fullYear = 1969;
date.month = date.date = 0;
return date;
}
/**
* Get the full date and time.
*
* @return
*/
public function get datetime():Date
{
var date:Date = new Date(_date.time);
return date;
}
/**
* Create a new DateUtil for the current data and time.
*
* @return
*/
public static function get now():DateUtil
{
return new DateUtil(new Date);
}
/**
* Create a new DateUtil for the passed in date. Updates will not effect the original date.
*
* @return
*/
public static function clone(date:Date):DateUtil
{
return new DateUtil(new Date(date.time));
}
/**
* Create a new DateUtil for the passed in date. Updates will alter the original date.
*
* @return
*/
public static function create(date:Date):DateUtil
{
return new DateUtil(date);
}
}
}