Horizontal Scroll a Table “In Place”

This is a a pretty cool trick for mobile where the amount of information you want to display just isn’t going to fit in the width available. Have the table horizontally scrollable …

ID First Name Last Name Email IP Address App Company Country Hash Registered Completed Confirmed Eyes Hair Favorite
1 Thomas Perez tperez0@craigslist.org 100.208.33.222 com.myspace.Toughjoyfax Brightbean South Africa 1LqnJGirgwjyMSHxTRRrSbxv5TuuxZTLwK false false false “Puce Pink Yellow
2 Michelle Nelson mnelson1@dyndns.org 132.105.223.121 gov.nps.Fintone Bubblebox China 17ANZgWGNB2B75qoRXS8NrxNYhwf67VBV3 true false false “Green Aquamarine Red
3 Carolyn Ramos cramos2@themeforest.net 241.207.38.235 com.kickstarter.Quo Lux Zooxo Brazil 16ypa5ZrLoTPQa3dsSWN2aGJQsSq494msa false false false “Fuscia Khaki Pink
5 Gloria Kelly gkelly4@google.cn 20.166.10.83 com.stumbleupon.Bigtax Meevee Bulgaria 15MyxCQerGT64DHKZjQvb8bRgTvQDxPEVW true false false “Orange Orange Mauv
6 Heather Elliott helliott5@adobe.com 53.172.163.238 io.pen.Matsoft Jabbertype Russia 1ctfF4kTwX4G7VtjmPqA3jDSVaecEUEpj false false true “Fuscia Mauv Khaki
7 Chris Alvarez calvarez6@godaddy.com 180.241.181.236 org.bbb.Mat Lam Tam Voomm Cyprus 1HZQu9rRYyYdTqLBgri268yE9g3ssh6oQZ true false false “Goldenrod Khaki Goldenrod
8 Rebecca Ramos rramos7@twitpic.com 33.184.157.226 gov.cdc.Voyatouch Centizu Latvia 1LREwA3au2AFsssgV3k58LDkBDQqMhwJPi false false true “Puce Pink Goldenrod
9 Cheryl Walker cwalker8@census.gov 202.93.128.99 com.histats.Holdlamis Twitterwire China 16Z6gUpUVcPFaiWfD8Mg7RPUhXhJJHjxJM false true false “Teal Maroon Turquoise
10 Lawrence Jacobs ljacobs9@wordpress.org 126.204.15.152 com.patch.Cookley Latz China 168Zpb6b9jCrNFzQ1WJeYwdAEAsfg5Q7Y7 true false false “Mauv Red Orange
11 Larry Morgan lmorgana@reverbnation.com 156.120.22.150 uk.nhs.Y-find Fiveclub China 1BUE62CFLctCnoNcL1fFPfPjXEtfjqo3aC true true false “Teal Green Violet
13 Elizabeth Myers emyersc@amazon.com 92.24.59.86 com.java.Otcom Voolia Indonesia 14fsux3DUUsZpUxims3HnzanxZuFP174Px true false true “Goldenrod Fuscia Pink
14 Jeffrey Hernandez jhernandezd@examiner.com 103.86.221.117 com.blogtalkradio.Zontrax Zoovu Ivory Coast 1Lg8itU8pTn1thF82rvqfjMWo4R1esbzPc false true false “Fuscia Violet Red
15 Roger Burns rburnse@symantec.com 21.10.159.170 br.com.uol.Keylex Yodoo Portugal 1Kv5osyo26akrsjjAkN1tmLR5yuxrro4dQ false false false “Pink Indigo Mauv
16 Ryan Burns rburnsf@sciencedaily.com 148.255.43.122 fr.free.Sub-Ex Cogibox Philippines 168XyNGMe2aQkbQnj2zV1TndncUCiZsx3f true false false “Mauv Maroon Indigo
17 Philip Cunningham pcunninghamg@i2i.jp 190.212.13.154 com.sbwire.Bigtax Yata Argentina 1BPNVNMkovTu18ooLeKgZfReLsNjSm4Q1n false false false “Khaki Purple Fuscia
18 Diana Armstrong darmstrongh@arizona.edu 37.1.31.159 gov.ed.Viva Npath China 14EYfzQ4pZ5CkkckkGZbEr6KmYVhyKL4UM true true false “Goldenrod Turquoise Purple
19 Brian Berry bberryi@sfgate.com 37.65.135.186 gov.senate.Span Topicshots China 1Ez7qMkjt2o7j55mRRMYviQFtX9n5CMAx3 false true false “Crimson Aquamarine Puce
20 Steve Clark sclarkj@blinklist.com 235.174.174.154 uk.co.amazon.Alphazap Kwilith Russia 1MowPLi2JQqBLEwGpC5xM9xFXZt6P96tkw true false true “Orange Yellow Purple

