Archive for October, 2009

Franc Jameso

Saturday, October 31st, 2009

I am dismayed to see that nobody on the world wide web has mentioned or even proposed the existence of the anti-celebrity Franc Jameso. So let me be the first. I postulate that this rendering could be an accurate depiction of the possible Franc Jameso:
Franc Jameso

Response to Jackson Pollock 4×4 Puzzle

Saturday, October 31st, 2009

I recently revisited Ken Perlin’s Jackson Pollock 4×4 Puzzle, a clever play on the sliding tile puzzle. With minimalism on my mind, I considered whether I could take this idea one step further. So here’s my response to the Jackson Pollock 4×4 Puzzle. I present the Ad Reinhardt 3×7 puzzle:

Note: The image is Reinhardt’s Abstract Painting, Red, 1952. Oil on canvas. 108 x 40 1/8 in. (274.4 x 102 cm).

Note: The source for this applet is a barely modified version of the source Ken (graciously) provided on his page.

Google images game: high score

Monday, October 26th, 2009

I will try to implement a current high score or high scores feature to the Google images game, but in the mean time I will post screenshots here. Here’s the first known “Hard” solution found for the “Nouns” game:


Google images game first hard solution


Try to beat this score!

Leave a comment below or contact me with a screen shot of your high score.

Google images game

Sunday, October 25th, 2009


google images game screen shot

I finished coding a rather simple but addictive and challenging puzzle game, I’m calling the Google images game. The player is presented with the image results of a Google images search for some search word or phrase. The player’s objective is to guess and figure out what that search phrase was. Play it now!

The game is an amalgamation of php, javascript and ruby. The ajax javascript for the game is rather complicated by now to handle all of the gaming options, but it’s all visible in the game’s page source. I use a little ruby program to grab the initial google images thumbnails:


#!/usr/bin/ruby
require 'uri'
require 'net/http'
require 'cgi'

SAFE_VALUES = ["on","moderate","off"]
cgi = CGI.new("html3")
safe = "moderate"
safe = cgi["safe"] if(!cgi["safe"].empty? and SAFE_VALUES.include?(cgi["safe"]))
target = ""
target = cgi["target"] if(!cgi["target"].empty?)

