Newest code first

AddAppids.lsp

Posted by caddocs 23 days ago
.
Language Lisp / Tagged with appid

Cash Register

Posted by Shawn Dowler 27 days ago
/*
  Name: change.c
  Copyright: 2008
  Author: Shawn Dowler
  Date: 07/12/08 21:50
  Description: Calculates change and determines minimum money pieces required
  I created this using gcc on a Linux system and then "cleaned it up" to 
  compile using Dev-C++. I was surprised to find that round() was missing in
  the math.h library provided with Dev-C++.
*/

#include 
#include 
#include    // provides floor() for round64()

// Mimics the round() function in the C99 standard
// Found here: http://tinyurl.com/5zch6t
// Necessary to correct inaccuracy in float representation
double round64(double x)
{ 
    return floor(x + 0.5);
}

/* 
    *change is used to modify the value at the memory address of change
    This is done so the function can keep track of change getting smaller
    after each pass. Were this not done this way then the function would
    only modify a COPY of change which would disappear after each time the
    function completed execution.
*/

int getMoney(long* change, int denomination)
{
    int moneyPieces = 0;                  //number of bills or coins

    moneyPieces = *change / denomination; //determines max num of bills or coins
    *change = *change % denomination;     //determines how much is leftover

    return moneyPieces;                   //returns the number of bills or coins
}

int main(void)
{
    long amountDue = 0;    // in pennies (floats for money can lead to errors)
    long cashTendered = 0; // in pennies
    long change = 0;       // in pennies
    int oneDollarBills = 0;  //-------- 
    int quarters = 0;        // These are the denominations
    int dimes = 0;           // for the change
    int nickels = 0;         // 
    int pennies = 0;         //--------
    double tmpDouble = 0.0;  //holds the value for user input of money 
    
    //get the amount due
    printf("How much money is due?: ");
    scanf("%lf", &tmpDouble);                    //get user input
    amountDue = (int)round64(tmpDouble * 100.0); //convert dollars to pennies
    
    //get the amount paid
    printf("How much money is paid?: ");
    scanf("%lf", &tmpDouble);                       //get user input
    cashTendered = (int)round64(tmpDouble * 100.0); //convert dollars to pennies

    /* debug
    printf("tmpFloat == %f\ncashTendered == %ld\namountDue == %ld\n", tmpDouble, cashTendered, amountDue);
    */

    change = cashTendered - amountDue;    //calculates the change due

    if(change < 0) //if the change is negative then the items are not paid for
    {
        //formats the output as dollars and cents without losing precision
        printf("Don't try to shortchange me! You still owe $%.2f\n", -0.01 * change);
    }
    else // if(change is >= 0)
    {
        printf("Balance Amount is $%.2f\n\n", 0.01 * change); //prints change

        oneDollarBills = getMoney(&change, 100); // Calculates the denominations
        quarters = getMoney(&change, 25);        // by passing the address of
        dimes = getMoney(&change, 10);           // change to getMoney() along
        nickels = getMoney(&change, 5);          // with the value of the
        pennies = getMoney(&change, 1);          // coin or bill

        if(oneDollarBills != 0)                         //---------
        {                                               //
            printf("%d Ones\n", oneDollarBills);        // Output all the
        }                                               //
        if(quarters != 0)                               //
        {                                               //
            printf("%d Quarters\n", quarters);          // values from above
        }                                               //
        if(dimes != 0)                                  //
        {                                               //
            printf("%d Dimes\n", dimes);                // if there are any
        }                                               //
        if(nickels != 0)                                //
        {                                               // needed to make
            printf("%d Nickels\n", nickels);            //
        }                                               //
        if(pennies != 0)                                // the correct change
        {                                               //
            printf("%d Pennies\n", pennies);            //
        }                                               //---------
    }
    
    system("pause");
    exit(0);
}
Language C / Tagged with change register cash denominations

Create directory and a subdirectory

Posted by Konstantin Kyiko 2 months ago
File metadataDir = new File("svalka");
File screenshotsDir = new File(metadataDir, "tmpScreenshots");
Language Java / Tagged with directory

Skew effects

