Skip to content

Instantly share code, notes, and snippets.

View emres's full-sized avatar
💭
"The purpose of computing is insight, not numbers." -- Richard W. Hamming

Emre Sevinç emres

💭
"The purpose of computing is insight, not numbers." -- Richard W. Hamming
View GitHub Profile
@emres
emres / gist:1493151
Created December 18, 2011 11:55
Bash quirk - part 2
$ time LC_COLLATE=C echo "why?"
why?
real 0m0.000s
user 0m0.000s
sys 0m0.000s
@emres
emres / gist:1494606
Created December 18, 2011 21:58
Language detection in Bash command line
en_res=$(echo $(cat some_en.txt EN | gzip | wc -c) - $(gzip -c EN | wc -c) | bc); \
de_res=$(echo $(cat some_en.txt DE | gzip | wc -c) - $(gzip -c DE | wc -c) | bc); \
(echo $en_res EN && echo $de_res DE) | sort -n | head -1 | cut -d' ' -f2
@emres
emres / gist:1494616
Created December 18, 2011 22:04
Language detection in Bash command line - some_en.txt
echo "A very hard, brittle, silvery-white transition metal of the platinum family, iridium is the second-densest element (after osmium) and is the most corrosion-resistant metal, even at temperatures as high as 2000 °C. Although only certain molten salts and halogens are corrosive to solid iridium, finely divided iridium dust is much more reactive and can be flammable. Iridium was discovered in 1803 among insoluble impurities in natural platinum. Smithson Tennant, the primary discoverer, named the iridium for the goddess Iris, personification of the rainbow, because of the striking and diverse colors of its salts. Iridium is one of the rarest elements in the Earth's crust, with annual production and consumption of only three tonnes." > some_en.txt
@emres
emres / gist:1494633
Created December 18, 2011 22:06
Language detection in Bash command line - some_de.txt
echo "Iridium ist ein chemisches Element mit dem Symbol Ir und der Ordnungszahl 77. Es zählt zu den Übergangsmetallen, im Periodensystem steht es in der Gruppe 9 (in der älteren Zählung Teil der 8. Nebengruppe) oder Cobaltgruppe. Das sehr schwere, harte, spröde, silber-weiß glänzende Edelmetall aus der Gruppe der Platinmetalle gilt als das korrosionsbeständigste Element. Unter 0,11 Kelvin wechselt es in den supraleitfähigen Zustand über." > some_de.txt
@emres
emres / gist:1494637
Created December 18, 2011 22:08
Language detection in Bash command line (for German)
en_res=$(echo $(cat some_de.txt EN | gzip | wc -c) - $(gzip -c EN | wc -c) | bc); \
de_res=$(echo $(cat some_de.txt DE | gzip | wc -c) - $(gzip -c DE | wc -c) | bc); \
(echo $en_res EN && echo $de_res DE) | sort -n | head -1 | cut -d' ' -f2
@emres
emres / gist:1494649
Created December 18, 2011 22:16
Language detection in Bash command line - retrieving English and German corpus from Gutenberg
wget http://www.gutenberg.org/ebooks/46.txt.utf8 && mv 46.txt.utf8 EN && wget http://www.gutenberg.org/cache/epub/2229/pg2229.txt && mv pg2229.txt DE
@emres
emres / gist:1494671
Created December 18, 2011 22:27
Language detection in Bash command line - Norvig's problematic example
(echo `cat some_de.txt EN | gzip | wc -c` EN; \
echo `cat some_de.txt DE | gzip | wc -c` DE) \
| sort -n | head -1
@emres
emres / subtract-number-from-current-word.el
Created December 20, 2011 19:45
Substract a number from the current word and replace it with the result.
(defun subtract-number-from-current-word (number)
"Substract a number from the current word and replace it with the result.
Beware: No error checking."
(interactive "p")
(let ((curr-word (current-word)))
(kill-word 1)
(insert (int-to-string
(- (string-to-int curr-word) number)))))
@emres
emres / gist:1510269
Created December 22, 2011 13:11
Create bubble chart in Excel 2010
Public Sub CreateBubbleChart()
''' Reference : Tom Hollander, http://blogs.msdn.com/b/tomholl/archive/2011/03/28/creating-multi-series-bubble-charts-in-excel.aspx
If (Selection.Columns.Count <> 4 Or Selection.Rows.Count < 3) Then
MsgBox "Selection must have 4 columns and at least 2 rows"
Exit Sub
End If
Dim bubbleChart As ChartObject
Set bubbleChart = ActiveSheet.ChartObjects.Add(Left:=Selection.Left, Width:=600, Top:=Selection.Top, Height:=400)
bubbleChart.Chart.ChartType = xlBubble
@emres
emres / number-of-days-between-two-dates.el
Created June 26, 2012 13:17
Number of days between two dates
(defun number-of-days-between-dates (date1 date2)
"Returns the number of days between two dates.
Usage:
(number-of-days-between-dates \"yyyy-mm-dd\" \"yyyy-mm-dd\")
Or
M-x number-of-days-between-dates"