if(!cgi["query"].empty?)
  address = "http://images.google.com/images?q="+
    cgi["query"].gsub(/ /,"+")+"&safe="+safe
  uri = URI(address)
  http = Net::HTTP.new(uri.host, uri.port)
  headers = {
    "User-Agent" => "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)"
    }

  code = http.head(address, headers).code.to_i
  if (code >= 200 && code < 300) then

      #the data is available...
      response = ""
      http.get(address, headers) do |chunk|
        response = response + chunk
      end
      images = []
      response.scan(
        /imgurl=(.+?)&imgrefurl=(.+?)&[^<]+<img src=(.+?) /
        ) do |img, ref, thumb|
        images<<[img,ref, thumb]
      end
      images.collect! do |e|
        "<a title='"+e[1]+" 'href='"+
        CGI.unescape(e[1]).gsub(/'/,"%27").gsub(/ /,"%20")+
        "' target='"+target+"'><img src='"+e[2]+"' height='100px'></a>"
      end
      cgi.out{
        images.join(" ")
      }
  end
end

I use a little php program to return a random line (initial search phrase/word) from a given file:


  $difficulty = 'easy';
  if (isset($_GET['difficulty'])&&strlen($_GET['difficulty'])>0) {
      $difficulty= $_GET['difficulty'];
  }
  $word_list = 'nouns.txt';
  $possible_word_lists = array('nouns.txt','wiki.txt');
  if (isset($_GET['word_list'])&&strlen($_GET['word_list'])>0) {
      if(in_array($_GET['word_list'],$possible_word_lists)){
        $word_list = $_GET['word_list'];
      }
  }


  $query = "";
  $word_count = 1;
  if(strcmp($word_list,'nouns.txt')==0){
    if(strcmp($difficulty,"medium")==0){
      $word_count = 2;
    }else if(strcmp($difficulty,"hard")==0){
      $word_count = 3;
    }
  }
  for($i=0; $i<$word_count; $i=$i+1){
    if(strlen($query)>0){
      $query= $query."+";
    }
    $query = $query.`ruby -e "a=File.readlines('$word_list').collect{|line| line.strip.gsub(' ','+').gsub('\'','%27')};puts a[rand*a.leng
    $query = trim($query);
  }
  print trim($query);

As you can see, I gave up on php half way through and cheated by calling a ruby one-liner. Someday I'll fix this up...

Sun messenger express delete all messages in inbox: applescript + javascript

Sunday, October 25th, 2009

I recently received a notice that I had filled my email storage quota for my NYU email account. About a month or two ago I set up my gmail account to fetch my NYU account mail, so all my emails are backed up with google. I logged into NYU Home’s webmail client (Sun Java™ System Messenger Express) and was dismayed to find out that the only way to delete all the messages in my inbox was to select “all” 20 messages and hit delete over and over again (see update below). I tried going to the Folders tab, selecting Inbox and clicking delete but I got this error: “System folders – cannot be deleted”. It seems impossible to purge your inbox using the “Mess Express”.

Since applescript can tell Safari to run arbitrary javascript on an open webpage, I hunted (rather painfully, “Mess Express” is about 10 html frames within frames, no objects have ids and the js is split between many files) through the source and found the necessary functions to automate deletion. Here’s my applescript. Before running you should have signed into you messenger express client and be viewing your inbox in the frontmost Safari window:


tell application "Safari"
	set doc to front document
	repeat (4945 / 20) times
		repeat until source of doc contains "</html>"
			delay 1
		end repeat
		do JavaScript "parent.mailFrame.selectAll('true');" in doc
		do JavaScript "parent.mailFrame.delmsg();" in doc
		delay 1
	end repeat
end tell

Note: Replace 4945 with the total number of messages you need to delete.

After the script has successfully finished (it should take less than 2 seconds per 20 emails deleted), click on the Folders tab at the top,
folder tab link
then hit Empty Trash.
empty trash

If there is an easier way to delete all messages in your inbox, I’d love to know.

Update: It is possible to speed this up even more by setting the message view count from 20 to 100 by clicking on the Options tab then selecting Appearance and changing the Message List View amount to 100.

messenger express appearance options

t9 scramble: windows puzzle game using “Texts from last night”

Wednesday, October 21st, 2009

t9 scramble screen shot

I finished an XNA (windows only) puzzle game. The idea is that you are presented with somebody’s poorly entered t9 txt msg. You job is to decipher the t9 words. Your guess needs to match the t9 digits of the scrambled words.

The phrases used for the scrambled t9 txt msgs are from http://www.textsfromlastnight.com/. Maybe they’ll buy the game? (or sue me…)

List of all hex words: words using only letters a through f

Sunday, October 18th, 2009

I used this ruby one-liner


ruby -e "puts File.readlines('List of English Words.txt').find_all{|word| word =~ /^[abcdef]+\n$/i}"

and a file containing a large list of English words (and acronyms) to make the following list of English words that only use “hex letters” or letters a through f.

A
AAA
ABA
ABC
AC
ADA
Ab
Ababa
Abba
Abe
Ada
Adad
Adda
Ade
B
BCD
Bab
Bee
Beebe
C
CA
CAD
CB
CDC
CDF
Caca
D
DC
DEC
Dacca
Dada
Dade
De
Deb
Dec
Decca
Dee
E
EBCD
Ecca
Ed
Edda
F
FAA
FCC
FDA
Faba
Fabaceae
Fe
Feb
a
aa
ab
aba
abac
abaca
abaff
abb
abba
abbe
abc
abed
ac
acca
accede
acceded
ace
aced
ad
ada
adad
add
adda
added
ade
adead
ae
aface
afaced
afb
afd
aff
affa
b
ba
baa
baaed
baba
babe
bac
bacaba
bacca
baccae
bad
bade
bae
baff
baffed
bb
bcd
be
bea
bead
beaded
bebed
bed
bedad
bedded
bede
bedead
bedeaf
bee
beebee
beef
beefed
c
ca
cab
caba
cabda
cad
cade
caeca
cafe
caffa
cc
cd
cdf
ce
ceca
cede
ceded
cee
cf
d
dB
da
dab
dabb
dabba
dabbed
dace
dad
dada
dade
dae
daff
daffed
db
dc
dca
dcb
de
dead
deaf
deb
dec
decad
decade
dee
deed
deeded
deedeed
deface
defaced
e
ea
ebb
ebbed
ebcd
ecad
ecb
ed
edda
edea
ef
eff
efface
effaced
f
fa
facade
facaded
face
faced
fad
fade
faded
fae
faff
fe
feb
fed
fee
feed
feeded

Perhaps you can use these to make your WEP wifi password easier to rattle off to your guests.

LaTeX “for any” symbol

Sunday, October 18th, 2009

for any or for all symbol

The upside-down capital A (∀) as in “for all” or “for any” element(s) in a set, can be typeset in LaTeX using the TeX macro in math mode:


\forall

Vi(m) tip #3: convert document to lowercase or uppercase

Friday, October 16th, 2009

Convert every matching regex (or line) to lowercase or uppercase using vims gsub command. In normal mode this will convert the entire document to lowercase (ie downcase all capitals):


:%s/[A-Z]/\L&/g

Likewise for to upcase:


:%s/[a-z]/\U&/g

source

Vi(m) tip #2: Entering greek/math symbols using vim digraphs

Wednesday, October 14th, 2009

Lately I have been taking computer science/math class notes using vim. Since typing LaTeX is too cumbersome and not readily intuitive (you have to typeset it). I just use plain text. This is fine until I need to quickly type strange letters/symbols. I can do this in vim using digraphs. To see a list of available digraphs, in normal mode type:


:digraphs

To enter a digraph in insert mode simply hit <ctrl>+k then the two symbols to create the digraph. So to make the greek capital phi, Φ, you’d hit (in insert mode)

<ctrl>kF*

Below is a table of useful math and computer science digraphs.

symbol description symbol unicode (decimal) vim digraph (first type <ctrl>k)
plus minus ± 177 +-
squared (superscript 2) ² 178 2S
coproduct (big, tall Pi) 8719 *P
summation (big, tall Sigma) 8721 +Z
bullet operator (dot product) 8729 Sb
(square) root 8730 RT
infinity 8734 00
Greek Letters
Gamma Γ 915 G*
Delta Δ 916 D*
Theta Θ 920 H*
Pi Π 928 P*
Sigma Σ 931 S*
Phi Φ 934 F*
Psi Ψ 936 Q*
Omega Ω 937 W*
alpha α 945 a*
beta β 946 b*
gamma γ 947 g*
delta δ 948 d*
epsilon ε 949 e*
eta η 951 y*
theta θ 952 h*
kappa κ 954 k*
lambda λ 955 l*
mu μ 956 m*
pi π 960 p*
rho ρ 961 r*
sigma σ 963 s*
sigma (alternative) ς 962 *s
tau τ 964 t*
phi* φ 966 f*
psi* ψ 968 q*
omega* ω 969 w*
dagger (sword) 8224 /-
double dagger (double sword) 8225 /=
left arrow* 8592 <-
up arrow 8593 -!
right arrow 8594 ->
down arrow 8595 -v
Logic
for all (for any) 8704 FA
partial differential (curled little d) 8706 dP
there exists (backwards capital E) 8707 TE
logical and 8743 AN
logical or 8744 OR
therefore (triangle of dots) 8756 .:
because (upside-down triangle of dots) 8757 :.
Sets
Null set, empty set, var nothing, capital O slash 8709 /0
Null set, empty set, var nothing, capital O slash Ø 216 O/
element of 8712 (-
contains as member 8715 -)
set intersect 8745 (U
set union 8746 U)
subset of (contained in) 8834 (C
superset of (contains) 8835 )C
subset of or equal to 8838 (_
superset of or equal to 8839 )_
concatenation, centered dot 8728 Ob
Calculus
integral S 8747 In
double integral S 8748 DI
line integral S with circle 8750 Io
Delta 8710 DE
Nabla 8711 NB
Equalities, inequalities, et al.
tilde operator (centered tilde, proportional) 8764 ?1
approximately equal to 8773 ?=
almost equal to 8776 ?2
not equal to 8800 !=
less than or equal to 8804 =<
greater than or equal to 8805 >=

* I avoid these because they are double-width characters. In the document they are technically only one character put displayed they take up two character positions resulting in overlap in vim.

Note: Greek letters are usually their Latin alphabet “equivalent” then star, with capitals taking capital (uppercase) Latin letters, likewise for lowercase. I included some (what I use most) here.

Note:“Superscript” and “subscript” numbers are all [digit]S for Superscript and [digit]s for subscript.

Note: If you don’t find the character you want above, or by typing :digraphs and paging through supported digraphs, you can input a unicode character by its value in hex. Do this by typing <ctrl>v in insert mode then:

u[4-hex-digit value]

U[8-hex-digit value]

Leading zeros may be omitted.

Note: On some machines <ctrl>v means paste, in that case use <ctrl>q

source

Update: I found a useful list of unicodes for math symbols.