working on it ...


Explore Public Snippets

Sort by

Found 64k snippets matching: example

    public by micurs  6866116  356  9  18

    Typescript: passing a class member function as parameter to another function

    Typescript introduces the class construct and the concept of member functions. However if you try to pass a instance member function as parameter to another function the binding with the instance is lost. To solve this problem you can use the capability of javascript (and Typescript) to support closures on anonymous function (or lambda expressio
    ///<reference path='../types/node.d.ts'/>
    ///<reference path='../types/underscore.d.ts'/>
    import _ = require("underscore");
    class SomePeople {
      values : string[] = [ 'John', 'Mary', 'Peter'];
      out() {
        _.each( this.values, (v) => process.stdout.write( v + '\n') );
    // This function accept a function it will execute internally
    function outSomething( outFunc : () => any ) {
    var crowd = new SomePeople();
    // This won't work since the actual crowd instance binding will be lost
    outSomething( crowd.out );
    // This will work: the closure within the lambda expression retain the
    // crowd instance and its data
    outSomething( () => crowd.out() );

    public by cghersi  468659  7  8  2

    Load a SOAP endpoint with Apache CXF using JMS transport provided by Apache ActiveMQ

    This is an example on how to load a SOAP web service in order to be able to invoke its methods via JMS transport
    private JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    public MyInterface loadEndPoint() {
    	//try to load from local, if available:
    	boolean loadOK = false;
    	MyInterface result = null;
    	try {
    		Class<?> c = Class.forName("MyImplClass");
    		Method fact = c.getMethod("get");
    		result = (MyInterface) fact.invoke(null);
    		loadOK = true;
    	} catch (ClassNotFoundException e) {"Cannot find MyImplClass, redirecting to  remote access...", e);		
    	} catch (Exception e) {
    		log.warn("Error searching MyImplClass, , redirecting to remote access. Exception is " + e, e);
    	//load remote endpoint:
    	if (!loadOK) {
    		//detect transport protocol for web services:
    		String brokerAddr = ""; //the right broker address
    		String queueName = "MyQueueName";
    		String address = "jms:jndi:dynamicQueues/" + queueName + "?jndiInitialContextFactory=org.apache.activemq.jndi.ActiveMQInitialContextFactory&jndiConnectionFactoryName=ConnectionFactory&jndiURL=" + brokerAddr;
 "Connecting to " + address);
    		String connString = "tcp://" + brokerAddr + ":61616";
    		ActiveMQConnectionFactory connFactory = new ActiveMQConnectionFactory("Myusername", "Mypassword", connString);
    		SoapBindingConfiguration conf = new SoapBindingConfiguration();
    		//MTOM not supported! .net does not interoperate with cxf mtom impl.
    //		conf.setMtomEnabled(true);
    		factory.getFeatures().add(new WSAddressingFeature());
    		factory.getFeatures().add(getJMSConfigFeature(queueName, connFactory, 10000)));
    		Object resObj = factory.create();
    		if ((resObj != null) && (resObj instanceof MyInterface))
    			result = (MyInterface) resObj;
    		return result;
    public static JMSConfigFeature getJMSConfigFeature(String queueName, ActiveMQConnectionFactory connectionFactory, Long receiveTimeout) {
    	JMSConfigFeature jmsConfigFeature = new JMSConfigFeature();
    	JMSConfiguration jmsConfig = new JMSConfiguration();
    	if (receiveTimeout != null)
    	return jmsConfigFeature;

    public by przodownikR1  394881  1  3  0

    example create datasource in javaConfig with full desc and params

    example create datasource in javaConfig with full desc and params:
      public DataSource dataSource() {
        final DataSource dataSource = new DataSource();
        dataSource.setValidationQuery("SELECT 1");
        return dataSource;

    public by Derek Pauley  381629  18  3  1

    SVNKit export from Subversion example

    SVNKit export from Subversion example:
    import org.tmatesoft.svn.core.SVNDepth;
    import org.tmatesoft.svn.core.SVNException;
    import org.tmatesoft.svn.core.SVNURL;
    import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager;
    import org.tmatesoft.svn.core.wc.SVNClientManager;
    import org.tmatesoft.svn.core.wc.SVNRevision;
    import org.tmatesoft.svn.core.wc.SVNUpdateClient;
    import org.tmatesoft.svn.core.wc.SVNWCUtil;
    public class SvnExportExample {
    	public static void main(String... args){
    		final String url = "svn://";
    		final String destPath = "c:/temp/svntest";
    		SVNRepository repository = null;
    			//initiate the reporitory from the url
    			repository = SVNRepositoryFactory.create(SVNURL.parseURIDecoded(url));
    			//create authentication data
    			ISVNAuthenticationManager authManager = 
    					SVNWCUtil.createDefaultAuthenticationManager("cliff.darling", "svnuser");
    			//output some data to verify connection
    			System.out.println( "Repository Root: " + repository.getRepositoryRoot( true ) );
    			System.out.println(  "Repository UUID: " + repository.getRepositoryUUID( true ) );
    			//need to identify latest revision
    			long latestRevision = repository.getLatestRevision();
    			System.out.println(  "Repository Latest Revision: " + latestRevision);
    			//create client manager and set authentication
    			SVNClientManager ourClientManager = SVNClientManager.newInstance();
    			//use SVNUpdateClient to do the export
    			SVNUpdateClient updateClient = ourClientManager.getUpdateClient( );
    			updateClient.setIgnoreExternals( false );
    			updateClient.doExport( repository.getLocation(), new File(destPath), 
    					SVNRevision.create(latestRevision), SVNRevision.create(latestRevision), 
    					null, true, SVNDepth.INFINITY);
    		} catch (SVNException e) {
    		}finally {

    public by lbottaro  406559  1  7  9

    Simple CORBA java server

    This code shows an example of simple corba server in java. A CORBA server needs a local ORB object. The server instantiates an ORB and registers its servant objects so that the ORB can find the server when it receives an invocation for it. the server is a process that instantiates one or more servant objects. Each servant implements the
    // The package containing our stubs.
    import HelloApp.*;
    // HelloServer will use the naming service.
    import org.omg.CosNaming.*;
    // The package containing special exceptions thrown by the name service.
    import org.omg.CosNaming.NamingContextPackage.*;
    // All CORBA applications need these classes.
    import org.omg.CORBA.*;
    public class HelloServer 
      public static void main(String args[])
           // Create and initialize the ORB
          ORB orb = ORB.init(args, null);
          // Create the servant and register it with the ORB
          HelloServant helloRef = new HelloServant();
          // Get the root naming context
        org.omg.CORBA.Object objRef = 
          NamingContext ncRef = NamingContextHelper.narrow(objRef);
          // Bind the object reference in naming
          NameComponent nc = new NameComponent("Hello", "");
          NameComponent path[] = {nc};
          ncRef.rebind(path, helloRef);
          // Wait for invocations from clients
          java.lang.Object sync = new java.lang.Object();
              } catch(Exception e) {
            System.err.println("ERROR: " + e);
    class HelloServant extends _HelloImplBase
      public String sayHello()
        return "\nHello world!!\n";

    public by lbottaro  356031  1  7  3

    Vendor class - Java example for marshalling/unmarshalling, using JAX-B XmlID annotation

    This is the Vendor class, where the XmlElement annotation sets the vendorID attribute as XmlID. Such key will match the reference set in Card class, using annotation XmlIDREF.
    package com.test.jaxb;
    import javax.xml.bind.annotation.XmlAccessType;
    import javax.xml.bind.annotation.XmlAccessorType;
    import javax.xml.bind.annotation.XmlElement;
    import javax.xml.bind.annotation.XmlID;
    public class Vendor implements Serializable {
    	 @XmlElement(name = "vendor-ID")
    	private String vendorID;
    	 @XmlElement(name = "vendor-Name")
    	private String vendorName;
    	 * @param vendorID
    	 * @param vendorName
    	public Vendor(String vendorID, String vendorName) {
    		this.vendorID = vendorID;
    		this.vendorName = vendorName;
    	public Vendor() {
    		// TODO Auto-generated constructor stub
    	 * @return the vendorID
    	public String getVendorID() {
    		return vendorID;
    	 * @param vendorID the vendorID to set
    	public void setVendorID(String vendorID) {
    		this.vendorID = vendorID;
    	 * @return the vendorName
    	public String getVendorName() {
    		return vendorName;
    	 * @param vendorName the vendorName to set
    	public void setVendorName(String vendorName) {
    		this.vendorName = vendorName;
    	/* (non-Javadoc)
    	 * @see java.lang.Object#toString()
    	public String toString() {
    		return "Vendor [vendorID=" + vendorID + ", vendorName=" + vendorName
    				+ "]";

    public by HeathDernovich  262028  0  4  1

    An example of inheriting from event emitter

    An example of inheriting from event emitter: EventEmitterPattern.js
    // Require our emitter
    var Emitter = require('events').EventEmitter;
    // Our main constructor
    var myEmitter = function (config) {
      // extend with emitter;
      // Inherit from emitter, but keep my constructor
      myEmitter.prototype = Object.create(Emitter.prototype, {
        constructor: {
          value: myEmitter
      // methods
    myEmitter.prototype.setName = function (nam) { = nam;
      this.emit('nameChanged', name);
    module.exports = myEmitter;

    public by lbottaro  294401  1  6  3

    Simple RMI Java client

    This is a simple RMI client implementation. Here the client program obtains a stub for the registry on the server's host, then looks up the remote object's stub by name in the registry. Finally invokes the sayHello method on the remote object using the stub. Here the client invokes the method exposes by Hello remote interface. Note that if no
    package example.hello;
    import java.rmi.registry.LocateRegistry;
    import java.rmi.registry.Registry;
    public class Client {
        private Client() {}
        public static void main(String[] args) {
    	String host = (args.length < 1) ? null : args[0];
    	try {
    	    Registry registry = LocateRegistry.getRegistry(host);
    	    Hello stub = (Hello) registry.lookup("Hello");
    	    String response = stub.sayHello();
    	    System.out.println("response: " + response);
    	} catch (Exception e) {
    	    System.err.println("Client exception: " + e.toString());

    public by lbottaro  281544  2  6  3

    Simple RMI Java server

    This code shows a basic RMI server example. A "server" is the class which has a main method that creates an instance of the remote object implementation, exports the remote object and then binds that instance to a name in a RMI registry. Here the server implements the remote interface Hello. The class that contains this main method could be the
    package example.hello;
    import java.rmi.registry.Registry;
    import java.rmi.registry.LocateRegistry;
    import java.rmi.RemoteException;
    import java.rmi.server.UnicastRemoteObject;
    public class Server implements Hello {
        public Server() {}
        public String sayHello() {
    	return "Hello, world!";
        public static void main(String args[]) {
    	try {
    	    Server obj = new Server();
    	    Hello stub = (Hello) UnicastRemoteObject.exportObject(obj, 0);
    	    // Bind the remote object's stub in the registry
    	    Registry registry = LocateRegistry.getRegistry();
    	    registry.bind("Hello", stub);
    	    System.err.println("Server ready");
    	} catch (Exception e) {
    	    System.err.println("Server exception: " + e.toString());

    public by yulian  207658  3  5  0

    struct code example

    typedef unsigned short byte2;
    typedef unsigned long  byte4;
    struct header
        /* totally 44 bytes;        endianness (all the rest are little) */
        /* RIFF */
        char    ChunkID[4];         // big
        byte4   ChunkSize;
        char    Format[4];          // big
        /* fmt  */
        char    SubChunk1ID[4];     // big
        byte4   SubChunk1Size;
        byte2   AudioFormat;
        byte2   NumChannels;
        byte4   SampleRate;
        byte4   ByteRate;
        byte2   BlockAlign;
        byte2   BitsPerSample;
        /* data */
        char    SubChunk2ID[4];     // big
        byte4   SubChunk2Size;
    • Public Snippets
    • Channels Snippets