This is achieved with overflow-x: auto on the containing div, width: 600% on the table and normal widths adding up to 100% on the columns.

Compressing a program in plain text

I came across this neat way of sharing a program in limited space in plain text (Stack Overflow comments are limited in length).

require 'base64';require 'zlib';puts Zlib.inflate(Base64.decode64("eJxlkMEOwiAQRO98hekFuGzxQEwPXvwR01ZqiYHqBk2Tln8XDlWgnDbM25nJonq9NaoD7ZTtR9PigxK09zM7AkgRHieXTYHOsBNf1nklM6B6TuhYpdp+rPgSdiCOi/d/kQ71QBOtAVFLEDly05+UYQ2H+MckL6z0zioDdJG1S9K1K4iQAW66DhnmiqRYKEJFXMByux+XuOJ2XdO60dKsjC7aBtyTL5O5hLk="))

When run this produces:

require 'benchmark'
rng=(1..50000)
Benchmark.bm(7){|x|
x.report("each"){rng.each{}}
x.report('f/f'){rng.each{9.0/5.0}}
x.report('fdiv'){rng.each{(9).fdiv(5)}}
x.report('f/i'){rng.each{9.0/5}}
x.report('i/f'){rng.each{9/5.0}}
x.report('i/tf'){rng.each{9/(5).to_f}}
x.report('tf/i'){rng.each{(9).to_f/5}}
x.report('tf/tf'){rng.each{(9).to_f/(5).to_f}}
require 'mathn'
x.report('i/i'){rng.each{9/5}}
}

Source: Stack Overflow

For MySQL, utf8 is not enough, you want utf8mb4

Someone entered 😨, the “fearful face emoticon”, in a forum on a website I run. But it didn’t display.

Here’s what I had to do to get it to work:

  • ALTER DATABASE dbname CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci
  • ALTER TABLE tablename CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci
  • ALTER TABLE tablename MODIFY columnname COLUMNNAMEEXISTINGTYPE CHARACTER SET utf8mb4;
  • In my.conf:

    [client]
    default-character-set = utf8mb4

    [mysqld]
    collation-server = utf8mb4_unicode_ci
    init-connect=’SET NAMES utf8mb4′
    character-set-server = utf8mb4

Note that if you are converting from latin-1 not utf-8 you will need to convert columns to blob and then to utf8mb4 to correctly preserved already latin1-encoded special characters.

Convert from underscore_style to camelCaseStyle and Vice Versa

  // AStringConverted -> a_string_converted
  function toUnderscoreStyle($s) {
    $f = function ($match) { return "_" . mb_strtolower($match[1]); };
    return preg_replace_callback('/([A-Z])/', $f, lcfirst($s));
  }

  // a_string_converted -> aStringConverted
  function toCamelCase($s) {
    $f = function($match) { return mb_strtoupper($match{1}); };
    return preg_replace_callback('/_([a-z])/', $f, $s);
  }

Arguing on the Internet

wrong

“Don’t read the comments” is a pretty good warning. You can waste a lot of time shouting at strangers in comment threads or fighting with friends-of-friends on Facebook. But if you feel like you do have to engage I really like these rules from Anatol Rapoport by way of Daniel Dennett to give you a fighting chance of changing a mind rather than just blowing hot air.

How to compose a successful critical commentary:

  1. You should attempt to re-express your target’s position so clearly, vividly, and fairly that your target says, “Thanks, I wish I’d thought of putting it that way.
  2. You should list any points of agreement (especially if they are not matters of general or widespread agreement).
  3. You should mention anything you have learned from your target.
  4. Only then are you permitted to say so much as a word of rebuttal or criticism.

Remember the Milk Alfred Plugin that Respects Double Quotes, Single Quotes, Backslashes and Anything Else You Throw At It

I’ve used various Remember the Milk plugins for Alfred but none of them cope with any input and reproduce it faithfully in the resulting task. Here’s a plugin that does. You need Alfred’s Power Pack to use this.

$ sudo gem install rumember
$ ru # Agree to authenticate rumember, then press Enter in the terminal when authenticated

Now install this plugin. It’ll use “todo” as the keyword by default but that’s easily changed under ‘Workflows’ in Alfred’s settings should you wish.

Things I Absolutely Must Do On A New Mac

I try to stick to “default is better than configuration”. But there’s some stuff I absolutely must have on a Mac to be useful.