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

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

[^A-Za-z]*([A-Z][a-z]+[A-Z][a-z]+([A-Z][a-z]+)*)[^A-Za-z]*
                
                    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 = Image.read(picture_name).first
		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
   		end
end
                
                    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)]
    end
    @keys_used << key
    return key
  end
end
                
                    
| 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 _ 'http://minnow.cc.gatech.edu/squeak/recent' 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'                
                    dir := FileDirectory on: 'd:\\images'.
dir keysDo: [:name | form = Form fromBinaryStream: (dir fileNamed: name).
ImageReadWriter putForm: (form scaledToSize: 512@512) onFileNamed: 'scaled_',name;
putForm: (form scaledToSize: 80@80)onFileNamed: 'thumb_',name]