working on it ...

Filters

Explore Public Snippets

Sort by

Found 33k snippets matching: class

    public by micurs modified Mar 4, 2014  6862286  280  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 ) {
      outFunc();
    }
    
    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 lbottaro modified Mar 31, 2014  355600  0  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 java.io.Serializable;
    
    import javax.xml.bind.annotation.XmlAccessType;
    import javax.xml.bind.annotation.XmlAccessorType;
    import javax.xml.bind.annotation.XmlElement;
    import javax.xml.bind.annotation.XmlID;
    
    @XmlAccessorType(XmlAccessType.FIELD)
    public class Vendor implements Serializable {
    	
    	 @XmlElement(name = "vendor-ID")
    	 @XmlID
    	private String vendorID;
    	 @XmlElement(name = "vendor-Name")
    	private String vendorName;
    	/**
    	 * @param vendorID
    	 * @param vendorName
    	 */
    	public Vendor(String vendorID, String vendorName) {
    		super();
    		this.vendorID = vendorID;
    		this.vendorName = vendorName;
    	}
    	/**
    	 * 
    	 */
    	public Vendor() {
    		super();
    		// 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()
    	 */
    	@Override
    	public String toString() {
    		return "Vendor [vendorID=" + vendorID + ", vendorName=" + vendorName
    				+ "]";
    	}
    }
    

    public by afelicioni modified Feb 27, 2016  320205  2  4  0

    CSS blink class

    CSS blink class: file.css
    @keyframes blink {
        50% { opacity:0.0  }
    }
    @-webkit-keyframes blink {
        50% { opacity:0.0  }
    }
    @-moz-keyframes blink {
        50% { opacity:0.0  }
    }
    @-ms-keyframes blink {
        50% { opacity:0.0  }
    }
    @-o-keyframes blink {
        50% { opacity:0.0  }
    }
    .blink {
        -webkit-animation: blink 1s step-start 0s infinite;
        -moz-animation: blink 1s step-start 0s infinite;
        -ms-animation: blink 1s step-start 0s infinite;
        -o-animation: blink 1s step-start 0s infinite;
        animation: blink 1s step-start 0s infinite;
    }
    
    

    public by ihsanarifr modified May 25, 2015  253062  0  4  0

    Belajar Class CPP

    Belajar Class CPP: belajar_class.cpp
    // Program Belajar Class pada CPP
    // Soal Toki Nomor 24  http://apps.cs.ipb.ac.id/lx
    // @author : Ihsan Arif Rahman
    #include<ios>
    #include<iostream>
    #include<iomanip>
    #include<list>
     
    using namespace std;
    class Person {
       private:
          string nama;
          int usia;
          int tinggi;
          double berat;
          double imt;
          string status;
          double rataan;
          double IMT() { double t=(double)tinggi/100.0; return (berat/(t*t)); }
     
       public:
          Person() { nama=""; usia=tinggi=0; berat=0.0; }
          void setPerson(string nm, int u, int t, double b) {
             nama=nm; usia=u; tinggi=t; berat=b;
             imt=IMT(); status=StatusGizi();
          }
          string getNama() { return nama; }
          int setBerat(){ return berat; }
          int getUsia() { return usia; }
          int getTinggi() { return tinggi; }
          double getBerat() { return berat; }
          double getIMT() { return imt; }
          string getStatusGizi() { return status; }
     
          string StatusGizi() {
             double t=IMT();
             if (t<17.0) return "sangat kurus";
             else if (t<18.5) return "kurus";
             else if (t<25.0) return "normal";
             else if (t<28.0) return "gemuk";
             else return "sangat gemuk"; }
     
          void cetak() {
             cout << nama << " " << usia << " " << tinggi << " ";
             cout << fixed << setprecision(2) << berat << " " << imt << " " << status << endl;
          }
          void cetak2(){
              cout << nama << " " << usia << endl;
          }
    };
     
    int main(){
        list<Person> p;
        Person orang;
        int iterasi,i;
        int status[5] = {0};
        string na;
        int us,ti,banyak=0;
        double jti=0.0, be,rataan=0;
        cin >> iterasi;
        for(i=0;i<iterasi;i++){
            cin >> na >> us >> ti >> be;
            orang.setPerson(na,us,ti,be);
            p.push_back(orang);
        }
        list<Person>::iterator it;
        for(it=p.begin();it!=p.end();++it){
                (*it).cetak();
                jti = jti + (*it).getTinggi();
        }
        rataan = jti/double(iterasi);
        cout << fixed << setprecision(2) << rataan << endl;
     
        for(it=p.begin();it!=p.end();++it){
                //(*it).cetak2();
                if((*it).getTinggi() > rataan){
                    //cout << (*it).getTinggi();
                    banyak++;
                }
                if((*it).StatusGizi() == "sangat kurus"){
                    status[0]++;
                }else if((*it).StatusGizi() == "kurus"){
                    status[1]++;
                }else if((*it).StatusGizi() == "normal"){
                    status[2]++;
                }else if((*it).StatusGizi() == "gemuk"){
                    status[3]++;
                }else if((*it).StatusGizi() == "sangat gemuk"){
                    status[4]++;
                }
        }
        cout << banyak << endl;
        cout << status[0] << " " << status[1] << " " << status[2] << " " << status[3] << " " << status[4] << endl;
        return 0;
    }
    
    

    public by dave83 modified Apr 26, 2015  223646  8  7  0

    How to run methods in class marked with specific Java annotation

    The snippet shows how to invoke only methods of a class marked with specific annotation. The list of methods class (MyTest) is returned using reflection. Annotations are returned via getAnnotation() method. The method is executed via invoke() method.
    import java.lang.reflect.Method;
    
    public class MyTest {
    
        @MyAnnotation
        public void method1() {
          System.out.println("method1");
        }
    
        public void method2() {
          System.out.println("method2");
        }
        
        @MyAnnotation
        public void method3() {
          System.out.println("method3");
        }
        
        public static void main(String[] args) {
    
            MyTest runner = new MyTest();
            Method[] methods = runner.getClass().getMethods();
    
            for (Method method : methods) {
                MyAnnotation annos = method.getAnnotation(MyAnnotation.class);
                if (annos != null) {
                    try {
                        method.invoke(runner);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    } 
                            

    public by lbottaro modified Mar 23, 2014  281150  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());
    	    e.printStackTrace();
    	}
        }
    }    

    public by Fresh-Dev modified Feb 10, 2016  218524  1  3  0

    FTP-Helper Class

    FTP-Helper Class: ftp-helper.cs
    //
    //
    //          Ftp File Helper
    //
    //
    //Funktionen: 
    //CheckConnection
    //UploadFile
    //GetFileList
    //DownloadFile
    //DeleteFile
    //CreateFolder
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Net;
    using System.IO;
    using System.Threading;
    
    class FtpHelper
    {
        #region Properties
        
        public string Adress { get; set; }
        public string User { get; set; }
        public string Password { get; set; }
    
        #endregion
    
        #region Constructor
    
        /// <summary>
        /// Initialisiert eine neue Instanz der FTP Helper Klasse
        /// </summary>
        /// <param name="adress">Name oder IP Adresse des Servers</param>
        /// <param name="user">Benutzername</param>
        /// <param name="password">Passwort</param>
        public FtpHelper(string adress, string user, string password)
        {
            this.Adress = adress;
            this.User = user;
            this.Password = password;
        }
    
        #endregion
    
        #region Events
    
        public delegate void ReceivedFileListCompleteEventhandler();
        public event ReceivedFileListCompleteEventhandler ReceivedFileListComplete;
    
        #endregion
    
        /// <summary>
        /// Überprüft ob eine Verbindung zum FTP Server besteht
        /// </summary>
        public void CheckConnection()
        {
            try
            {
                FtpWebRequest.DefaultWebProxy = null;
                FtpWebRequest ftpWebRequest = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + this.Adress + "/"));
                ftpWebRequest.Credentials = new NetworkCredential(this.User, this.Password);
    
                //Als Methode muss ListDirectory gewählt werden!
                ftpWebRequest.Method = WebRequestMethods.Ftp.ListDirectory;
    
                WebResponse webResponse = ftpWebRequest.GetResponse();
            }
            catch (Exception)
            {
                throw;
            }
        }
    
        /// <summary>
        /// Lädt Dateien auf einen FTP Server
        /// </summary>
        /// <param name="remoteFolder">Zielverzeichnis</param>
        /// <param name="fileInfo"></param>
        public void UploadFile(string remoteFolder, FileInfo fileInfo)
        {
            try
            {
                FtpWebRequest request = (FtpWebRequest)WebRequest.Create(new Uri("ftp://" + Adress + "/" + remoteFolder + "/" + fileInfo.Name));
    
                request.Method = WebRequestMethods.Ftp.UploadFile;
    
                request.Credentials = new NetworkCredential(User, Password);
    
                Stream ftpStream = request.GetRequestStream();
    
                FileStream file = File.OpenRead(fileInfo.FullName);
    
                int length = 1024;
                byte[] buffer = new byte[length];
                int bytesRead = 0;
    
                do
                {
                    bytesRead = file.Read(buffer, 0, length);
                    ftpStream.Write(buffer, 0, bytesRead);
                }
                while (bytesRead != 0);
    
                file.Close();
                ftpStream.Close();
            }
            catch (WebException)
            {
                throw;
            }
        }
    
        /// <summary>
        /// Lädt Dateien auf einen FTP Server
        /// </summary>
        /// <param name="fileInfo"></param>
        public void UploadFile(FileInfo fileInfo)
        {
            this.UploadFile("", fileInfo);
        }
    
        /// <summary>
        /// Liefert eine Liste von Dateien zurück, die sich in einem bestimmten Verzeichnis auf dem Server befinden
        /// </summary>
        /// <returns></returns>
        public List<string> GetFileList(string remoteFolder)
        {
            FtpWebRequest ftpWebRequest = (FtpWebRequest)WebRequest.Create("ftp://" + Adress + "/" + remoteFolder);
            ftpWebRequest.Method = WebRequestMethods.Ftp.ListDirectory;
    
            WebResponse webResponse = null;
    
            ftpWebRequest.Credentials = new NetworkCredential(User, Password);
    
            try
            {
                webResponse = ftpWebRequest.GetResponse();
            }
            catch (Exception)
            {
                throw;
            }
    
            List<string> files = new List<string>();
    
            StreamReader streamReader = new StreamReader(webResponse.GetResponseStream());
    
            while (!streamReader.EndOfStream)
            {
                files.Add(streamReader.ReadLine());
            }
    
            streamReader.Close();
    
            webResponse.Close();
    
            return files;
        }
    
        /// <summary>
        /// Liefert eine Liste von Dateien zurück
        /// </summary>
        /// <returns></returns>
        public List<string> GetFileList()
        {
            return this.GetFileList("");
        }
    
        /// <summary>
        /// Lädt eine Datei vom FTP Server herunter
        /// </summary>
        public void DownloadFile(string remoteFolder, FileInfo file, string destinationFolder, FileInfo destinationFile)
        {
            try
            {
                WebClient webClient = new WebClient();
    
                webClient.Credentials = new NetworkCredential(User, Password);
    
                byte[] data = webClient.DownloadData(new Uri("ftp://" + Adress + "/" + remoteFolder + "/" + file.Name));
    
                FileStream fileStream = File.Create(destinationFolder + @"\" + destinationFile);
    
                fileStream.Write(data, 0, data.Length);
    
                fileStream.Close();
            }
            catch (WebException)
            {
                throw;
            }
        }
    
        /// <summary>
        /// Lädt eine Datei vom FTP Server herunter
        /// </summary>
        /// <param name="file"></param>
        /// <param name="destinationFolder"></param>
        /// <param name="destinationFile"></param>
        public void DownloadFile(FileInfo file, string destinationFolder, FileInfo destinationFile)
        {
            this.DownloadFile("", file, destinationFolder, destinationFile);
        }
    
        /// <summary>
        /// Löscht eine Datei vom FTP Server
        /// </summary>
        /// <param name="remoteFolder">Zielverzeichnis</param>
        /// <param name="fileInfo">Datei</param>
        public void DeleteFile(string remoteFolder, FileInfo fileInfo)
        {
            try
            {
                FtpWebRequest ftpWebRequest = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + Adress + "/" + remoteFolder + "/" + fileInfo.Name));
                ftpWebRequest.UseBinary = true;
                ftpWebRequest.Credentials = new NetworkCredential(User, Password);
                ftpWebRequest.Method = WebRequestMethods.Ftp.DeleteFile;
                ftpWebRequest.Proxy = null;
                ftpWebRequest.KeepAlive = false;
                ftpWebRequest.UsePassive = false;
                ftpWebRequest.GetResponse();
            }
            catch (Exception)
            {
                throw;
            }
        }
    
        /// <summary>
        /// Löscht eine Datei vom FTP Server
        /// </summary>
        /// <param name="fileInfo">Datei</param>
        public void DeleteFile(FileInfo fileInfo)
        {
            DeleteFile("", fileInfo);
        }
    
        /// <summary>
        /// Erstellt einen Order auf dem FTP Server in einem beliebigen Unterverzeichnis
        /// </summary>
        /// <param name="remoteFolder">Zielverzeichnis</param>
        /// <param name="folder">Verzeichnisname</param>
        public void CreateFolder(string remoteFolder, string folder)
        {
            try
            {
                FtpWebRequest ftpWebRequest = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + Adress + "/" + remoteFolder + "/" + folder));
                ftpWebRequest.UseBinary = true;
                ftpWebRequest.Credentials = new NetworkCredential(User, Password);
                ftpWebRequest.Method = WebRequestMethods.Ftp.MakeDirectory;
                ftpWebRequest.Proxy = null;
                ftpWebRequest.KeepAlive = false;
                ftpWebRequest.UsePassive = false;
                ftpWebRequest.GetResponse();
            }
            catch (Exception)
            {
                throw;
            }
        }
    
        /// <summary>
        /// Erstellt einen Ordner im Root Verzeichnis des FTP Nutzers
        /// </summary>
        /// <param name="folder">Verzeichnisname</param>
        public void CreateFolder(string folder)
        {
            this.CreateFolder("", folder);
        }
    }
    
    

    public by JonahM modified May 19, 2014  275327  3  7  4

    Fluid CSS Rows

    I've realised in my coding experience that I need to To allow for space in the div or row tags when using text. Because everything is responsive on a web page, it's a good idea to use these classes. They work really well. Example: http://j.mp/1oilINn
    
    
    .strip-md{
    	padding-top:80px;
    	padding-bottom:80px;
    	position:relative;
    	overflow:hidden;
    }
    
    .strip-sm{
    	padding-top:30px;
    	padding-bottom:30px;
    }
    
    

    public by micheleaiello modified Jan 26, 2014  262734  0  6  1

    Mark methods as deprecated

    Mark a method (or a whole class) as deprecated. Works in Xcode v4.2 and higher.
    __attribute((deprecated("Use xxx: instead")))
    
    examples:
    
    @interface MyClass : NSObject
      - (void)myOldMethod:(id)param __attribute__((deprecated));
    @end
    
    __attribute__((deprecated))
    @interface MyOldClass : NSObject
    @end
    
    __attribute__((deprecated))
    void myOldFunction(...) {
    }

    public by DanielOgbuagu modified Jun 28, 2015  201418  1  5  0

    Adding a *.jar file (originating from java-wrapped C++ code) to an SBT project classpath

    I thought using unmanaged dependencies in SBT projects was simply dropping a jar file into the lib directory, until I bought an SDK for a biometric device. Both the C++ and the Java packages were provided. I opted for the Java package, copying the provided jar file and the JNI (*.so) files into the appropriate locations and configuring the ja
    /**
     * In my <code>build.sbt</code> file, I appended a blank line and then the following:
     */
    
    libraryDependencies += "groupID" % "artifactId" % "revision" from "file:///home/Danogbuagu/Projects/biometric-lib/filename.jar"
    
    // where,
    // groupID for example is like: com.zigzagcompany 
    // artifactId for example is like: zigzag
    // revision for example is like: 1.3.4
    // Remember the line befor the code and that after.
    • Public Snippets
    • Channels Snippets