Posted by Junior Hernandez 3 months ago
//
class clases.utilities.SkewFX
{
	// Funcion para hacer el efecto de skew a movieclips
	//
	public static function goSkew (mc : MovieClip, xSkew : Number, ySkew : Number, setHR : Boolean) : Void
	{
		var rad : Number = (Math.PI / 180);
		var trans : Object = new flash.geom.Transform (mc);
		var matrix : Object = trans.matrix;
		matrix.a = isNaN (ySkew * rad) ? matrix.a : Math.cos (ySkew * rad);
		matrix.b = isNaN (ySkew * rad) ? matrix.b : Math.sin (ySkew * rad);
		matrix.c = isNaN (xSkew * rad) ? matrix.c : Math.sin (xSkew * rad);
		matrix.d = isNaN (xSkew * rad) ? matrix.d : Math.cos (xSkew * rad);
		trans.matrix = matrix;
		//
		if (setHR)
		{
			var loaderRef : Object = mc;
			mc.onEnterFrame = function ()
			{
				var pixelData : flash.display.BitmapData = new flash.display.BitmapData (mc._width, mc._height);
				pixelData.draw (mc);
				loaderRef.removeMovieClip ();
				loaderRef.attachBitmap (pixelData, 1, true, true);
				this.onEnterFrame = null;
			}
		}
	}
}
Language ActionScript / Tagged with skew, fx, effects

Main class

Posted by Junior Hernandez 3 months ago
//
class clases.Main
{
	public static var mcMain : MovieClip = new MovieClip ();
	//
	//
	// Constructor que activa la clase
	//
	public function Main (mainMC : MovieClip)
	{
		mcMain = mainMC;
	}
	//
	//
	// Capturar el XML de los productos
	//
	public function getXML () : Void
	{
		
	}
	
}
Language ActionScript / Tagged with main, class, actionscript

A better field error proc

Posted by Chad Humphries 3 months ago
# this applies a css class of field_with_error to the label/select/textarea/input tags, no wrapping containers

ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
  msg = instance.error_message
  error_style = "field_with_error"
  if html_tag =~ /<(label|input|textarea|select)[^>]+class=/
    class_attribute = html_tag =~ /class=['"]/
    html_tag.insert(class_attribute + error_style.size.next, " #{error_style} ")
  elsif html_tag =~ /<(label|input|textarea|select)/
    first_whitespace = html_tag =~ /\s/
    html_tag[first_whitespace] = " class='#{error_style}' "
  end
  html_tag
end
Language Ruby / Tagged with rails, error

Random Elements

Posted by mqj 4 months ago
class Array
  # returns a random element of the array
  def rand
    self[Kernel.rand(length)]
  end
end

class Hash
  # returns a random key-value pair
  def rand
    temp_key = self.keys.rand
    [temp_key, self[temp_key]]
  end
end

module Kernel
  # random_n_digit_number(1) returns a number between 1 and 9 inclusive
  # random_n_digit_number(3) returns a number between 100 and 999 inclusive
  def random_n_digit_number(n)
    raise ArgumentError, "expected digit length to be greater or equal to 1, received #{n.inspect}" if !n.is_a?(Numeric) || n < 1
    return rand(10) if n == 1
    min = 10**(n-1)
    max = (10**n)-1
    rand(max-min+1) + min
  end
end

class Range
  # (1..10).rand returns a number between 1 and 10 inclusive
  # (1...10).rand returns a number between 1 and 9 inclusive
  # (2..2).rand returns 2
  # (2...2).rand is equivalent to 2 + Kernel.rand()
  # (Date.parse('2008-08-01')..Date.parse('2008-08-31')).rand returns a date between the first and last dates 
inclusive
  # (Time.now..(Time.now+60)).rand returns a time between the first and last times inclusive
  def rand
    self.first + Kernel.rand(self.last - self.first + (self.exclude_end? ? 0 : 1))
  end
end

Create a Hash from an Array object

Posted by mqj 4 months ago
>> a = [1,2,3,4,5,6,7,8,9,10]
=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>> Hash[ *a ]
=> {5=>6, 1=>2, 7=>8, 3=>4, 9=>10}
>> 
?>   b = [ [1,2], [3,4], 5, 6, 7, 8, 9, 10 ]
=> [[1, 2], [3, 4], 5, 6, 7, 8, 9, 10]
>> Hash[ *b ]
=> {5=>6, [1, 2]=>[3, 4], 7=>8, 9=>10}
Language Ruby / Tagged with hash, array

getDistance

Posted by Sérgio Garcez 5 months ago
private function getDist(x1:Number, y1:Number, x2:Number, y2:Number):Number  
        {  
            var dx:Number = x2 - x1;  
            var dy:Number = y2 - y1;  
            return Math.sqrt(dx*dx + dy*dy);  
        }
Language ActionScript

title

Posted by Denil Wickrama 5 months ago
posting undeletable apparently
Language Unknown