Skip to main content

browserify – write client-side javascript server-side

thechangelog:

Unifying your front-end and back-end codebases can be a harrowing experience. Regardless of your web technology stack of choice, you’ve probably created some server-side component which generated some front-end JavaScript for you at some point. I’ve created and used many tools that do such code generation, and I’ve hated all of them. This is why I’m soo excited to see node-browserify by prolific Node.js module author,James Halliday.

browserify is a node.js library which helps you share your back-end code to the front-end by enabling such features as:

  • a client-side require() method
  • being able to load npm packages
  • a middleware system for code generation:
    • minify
    • uglify
    • ES5 compatibility
    • fileify ( wrap static files or directories in JavaScript methods )
  • a CLI tool for creating stand-alone bundles
  • full integration with node’s httpServer and Express
  • browser-versions of certain core node modules such as path, events, and vm

Browserify does a great job of simplifying the process of sharing code between the browser and server by building on top of existing infrastructure and providing some great new features that play very nice with node.js

I needed to build a library that would operate dual-sided ( front-end and back-end ), and I choose to build it server-side first and then use the browserify CLI tool to port it to the client ( and work as a standalone with no server dependencies ). The entire process worked out much better then expected and I’d recommend trying it out for your next JavaScript project.

If you’d like to see an example of node-browserify in production, you can check out Browserling, Mr. Halliday’s very own company which allows you to test websites cross-browser, in your own browser! I can only imagine what crazy libraries SubStack will think up next.

Related Posts:

SplMaxHeap aka SelfSort-“array”

class MyListHeap extends SplMaxHeap {
  public function compare( $value1, $value2 ) {
    return ( $value1['created_at'] - $value2['created_at'] );
  }
}

$list = new MyListHeap;

$list->insert(array('user_id' => 1, 'created_at' => time()-2000));
$list->insert(array('user_id' => 2, 'created_at' => time()-1000));
$list->insert(array('user_id' => 3, 'created_at' => time()-5000));

foreach($list as $l) {
  echo "{$l['user_id']}:{$l['created_at']}\n";
}

And the output will be:

2:1309908000
1:1309907000
3:1309904000

And the output will be:

2:1309908000
1:1309907000
3:1309904000

Read more: http://hu2.php.net/splmaxheap

Related Posts:

  • No Related Posts

How to extend the ArrayObject and create a custom array

to my friend with lots of love

class MyArray extends ArrayObject {
  public function __construct($array = array()){ 
    parent::__construct($array, ArrayObject::ARRAY_AS_PROPS);
  }

  public function get_property_string($sep = ':') {
    return implode($sep, $this->getArrayCopy());
  }

  public function __ToString() {
    return 'Array';
  }

  /* some custom method */
}

$rights = new MyArray;
$rights->append('LOGIN');
$rights->append('BETA_ACCESS');
$rights->append('WRITE_COMMENT');

var_dump($rights->get_property_string());

And the output will be:

string(31) "LOGIN:BETA_ACCESS:WRITE_COMMENT

Read more: http://php.net/manual/en/class.arrayobject.php

Related Posts:

  • No Related Posts

VirtualBox 4.0.10 released

This is a maintenance release. The following items were fixed and/or added:

  • GUI: fixed disappearing settings widgets on KDE hosts (bug #6809)
  • Storage: fixed hang under rare circumstances with flat VMDK images
  • Storage: a saved VM could not be restored under certain circumstances after the host kernel was updated (bug #8983)
  • Storage: refuse to create a medium with an invalid variant (for example Split2G with VDI; bug #7227)
  • Snapshots: none of the hard disk attachments must be attached to another VM in normal mode when creating a snapshot
  • USB: fixed occasional VM hangs with SMP guests (bug #4580)
  • USB: proper device detection on RHEL/OEL/CentOS 5 guests (partial fix for bug #8978)
  • ACPI: force the ACPI timer to return monotonic values for improve behavior with SMP Linux guests (bug #8511 and others)
  • RDP: fixed screen corruption under rare circumstances (bug #8977)
  • rdesktop-vrdp: updated to version 1.7.0
  • OVF: under rare circumstances some data at the end of a VMDK file was not written during export
  • Mac OS X hosts: Lion fixes (bug #8903)
  • Mac OS X hosts: GNOME 3 fix
  • Linux hosts: fixed VT-x detection on Linux 3.0 hosts (bug #9071)
  • Linux hosts: fixed Python 2.7 bindings in the universal Linux binaries
  • Windows hosts: fixed leak of thread and process handles
  • Windows Additions: fixed bug when determining the extended version of the Guest Additions (4.0.8 regression; bug #8948)
  • Solaris Additions: fixed installation to 64-bit Solaris 10u9 guests (4.0.8 regression)
  • Linux Additions: RHEL6.1/OL6.1 compile fix
  • Linux Additions: fixed a memory leak during VBoxManage guestcontrol execute (bug #9068)

Download and more info: VirtualBox.org

Source: Changelog

    Related Posts:

    • No Related Posts

    What can I do…

    Me: What can I do if I need to try to hack an existing (not self-made) PHP library?
    Sensei: Patience.
    Me: What can I do if I do not have the patience?
    Sensei: How long have you been coding?
    Me: 10 years… but why?
    Sensei: Sit on the floor, close your eyes and try to think about the last 10 years.
    Me: About the beginning?
    Sensei: If you have a good picture in your memory about the first 3 days of the first self-made program then try to remember the first time when you needed to hack that code.
    Me: Oh yes. I could hack that.
    Sensei: That was your code?
    Me: Yes.
    Sensei: Was it easy to read? Did you remember some lines of it?
    Me: Nope.
    Sensei: Why did you hack that?
    Me: Thanks Sensei… I will think of these.

    Related Posts:

    MySQL + MongoDB + PHP

    We used MySQL with PHP… In the past months we try to migrate MySQL tables to MongoDB. And yes it was not a simple method ^_^ (but we did it).

    Now I’ll tell you a simple source of bugs because i have too much fun with this. We have a users table with some fields for example member_type (int). The types already migrated to MongoDB. We fetch the user and we make a query with member_type value but it doesn’t work for us. Why?

    Yes. When i call var_dump then i get a string but in MongoDB we need an integer. If you don’t use any ORM then if you fetch any data from MySQL what is an integer then you need a type conversion: (int)$row->member_type;

    Related Posts: