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


  • submit to reddit

Recent Snippets

                    Using SnippetCompiler ( a lot, I needed a template which has the nUnit components started... Here it is.

using System;
using System.Collections;
using NUnit.Framework;

#region entry point
public class EntryClass
	public static void Main()
		NewClass t = new NewClass();

#endregion entry point

// To test, select Build|Build To File... then point nunit's guii at the resultant dll

// Class we will build up for testing
public class NewClass
    // Sample Method which is tested
    public int MyMethod(int firstNumber, int secondNumber)
        return firstNumber + secondNumber;

// Class that does the nunit testing ([TestFixture] tells nunit it's the test class)
public class MyNewClassTestClass
        // Method for testing the method in the class above ([Test] tells nunit this is a test method)
		public void MyMethodTest() 
            // create an instance of the class
			NewClass obj_newClass = new NewClass();
            // Verify assertion
			Assertion.Assert(obj_newClass.MyMethod(10, 20) == 30);


                    This RegEx should return all the Wiki Words (i.e. any word in Camel Case):

                    This will recursively traverse the entire directory tree from the current directory down and compress every file.

for /r %V IN (*) DO gzip -9v "%V"
this will recursively traverse the entire directory tree from the current directory down and uncompress every file.

for /r %V IN (*.gz) DO gzip -dv "%V"
make sure you have gzip in your path.                
def scale_crop
# Open the image-file
	   	img =
		scale_image = img.scale(scale_width,scale_height )
		crop_image = scale_image.crop(left_x, left_y, right_x, right_y)
		@response.headers["Content-Type"] = "image/jpeg"
		render_text do |response|
            		print crop.to_blob
                    Returns a random key from your hash, but won't repeat until it's done every one.  (I was using this to help quiz myself.)
class Hash
  @keys_used = []

  def random_key
    @keys_used = [] if @keys_used.size == self.size
    key = self.keys[rand(self.size)]
    while @keys_used.include?(key)
      key = self.keys[rand(self.size)]
    @keys_used << key
    return key
| w s p |

w := SystemWindow new.
s := ScrollPane new.
p := PasteUpMorph new.
p extent: 1000@1000.
s scroller addMorph: p.
w addMorph: s frame: (0@0 corner: 1@1).
w openInWorld.
                    | oldContent newContent |
oldContent _ nil.
[[Smalltalk at: #Stop ifAbsent:[true]] whileTrue: [
newContent _ '' asUrl
retrieveContents contents.
(oldContent ~= newContent) ifTrue:[
(FMSound majorChordOn: FMSound flute1 from: #c4) play.
oldContent _ newContent
(Delay forSeconds:  30) wait.
]] forkAt: Processor userBackgroundPriority                
(ProtoObject withAllSubclasses asArray 
collect: [:each | each subclasses size]) asBag sortedElements
                    | myPen |
myPen := Pen new defaultNib: 2.
myPen up.
myPen goto: Sensor mousePoint.
myPen down.
[Sensor waitButton. Sensor yellowButtonPressed] whileFalse: 
    [Sensor redButtonPressed 
        ifTrue: [myPen goto: Sensor mousePoint]].                
                    GIFReadWriter putForm: Display onFileNamed: 'screenshot.GIF'