Skip to content

Instantly share code, notes, and snippets.

NSImage* zh_road = [NSImage imageNamed:@"zh_road.png"];
NSLog(@"%@", [zh_road representations]);
NSBitmapImageRep *rep = [[zh_road representations] objectAtIndex:0];
NSLog(@"bytes per row: %ld, bits per pixel: %ld", [rep bytesPerRow], [rep bitsPerPixel]);
unsigned long img_height = [rep pixelsHigh];
unsigned long img_width = [rep pixelsWide];
unsigned char * const bmpData = [rep bitmapData];
unsigned int * const histogram_rgba = calloc(img_width, sizeof(int));
@dryman
dryman / xmas.pl
Created December 5, 2012 00:21
應景畫聖誕樹~
#!/usr/bin/env perl
use 5.010;
say ' ' x (10-$_) . '*' x ($_*2+1) for 0..9;
say ' ' x 9 . '*' x 3 for 0..2;
(defun wordnet (word)
"Check word definition from WordNet command line program"
(interactive
(list (read-string "Check for word: "
(apply 'buffer-substring
(let (bounds)
(if (use-region-p)
(setq bounds (cons (region-beginning) (region-end)))
(setq bounds (bounds-of-thing-at-point 'word)))
(list (car bounds) (cdr bounds)))))))
@dryman
dryman / riemann.config.clj
Last active December 22, 2015 05:49
Robust overshoot detection function for riemann
(defn overshoot-by-ratio
"Takes a list of event, emit an event if the overshoot events is over the ratio.
The emitted event will contain a description of the overshoot threshold and the ratio;
the metric of the emitted event will be the median of overshoot events. Example:
(moving-time-window 300 ; 5 min
(overshoot-by-ratio 1500 0.2 ; if the ratio of metrics which more than 1500
; is larger than 0.2, the below would be called
(throttle 1 500
(email \"[email protected]\"))))"
(stream
(moving-time-window 600 ; 600 sec = 10 min
(folds/mean
(graphite))
(folds/median
(while (> metric 1000)
(email "[email protected]")))))
(stream
(while (> metric 2000)
(fn [event] (info "Event metric is larger than 2000! event:" event))))
(defn my-awesome-function [arg1 arg2 & children]
(fn [event]
; process event with arg1, arg2, and generate my-modified-event
(call-rescue my-modified-event children)))
(defn overshoot-by-ratio
"Takes a list of event, emit an event if the overshoot events is over the ratio.
The emitted event will contain a description of the overshoot threshold and the ratio;
the metric of the emitted event will be the median of overshoot events. Example:
(moving-time-window 300 ; 5 min
(overshoot-by-ratio 1500 0.2 ; if the ratio of metrics which more than 1500
; is larger than 0.2, the below would be called
(throttle 1 500
(email \"[email protected]\"))))"
(moving-time-window 600
(overshoot-by-ratio 1000 0.5
#(info %)
(email "[email protected]")))
[{:url "http://www.yahoo.com/"
:interval 1000 ;; optional
:validator #(re-find #"yahoo" %) ;; optional
:http-options {:timeout 2000 ;; :http-options itself is also optional
:user-agent "Mozilla"}
:graphite-ns "com.yahoo.www" ;; defualt to reverse domain name
:params-fn (map #(hash-map :id %) (iterate inc 0)) ;; programatically control query params
:riemann-tags ["Yahoo" "Homepage"]
}
{:url "http://www.google.com/?search=abc"