01.26.11
Posted in Programming at 2:38 pm by Toby
document.location.replace(‘http://mysite.example.com/myurl.html’)
seems to replace (!) the contents of the window, and although it replaces the url in the address bar it doesnt really refresh the page as you will notice if you try the back button as it will look like you are going two pages back.
document.location = ‘http://mysite.example.com/myurl.html’
will go to the new location.
Permalink
01.25.11
Posted in Programming, YUI at 10:43 am by Toby
I have been using YUI 2 and now YUI 3 for the last year or so. I’m not a major javascript developer by any means but I started with Douglas Crockfords excellent book and series and javascript and YUI have finally started to make sense and I’m begining to put together a few bits and pieces for an internal app we have. I started using YUI 3 recently as there is no reason not to since it works almost seemlessly with YUI 2 with only a little moving around. However I was never quite sure how to put it all together. The standard YUI template looks a bit funny at the begining.
YUI().use(''yui2-tabview', 'yui2-element', 'yui2-connection', function(Y) {
//Do all sorts of cool things here.
});
You see this pattern all over the place, and infact it is how you use YUI3.
After watching some of the excellent videos at YUI Theatre, I figured out that it was really easy to use the YUI.add method to add my own module, but all the code I could find was one slide in the presentation which sort of described how to do it, so I thought it would be useful to do a little how to here to help people out.
Basic Module
Adding a module to YUI is super easy, so easy infact that you will never write YUI code again that isnt part of a module. I guess thats the point.
Instead of just writing functions or objects in your .js file, do this.
YUI.add('mycoolmodule-core', function(Y){
var privatevariable = 'Private Value';
var privatefunction = function(){ //dos something };
Y.namespace('mycoolmodule');
Y.mycoolmodule.core = {
//declare object with public functions and variables.
}
}, '0.1.1' //Version String is Third parameter to add function
//,RequirementsObject //if you wish fourth param can be a Config Object, see API reference for details.
);
Note we do not execute YUI as in the use pattern.
In the above code, the object assigned to Y.mycoolmodule.core is our public module. The public code you would have had in your .js file is in this object, and available to your other code . In order to use it you just need to include the .js file in your page as expected, and call use.
YUI().use(''yui2-tabview', 'yui2-element', 'yui2-connection','mycoolmodule-core', function(Y) {
//Do all sorts of cool things here with my own module.
});
Thats it! It works, and you have all the sandboxing that YUI provides for your code. How brilliant is that?
How do I reference Stuff
One of the things I found confusing initially was how to reference stuff within this module structure, so I’ll show you what I did (if someone wants to correct me to make this better please do, I find the whole this, that, these, those a bit confusing).
YAHOO!
Most people are still using YUI 2 so a reference to the YAHOO object is essential, the way to do this is to declare YAHOO as a private variable in your module, which makes it available to all your module functions.
YUI.add('mycoolmodule-core', function(Y){
var YAHOO = Y.YUI2;
var privatefunction = function(){ //dos something };
Y.namespace('mycoolmodule');
Y.mycoolmodule.core = {
//etc
Your Module
Stuff within your module, such as dialogs, functions, objects , array etc, can be referenced in a number of ways, I suppose you can use ‘this’, but I find this confusing. In my case it works well to refer to it by full namespaces
YUI.add('mycoolmodule-core', function(Y){
var YAHOO = Y.YUI2;
var privatefunction = function(){ //dos something };
Y.namespace('mycoolmodule');
Y.mycoolmodule.core = {
PublicVar : 'A Value',
PublicObj : {a:'A', b:'B'},
afunction : function(){
alert(Y.mycoolmodule.core.PublicObj.a);
}
}
//etc
I hope this helps out with someone needing to get a YUI module working by using YUI.add
Permalink
01.27.10
Posted in EditPadPro, tools at 7:14 am by Toby
Following on from my previous post about setting Editpadpro up to run your php script, I wondered whether I could get it to run any command line command. It was wonderfully easy.
- Create a new Tool called ‘Command Line’
- Set the Command Line to ‘cmd’
- On The Standard I/O tab, set the Selected text to be sent to the standard input .
- Set the tools output to be sent to the message pane (or a new document if you wish).
- Save the tool
Type your command and select then click on Tools|Command Line to run the command and you get your output in the message window.
Permalink
Posted in EditPadPro, Programming, tools at 1:39 pm by Toby
As mentioned in a previous post I am a fan of Editpadpro, it is now my text tool of choice, I find it very powerful, quick and easy to use. I have recently made an addition which is a nice little improvement. I set up an Editpadpro tool to run the current file as a php script and dump the output to a new file in Editpadpro. No more need to jump to your webbrowser and keep refreshing windows.
Follow the steps below to get this up and running.
- Create a new tool by going to Tools – Configure Tools – New
- Give it a name (I’ve called mine PHP File)
Set the options on the first screen
- Command line – path to php.exe and the %FILE% placeholder (places the current filename on command line).
- We must set the Working folder or any included files in your script wont be found. – use %Path% to set to the currently selected files path.
- Select any file type this should apply to probably just php.
If you wish ask Editpadpro to Save your current file to take advantage of any changes you might have made.
Now comes the fun bit,
- In the ‘How to capture the tool’s standard output’ select Into new tab to give us the output of our phpscript.
- Dump any error into the message pane.
This works a treat and for many text processing tasks I no longer need to go near a browser which makes me happy.
Permalink
01.15.10
Posted in fossil-scm at 1:45 pm by Toby
This wasn’t difficult, but there was few bits and pieces so I will put it down here and maybe it will help someone. My current host is dreamhost.com so these are the steps for that host but I would image its probably pretty close for any other host.
Assumptions
Linux Host – Intel
Perl Scripts can be run on your shared hosting.
Steps
- Download the linux binary for intel or amd from fossil-scm.org and unzip.
- Upload fossil linux binary to your webspace – uploaded into a subdirectory bin
- Create a file with a .pl extension to run your script (I called mine fossil.pl)
- Put the code below into your fossil.pl file
#!/home/user/domain/bin/fossil
repository: /home/user/domain/fossilrepository.fossil
- Obviously replacing user and domain with the path to the directory you put the fossil binary in.
- Next you need to change the permissions on the following files to 755
Navigate to www.yourdomain.com/fossil.pl and you should see the familiar fossil web ui.
Permalink