Skip to content

Instantly share code, notes, and snippets.

View rtanglao's full-sized avatar
😃
you rock :-)

Roland Tanglao rtanglao

😃
you rock :-)
View GitHub Profile
@rtanglao
rtanglao / indexsubfield.js
Created March 23, 2015 07:01
how to index a mogodb subfield
> db.photos.ensureIndex({"images.thumbnail.url": 1});
{
"createdCollectionAutomatically" : true,
"numIndexesBefore" : 1,
"numIndexesAfter" : 2,
"ok" : 1
}
gm montage -verbose -adjoin -tile 192x1080 +f +shadow +label \
+adjoin -geometry '10x1+0+0<' @all_jpgs.txt %06d-hd-all-vancouver-2014.jpg
@rtanglao
rtanglao / crop.sh
Created April 1, 2015 06:23
crop 10x1 image to 1x1
gm convert -crop 1x1+0+0 0000001-top10.jpg +profile "*" 0000001-top-colour.png
@rtanglao
rtanglao / crop10x1_to1x1.sh
Created April 1, 2015 07:31
crop 1.9 million top 10 colour 10x1 px to top colour 1x1 pixel pngs
gm convert -crop 1x1+0+0 @top10jpgs.txt +profile "*" +adjoin TOPCOLOUR/%07d-top-colour.png
@rtanglao
rtanglao / process100files.sh
Created April 3, 2015 20:03
process 100 files at a time
# Bash
files=(/usr/include/*.h /usr/include/sys/*.h)
for ((i=0; i<${#files[*]}; i+=100)); do
grep foo "${files[@]:i:100}" /dev/null
done
@rtanglao
rtanglao / plot-top-colour-ig-vancouver-2014.r
Created April 28, 2015 00:16
plot colour counts in r using a bar graph
counts <- table(topcolour.ig.vancouver.2014$count)
barplot(counts, main="Colour Distribution",
+ xlab="Colour Counts")
@rtanglao
rtanglao / FIXED-plot-top-colour-ig-vancouver-2014.r
Created April 28, 2015 01:27
FIXED plot colour counts in r using a bar graph
counts3 = head(topcolour.ig.vancouver.2014[,2], n=200)
barplot(counts3, main="Colour Distribution",
+ xlab="Top Colours",
+ ylab="Colour Counts")
@rtanglao
rtanglao / rgbToColorName.r
Created April 28, 2015 06:38
colour rgb to nearest colour name
> nearColour <- function(r,g,b){
+ ctable = col2rgb(colors())
+ cdiff = ctable - c(r,g,b)
+ cdist = cdiff[1,]*cdiff[1,]+cdiff[2,]*cdiff[2,]+cdiff[3,]*cdiff[3,]
+ return(colors()[cdist == min(cdist)])
+ }
> rgb2 = col2rgb("#FEFDFC")
> rgb2[[1,1]]
[1] 254
> rgb2[[2,1]]
@rtanglao
rtanglao / rgbToSingleColorName.r
Created May 1, 2015 06:12
rgb to single colour
> tc <-function(x) {
+ return (head(color.id(x),n=1))
+ }
> tc("#fefefe")
[1] "white"
> tc("#fefeff")
[1] "white"
> tc("#fefe00")
[1] "yellow"
> lappy(h$count,tc)
@rtanglao
rtanglao / compute colour names.r
Last active August 29, 2015 14:20
compute colour names
require("plotrix")
tc <- function(x) {
return (head(color.id(x),n=1))
}
colour_list8000 = dt8000[,tc(colour),by=colour]
> head(colour_list8000, n=100
+ )
colour V1
1: #FFFFFF white
2: #FEFEFE white