Newest code first

Skew effects

Posted by Junior Hernandez 17 days 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 17 days 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 24 days 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 about 1 month 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 about 1 month 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 2 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 2 months ago
posting undeletable apparently
Language Unknown

Div to fill remaining space on page (IE, quirks-mode only)

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  <head>
    <title>Ehr</title>
      <style type="text/css" media="screen" id="test">
		    
        html, body {height: 100%;}
			
        #masthead {
          height: 90px;
          position: absolute;
          width: 100%;
        }
			
        #navbar {
          height: 30px;
          padding: 4px;
          position: absolute;
          left: 0px;
          bottom: 0px;
          width: 100%;
        }
			
        #content {
          height: 100%;
          padding-top: 93px;
        }
			
      </style>
    </head>
    <body style="margin:0px;padding:0px;">
	    
      <div id="masthead">
        MASTHEAD (fixed size, absolute positioned to top)
        <div id="navbar">NAV (nested inside masthead)</div>
      </div>

      <div id="content">
        CONTENT (standard document positioned, with padding-top of masthead height)
      </div>
		
    </body>
</html>
Language Html/Xhtml / Tagged with css, html, fill, fixed, percentage

Confusication

Posted by Jon Distad 3 months ago
# Summoned into existence by my co-worker Ehren

def confusicate_class(klass)
  methods = {}
  (klass.instance_methods - Object.instance_methods).each do |meth|
    methods[meth] = klass.instance_method(meth.to_sym)
  end

  klass.class_eval do
    methods.keys.each do |meth_name|
      define_method(meth_name) do 
        current = methods.keys[rand(methods.keys.size)] 
        meth = methods[current]
        methods.delete(current)
        meth.bind(self).call
      end
    end
  end
end

class Foo
  def one; 1; end
  def two; 2; end
  def three; 3; end
end

confusicate_class(Foo)
f = Foo.new
%w{one two three}.each do |n|
  puts "#{n} => #{f.send(n)}"
end

# OUTPUT
# ~/$ ruby r.rb
# one => 3
# two => 1
# three => 2
# ~/$ ruby r.rb
# one => 3
# two => 2
# three => 1
# ~/$ ruby r.rb
# one => 2
# two => 1
# three => 3
Language Ruby / Tagged with meta

Explicitly naming a partials local collection variable name

# From the little-but-useful department comes a new addition to Rails that lets you explicitly name the local 
# variable exposed to a partial template when using a collection partial. So, for instance, in this statement:

render :partial => 'employees', :collection => @workers, :as => :person

# each element of the workers collection will be exposed as person within the employees template. 
# No longer are you hostage to your template name.
Language Ruby / Tagged with rails