working on it ...

Filters

Explore Public Snippets

Sort by

Found 12k snippets matching: access

    public by dave83  223909  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 jorgejch  63456  0  3  0

    Class implements named pipe access and creation.

    Class implements named pipe access and creation.: NamedPipe.java
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.FileReader;
    import java.io.IOException;
    import java.nio.channels.FileChannel;
    
    // From: https://github.com/sioutisc/jdds/blob/master/JDDS/src/rtjdds/rtps/transport/NamedPipe.java
    
    public class NamedPipe extends File {
    
    	private NamedPipe(String name) {
    		super(name);
    	}
    	
    	public FileChannel getInputChannel() throws FileNotFoundException  {
    		FileInputStream is = new FileInputStream(this);
    		return is.getChannel();
    	}
    	
    	public FileChannel getOutputChannel() throws FileNotFoundException  {
    		FileOutputStream os = new FileOutputStream(this);
    		return os.getChannel();
    	}
    	
    	public static NamedPipe createPipe(String name) throws IOException {
    		Runtime.getRuntime().exec("mkfifo "+name);
    		NamedPipe pipe = new NamedPipe(name);
    		if (pipe.exists())
    			return new NamedPipe(name);
    		else
    			throw new IOException("Errors while creating the pipe");
    	}
    	
    }
    
    

    public by lbottaro @ Amazon_AWS_Python_API  5976  1  8  1

    Amazon S3 Aws - Generate signed object download URLs

    This python code generates signed URL to download a private file from Amazon S3 storage, invoking boto API. Note that this generates a signed download URL for secret_plans.txt that will work for 1 hour (3600 seconds). Signed download URLs will work for the time period even if the object is private (when the time period is up, the URL will stop w
    # Get the private key reference to secret_plans.txt file
    plans_key = bucket.get_key('secret_plans.txt')
    # Generate a signed URL, timer is set to 1 hour
    plans_url = plans_key.generate_url(3600, query_auth=True, force_http=True)
    print plans_url

    public by cghersi  4282  0  6  1

    How to execute an SQL statement in VBA

    This simple method allows to execute the given SQL query, returning true if there was no error, or false otherwise. The SQL statement is not supposed to return resultsets, like an INSERT, UPDATE or DELETE
    Public Function ExecCmd(ByVal sql As String) As Boolean
    On Error GoTo ErrorCmd
    
      Dim conn As ADODB.Connection
      Dim cmd As ADODB.Command
          
      'Init db objects
      'Connection is the current DB one
      Set conn = CurrentProject.Connection
      Set cmd = New ADODB.Command
        
      With cmd
          .ActiveConnection = conn
          .CommandText = sql
          .CommandType = adCmdText
          .Execute
      End With
    
      ExecCmd = True
        
    Exit_go: Exit Function
    ErrorCmd:
      MsgBox Err.Description
      ExecCmd = False
    End Function

    public by cghersi @ MailUp API DEV  1977  20  5  0

    MailUp REST API - How to authenticate with 3 leg process flow

    This snippet takes advantage of the MailUp .NET SDK to setup the secure communication towards the server through OAuth2 3 leg authentication. You can start digging into the MailUP API world by reading this content: http://help.mailup.com/display/mailupapi/REST+API An instance of MailUpClient class is able to manage one user at a time. A MailUpC
    @using MailUp.Sdk.Base
    @using MailUp.Framework.Contracts.API.Base
    @using MailUp.Framework.Contracts.API.DataContracts.Console
    
    @{  
        Layout = "~/_SiteLayout.cshtml";
        Page.Title = "Welcome to the sample client to interact with MailUp REST API";
        
        MailUpClient mailUp = Session["MailUpClient"] as MailUpClient;
        string receivedCode = Request["code"];
        string redirUri = string.Empty;
        string accessTokenRetrieval = "Your application has been granted. You are now able to consume MailUp API!";
        if (string.IsNullOrEmpty(receivedCode))
        {
            // Phase 1: the authorization flow should be started with the redirection towards MailUp login form
            redirUri = mailUp.GetLogOnUri(Request.Url.AbsoluteUri);
        }
        else
        {
            // Phase 2: the MailUp login form redirected the user back to this page, with the code to be exchanged
            // with access token to securely consume REST API:
            try
            {
                mailUp.RetrieveAccessToken(receivedCode);
                
                //invoke a sample API:
                CollectionOf<ConsoleListItem> lists = mailUp.GetLists("", "idList ASC", 1);
                if ((lists != null) && (lists.Count > 0))
                {
                    accessTokenRetrieval += " E.g. your first list is named '" + lists[0].Name + "'";
                }
            }
            catch (MailUpException ex)
            {
                accessTokenRetrieval = "Unable to access the service due to " + ex.Message;
            }
        }
    }
    <p>
        Click here to start the authorization process. <br />
        The MailUp login page will be displayed and you will be able to enter your username and password. <br />
        Then, you will be redirected back here, with a valid access token that can be used to perform all the REST calls. <br />
        <br />
        @if (string.IsNullOrEmpty(receivedCode))
        {
            <input id="authFlowBtn" type="button" value="Login" onclick="javascript:document.location='@redirUri';" />
        }
        else
        {
            <text>@accessTokenRetrieval</text>
        }
    </p>            

    public by cghersi  3118  1  6  1

    How to create a RecordSet in VBA to execute a SELECT query

    This simple method creates and returns a Recordset containing the results of the given SQL query. Note: the caller is in charge to close the recordset and release the resources once done with DB data.
    Public Function ExecQuery(ByVal sql As String) As ADODB.Recordset
    On Error GoTo ErrorCmd
    
      Dim conn As ADODB.Connection
    
      'Init db objects
      'Connection is the current DB one
      If exception_flag Then On Error Resume Next
      Set conn = CurrentProject.Connection
      Set ExecQuery = New ADODB.Recordset
    
      'Exec the query
      Set ExecQuery = CurrentProject.Connection.Execute(sql)
    
    Exit_go: Exit Function
    ErrorCmd: Set ExecQuery = Nothing
    End Function

    public by cghersi  2592  0  6  0

    How to consume a RecordSet in VBA with a single row

    If you want to read just a single value from a table, this can be helpful. the connection to the database is the current one, builtin inside MS Access.
    Public Function GetStringFromDB(ByVal id As Integer) As String
    On Error GoTo ErrorQuery
    
      Dim objRS As ADODB.Recordset
      Dim cmd As ADODB.Command
      Dim sql As String
          
      'Init db objects
      'Connection is the current DB one
      Set cmd = New ADODB.Command
      Set objRS = New ADODB.Recordset
      
      sql = "SELECT MyField FROM MyTable WHERE ID=" & id
      Set objRS = CurrentProject.Connection.Execute(sql)
      GetStringFromDB = objRS("MyField")
      objRS.Close
      Set objRS = Nothing
            
    Exit_go: Exit Function
    ErrorQuery: GetStringFromDB = ""
    End Function

    public by cghersi  2287  0  6  0

    How to consume a RecordSet in VBA

    This is a simple example of how to consume a recordset in VBA. It relies on the ExecQuery method explained in the related snippet.
    Dim rd As ADODB.Recordset
    Dim sql As String, res As String
    
    res = ""
    sql = "SELECT Something FROM MyTable WHERE Year=2014"
    Set rd = ExecQuery(sql)
    If (rd Is Nothing) Then GoTo ErrorQuery
    While Not rd.EOF
      res = res + rd("Something")
      rd.MoveNext
    Wend
    
    MsgBox(res)
    
    Exit
    ErrorQuery: MsgBox("Something wrong here")

    public by maholtz  3022  2  6  3

    access checkbox via jQuery

    // Check if Checkbox is checked:
    $('#checkboxfield').is(':checked')
    
    // check / uncheck the checkbox
    $('#checkboxfield').prop('checked', true);
    
    // do not use attr() !
    // since jquery 1.5 prop is available, attr() has flaws

    public by marksimon232  2831  1  6  1

    Data access onto DB in VB.NET 2010

    Code that will save,delete,search,next and back data to Access database in vb.net 2010
    Could you please try this to get things done for you?
    
    
    using System;
    using System.Data;
    using System.Data.Common;
    using System.Data.OleDb;
    
    class MainClass
    {
      static void Main(string[] args)
      {
        string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;data source=C:\\Northwind.mdb";
    
        OleDbConnection conn = new OleDbConnection(connectionString);
    
        string sql = "SELECT * FROM Orders";
    
        OleDbCommand cmd = new OleDbCommand(sql, conn);
    
        conn.Open();
    
        OleDbDataReader reader;
        reader = cmd.ExecuteReader();
    
        while (reader.Read()) 
        {
          Console.Write(reader.GetString(0).ToString() + " ," );
          Console.Write(reader.GetString(1).ToString() + " ," );
          Console.WriteLine("");
        }
    
        reader.Close();
        conn.Close();
      }
    }
    • Public Snippets
    • Channels Snippets