working on it ...


Explore Public Snippets

Sort by

Found 101k snippets matching: int

    public by  6866287  360  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 micurs  748135  19  7  0

    JQuery typescript interface for $.ajax() callbacks

    To use JQuery $.ajax() you must define your callback functions with the following interfaces
    interface OnSuccessAjaxCallback {
      (data: any, textStatus?: string, jqXHR?: JQueryXHR): any;
    interface OnErrorAjaxCallback {
      (jqXHR?: JQueryXHR, textStatus?: string, errorThrow?: string) : any;

    public by cghersi  475324  5  7  0

    C#: Parse a comma separated string into a collection of numeric items

    This method can be used with any separator you need, just setting the 'separator' input
    public static List<long> ParseIntoListOfLongs(string content, char separator = ',')
        List<long> ids = new List<long>();
        if (string.IsNullOrEmpty(content))
            return ids;
        string[] strIds = content.Split(separator);
        foreach (string str in strIds)
            long id = -1;
            if (long.TryParse(str, out id))
                if (id > 0)
        return ids;

    public by lbottaro  406590  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  311420  3  6  0

    Get MAC address of current interface in Python

    This python uses uuid.getnode to get current mac address as an integer. It formats the number in a standard mac address form (i.e. bytes splitted by :)
    import uuid
    print ':'.join(['{:02x}'.format((uuid.getnode() >> i) & 0xff) for i in range(0,8*6,8)][::-1])

    public by cghersi @ Thotpot alumni  303325  0  5  0

    Java: generate hprof during runtime

    To generate hprof may be interesting for debug purpose, most of all before an OutOfMemory occurs on production applications! This .ini option halps to create an hprof to be analyzed before the occurrence of memory errors. See for further details
    java -Xrunhprof:heap=sites,depth=10,thread=y,doe=y ...other jvm options in ini file...

    public by lbottaro  294427  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  281568  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 lbottaro  170311  0  6  0

    Simple RMI Java interface

    A simple RMI interface example. A remote interface extends the interface java.rmi.Remote and declares a set of remote methods. Each remote method must declare java.rmi.RemoteException (or a superclass of RemoteException) in its throws clause, in addition to any application-specific exceptions. This interface declares just one method, sayHello, w
    package example.hello;
    import java.rmi.Remote;
    import java.rmi.RemoteException;
    public interface Hello extends Remote {
        String sayHello() throws RemoteException;

    public by cghersi  202350  0  5  1

    Java enum definition

    This is the classic enum definition with a member and the static getter to parse from the internal code
     * This enumeration defines ....<br/>
    public enum MyComponent {
    	Comp1 			(1),
    	API 			(2),
    	unknown			(0);
    	private int code;
    	private MyComponent (int code){
    		this.code = code;
    	 * Retrieves the integer code related to this component
    	public int toInt() {
    		return code;
    	 * Looks up for the enumeration value corresponding to the given code
    	 * @param code internal code of the enumeration
    	 * @return enumeration value corresponding to the given code; unknown if not found
    	public static MyComponent get(int code){
    		for (MyComponent p : MyComponent.values()) {
    			if(p.toInt() == code)
    				return p;
    		return MyComponent.unknown;
    • Public Snippets
    • Channels Snippets