Skip to content

Instantly share code, notes, and snippets.

@Olathe
Olathe / make-compress-script.rb
Last active December 19, 2015 00:29
Linux PNGOUT script generator
#!/usr/bin/env ruby
require 'open3'
require 'tempfile'
ThreadCount = 2
Infinity = 1.0/0.0
Filenames = Dir['**/favicon.ico', '**/*.png'].map! { |filename| File.expand_path filename }
BestSizes = Hash.new { |h, filename| h[filename] = [Infinity, nil] }
@Olathe
Olathe / Optimizing PNGs.md
Last active December 19, 2015 00:49
Procedure for optimizing PNGs
  1. pngcheck can detect non-PNGs:
    find -name '*.png' -exec pngcheck -q '{}' +
  2. GIMP GUI (unlike *Magick or Script-Fu, which are buggy) can properly convert to sRGB (remember to overwrite the original for each one):
  • Open in GIMP (press Ctrl-C once it stops opening windows for a while):
    find -name '*.png' -exec sh -c "pngcheck -v '{}' | grep -q 'chunk iCCP' && echo \"\\\"{}\\\"\"" \; | xargs gimp & while true; do window_id=$(wmctrl -l | grep -Pom 1 "^(0x[0-9a-f]{8})(?=\s.+ Convert to RGB working space\?$)"); if [ "$window_id" != "" ]; then xsendkey -window $window_id "Alt+C"; fi; sleep 1; done
  • Convert and overwrite originals:
    `wmctrl -l | grep -Po "^(0x[0-9a-f]{8})(?=\s.+ GIMP$)" | while read window_id; do echo Handling window $window_id; xsendkey -window $window_id Alt+i; xsendkey -window $window_id m; xsendkey -window $window_id c; until (wmctrl -l | grep -Poq "^(0x[0-9a-f]{8})(?=\s.+ Convert to ICC Color Profile$)"); do sleep 1; done; wmctrl -l | grep -Po "^(0x[0-9a-f]{8})(?=\s.+
@Olathe
Olathe / IntegerSquareRoot.java
Last active August 29, 2015 13:56
Simple near-hardware-speed floored square root for 64-bit integers
/* Sometimes, taking the floored square root of a 64-bit integer is needed.
In order to gain the speed of hardware square root, 64-bit integers must be converted
to 53-bit mantissa doubles.
This can cause incorrect results due to loss of precision.
However, the floor of the square root produced will be either the correct
floored square root or the next higher integer.
For reasoning, see http://apps.topcoder.com/forums/?module=Thread&threadID=695233
So, we can simply:
1) Convert to double.
2) Use hardware square root.
@Olathe
Olathe / springer-free-maths-books.md
Created December 29, 2015 05:39 — forked from bishboria/springer-free-maths-books.md
Springer have made a bunch of maths books available for free, here are the direct links