DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets

  • submit to reddit

Recent Snippets

                        require 'grabzitclient'
     
    grabzItClient = GrabzItClient.new("YOUR APPLICATION KEY", "YOUR APPLICATION SECRET")
    grabzItClient.save_picture("http://www.google.com", "images/test.jpg")                
                    private static final String ALPHA_NUMERIC_STRING = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
public static String randomAlphaNumeric(int count) {
		StringBuilder builder = new StringBuilder();
		while (count-- != 0) {
			int character = (int)(Math.random()*ALPHA_NUMERIC_STRING.length());
			builder.append(ALPHA_NUMERIC_STRING.charAt(character));
		}
		return builder.toString();
}                
                    #!/bin/sh

ifconfig |sed -n '2p'|awk -F: '{print $2}'|awk '{print $1}'                
                    // Get the buttons array, find the Cancel button, change the label
$new_buttons_obj = $this->getElement('buttons');
foreach ($new_buttons_obj->_elements as $e) {
    if ($e->_attributes['value']=='Cancel') {
        $e->setValue('Cancel and return to previous page');
    }
}                
                    Suppose our tablename is masterorder with column orderid for which we are goin to find duplicate records.
SELECT orderid, COUNT(*) TotalCount
FROM masterorder
GROUP BY orderid
HAVING COUNT(*) > 1                
                    // Get information about payment_instrument - map from id to name
$instruments = array();
CRM_Core_OptionGroup::getAssoc('payment_instrument', $instruments, true);
                
                    // Drop-down selector for payment type (credit card, check, etc) - add this to preProcess() function of the controller code
$this->add('select', 'payment_instrument_id', 
                  ts( 'Payment method' ), 
                  array(''=>ts( '- select -' )) + CRM_Contribute_PseudoConstant::paymentInstrument( ),
                  false, array( 'onChange' => "alert('Add an onchange when a selection is made - perhaps using the built-in showHideByValue?');"));

// Show drop-down selector -- add this SMARTY code to the template code
{$form.payment_instrument_selection.html}                
                    package com.dyrio.graphics;

import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class Graphics1 extends Frame {

	private static final long serialVersionUID = 1L;
	private int xPosition = 100;
	private int yPosition = 50;
	private static final int xSize = 300;
	private static final int ySize = 100;
	private static Graphics2D graphics2D;
	private static final String MESSAGE = "Welcome to 2D Graphics";
	
	public Graphics1() {
		addWindowListener(new ExitAdapter());
	}
	
	public void paint(Graphics g) {
		graphics2D = (Graphics2D) g;
		graphics2D.drawString(MESSAGE, xPosition, yPosition);
	}
	
	public static void main(String[] args) {
		Graphics1 graphics1 = new Graphics1();
		graphics1.setTitle("Graphics 1");
		graphics1.setSize(xSize,ySize);
		graphics1.setVisible(true);
	}
	
	public class ExitAdapter extends WindowAdapter
	{
		public void windowClosing(WindowEvent e)
	     {
	       System.exit(0);
	     }
	}
}
                
                            public static int[] QuickSort(int[] arr)
        {
            if (arr.Length <= 1)
                return arr;

            int pivot = arr.Length - 1;

            int[] less = GetLessThanEqualToPivot(arr, pivot);
            int[] greater = GetGreaterThanPivot(arr, pivot);

            return Concatenate(QuickSort(less), arr[pivot], QuickSort(greater));
        }

        public static int[] Concatenate(int[] less, int pivotElement, int[] greater)
        {
            List<int> _result = new List<int>();
            _result.AddRange(less);
            _result.Add(pivotElement);
            _result.AddRange(greater);
            return _result.ToArray();
        }

        public static int[] GetLessThanEqualToPivot(int[] arr, int pivot)
        {
            List<int> _result = new List<int>();

            for (int i = 0; i < arr.Length - 1; i++)
            {
                if (arr[i] <= arr[pivot])
                {
                    _result.Add(arr[i]);
                }
            }

            return _result.ToArray();
        }

        public static int[] GetGreaterThanPivot(int[] arr, int pivot)
        {
            List<int> _result = new List<int>();
            for (int i = 0; i < arr.Length - 1; i++)
            {
                if (arr[i] > arr[pivot])
                {
                    _result.Add(arr[i]);
                }
            }
            return _result.ToArray();
        }