Posts Tagged ‘google’

Create a “when I am busy” calendar

Monday, September 12th, 2016

Here’s how to create a public calendar on your website that shows when you are busy. For example, mine

\1. To set up sharing go to your calendar on http://calendar.google.com, select Sharing from the drop down on the left side:

dropdown google calendar

\2. Make sure that it’s public but only showing busy:

calendar busy checkbox

\3. Then go to “Calendar Details”, copy the <iframe ... HTML tag:

calendar iframe embedding

\4. On your website, create a calendar.html page with the following contents (replacing the <iframe ... tag appropriately):

“`

<!DOCTYPE html>
<html>
  <head>
    <title>Alec's Busy</title>
    <style>
html {margin: 0;padding 0;}
body { margin: 0;position:fixed; left:0; width:100%; top:0; height:100%; }
iframe { margin: 0;display: block; width:100%; height:100%; }
    </style>
  </head>
  <body>
      <iframe src="https://www.google.com/calendar/embed?title=Alec&#39;s%20Busy&showCalendars=0&mode=WEEK&src=alecjacobson%40gmail.com&ctz=local" style=" border-width:0 " width="100%" height="95%" frameborder="0" scrolling="no"></iframe>
  </body>
</html>

“`

Finally, if you’re logged into your google account and you visit your calendar.html page, you might be freaked out because you see all of your events (instead of busy). But to verify that it’s really hidden, use an “incognito”/private window to see that it just shows “busy”.

Missing faces when importing into SketchUp

Monday, April 4th, 2016

When loading a mesh into sketchup, I noticed that sometimes faces would be missing:

cheburashka imported into sketchup with missing faces

two mesh file format IO implementations later, I realized the problem is not the file format but rather that sketch up seems to be ignoring faces (and sometimes edges?) smaller than a certain scale. For example if I scale the model down by 0.1 I see:

smaller cheburashka imported into sketchup with missing more faces

And if I scale the model up, eventually I get all of the faces:

larger cheburashka imported into sketchup with no missing faces

Still not sure how to ensure that all faces get loaded at the correct scale, but at least I know what the problem is now.

Scrape google search by image (query by example) results

Sunday, August 18th, 2013

Here’s a php script that takes as an argument a path to a directory. First save this in a file called common-user-agents.php:


<?php
// http://searchnewscentral.com/20110928186/General-SEO/how-to-scrape-search-engines-without-pissing-them-off.html
$COMMON_USER_AGENTS = array(
  "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36",
  "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:22.0) Gecko/20100101 Firefox/22.0",
  "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36",
  "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/536.30.1 (KHTML, like Gecko) Version/6.0.5 Safari/536.30.1",
  "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36",
  "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36",
  "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36",
  "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:22.0) Gecko/20100101 Firefox/22.0",
  "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36",
  "Mozilla/5.0 (Windows NT 5.1; rv:22.0) Gecko/20100101 Firefox/22.0",
  "Mozilla/5.0 (Windows NT 6.1; rv:22.0) Gecko/20100101 Firefox/22.0",
  "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36",
  "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)",
  "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36",
  "Mozilla/5.0 (iPad; CPU OS 6_1_3 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10B329 Safari/8536.25",
  "Mozilla/5.0 (iPhone; CPU iPhone OS 6_1_3 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10B329 Safari/8536.25",
  "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36",
  "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:22.0) Gecko/20100101 Firefox/22.0",
  "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36",
  "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36",
  "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36",
  "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:22.0) Gecko/20100101 Firefox/22.0",
  "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36",
  "Mozilla/5.0 (iPhone; CPU iPhone OS 6_1_4 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10B350 Safari/8536.25",
  "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0",
  "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/536.30.1 (KHTML, like Gecko) Version/6.0.5 Safari/536.30.1",
  "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)",
  "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36",
  "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:22.0) Gecko/20100101 Firefox/22.0",
  "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36",
  "Mozilla/5.0 (X11; Linux x86_64; rv:22.0) Gecko/20100101 Firefox/22.0",
  "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:22.0) Gecko/20100101 Firefox/22.0",
  "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/534.59.8 (KHTML, like Gecko) Version/5.1.9 Safari/534.59.8",
  "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36",
  "Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:22.0) Gecko/20100101 Firefox/22.0",
  "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36",
  "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)",
  "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)",
  "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/28.0.1500.71 Chrome/28.0.1500.71 Safari/537.36",
  "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36",
  "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)",
  "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36",
  "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:23.0) Gecko/20100101 Firefox/23.0",
  "Mozilla/5.0 (Windows NT 6.1; rv:17.0) Gecko/20100101 Firefox/17.0",
  "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:23.0) Gecko/20100101 Firefox/23.0",
  "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36",
  "Mozilla/5.0 (Windows NT 6.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36",
  "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36",
  "Mozilla/5.0 (iPad; CPU OS 5_1_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B206 Safari/7534.48.3",
  "Mozilla/5.0 (Windows NT 5.1; rv:23.0) Gecko/20100101 Firefox/23.0",
  "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36",
  "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/536.28.10 (KHTML, like Gecko) Version/6.0.3 Safari/536.28.10",
  "Mozilla/5.0 (Windows NT 6.0; rv:22.0) Gecko/20100101 Firefox/22.0",
  "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36",
  "Mozilla/5.0 (iPod; CPU iPhone OS 6_1_3 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10B329 Safari/8536.25",
  "Mozilla/5.0 (Windows NT 6.1; rv:6.0) Gecko/20100101 Firefox/6.0",
  "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0; Trident/5.0)",
  "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0",
  "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0",
  "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/28.0.1500.52 Chrome/28.0.1500.52 Safari/537.36",
  "Opera/9.80 (Windows NT 6.1; WOW64) Presto/2.12.388 Version/12.16",
  "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.32 Safari/537.36",
  "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36",
  "Mozilla/5.0 (Windows NT 6.1; rv:23.0) Gecko/20100101 Firefox/23.0",
  "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0",
  "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0",
  "Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:23.0) Gecko/20100101 Firefox/23.0",
  "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)",
  "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36",
  "Mozilla/5.0 (Windows NT 5.1; rv:21.0) Gecko/20100101 Firefox/21.0",
  "Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36",
  "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.63 Safari/537.31");
?>

Then save this in a file called

scrape-sbi.php:


<?php

include "common-user-agents.php";

// http://stackoverflow.com/a/10635186/148668
function fetch_google(
  $terms="sample search",
  $numpages=1,
  $user_agent='Mozilla/5.0 (Windows NT 6.1; rv:8.0) Gecko/20100101 Firefox/8.0')  
{
    $searched="";
    // Why was this $i<=$numpages ?
    for($i=0;$i<$numpages;$i++)
    {
        $ch = curl_init();
        $url="http://www.google.com/searchbyimage?hl=en&image_url=".urlencode($terms);
        echo "$url\n";
        curl_setopt ($ch, CURLOPT_URL, $url);
        curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent);
        curl_setopt ($ch, CURLOPT_HEADER, 0);
        curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt ($ch, CURLOPT_REFERER, 'http://www.google.com/');
        curl_setopt ($ch,CURLOPT_CONNECTTIMEOUT,120);
        curl_setopt ($ch,CURLOPT_TIMEOUT,120);
        curl_setopt ($ch,CURLOPT_MAXREDIRS,10);
        curl_setopt ($ch,CURLOPT_COOKIEFILE,"cookie.txt");
        curl_setopt ($ch,CURLOPT_COOKIEJAR,"cookie.txt");
        $searched=$searched.curl_exec ($ch);
        curl_close ($ch);
    }

    return $searched;
}

if(sizeof($argv)<2)
{
  die("Usage:\n  scrape-sbi.php path/to/image/dir/\n");
}

$dir = $argv[1];
//  Create output directories
if (!file_exists('match')) {
  mkdir('match', 0777, true);
}
if (!file_exists('match/html')) {
  mkdir('match/html', 0777, true);
}
if (!file_exists('match/images')) {
  mkdir('match/images', 0777, true);
}
$connection = ssh2_connect('alecjacobson.com', 22,array('hostkey'=>'ssh-rsa'));
if(!ssh2_auth_pubkey_file($connection, 'alecjaco',
    '~/.ssh/id_rsa.pub',
    '~/.ssh/id_rsa', 'secret'))
{
  die("Error: SSH authentication failed.");
}
foreach(glob("$dir/*.jpg") as $file)
{
  echo $file."\n";
  if(sizeof(glob("match/images/".pathinfo("$file",PATHINFO_FILENAME).".*"))>0)
  {
    echo "  skipped.\n";
    continue;
  }
  $scp_path = "public_html/drop/closest/".
    uniqid().".jpg";
    //pathinfo($file, PATHINFO_BASENAME);
  if(!ssh2_scp_send($connection,$file,$scp_path,0777))
  {
    die("Error: SSH send failed.");
  }
  $up_url = preg_replace("/public.html/","http://alecjacobson.com/",
    $scp_path);
  echo $up_url."\n";
  $agent = $COMMON_USER_AGENTS[array_rand($COMMON_USER_AGENTS)];
  $res = "";
  $res = fetch_google($up_url,1,$agent);
  //$res =
  //  file_get_contents("test.html");
  if(sizeof($res)==0)
  {
    die("Error: google returned nothing.");
  }
  $matches = array();
  preg_match("/Visually similar.*?imgurl=([^&]*)&/",$res,$matches);
  if(sizeof($matches) < 2)
  {
    // Second type of results ( I think this is because of iPhone user agent)
    preg_match(
      '/Visually similar.*?data-largeimageurl="([^"]*)"/',$res,$matches);
    if(sizeof($matches) < 2)
    {
      file_put_contents("no-match.html",$res);
      // no match found: no visually similar image found?
      print_r($res);
      die("Error: No match found (check no-match.html).");
    }
    // http:\/\/... --> http://
    $matches[1] = trim(str_replace("\\/","/",$matches[1]));
  }
  file_put_contents(
    'match/html/'.
    pathinfo($file, PATHINFO_FILENAME).".html",
    $res);
  $match_url = $matches[1];
  echo "$match_url\n";
  $img = 'match/images/'.
    pathinfo($file, PATHINFO_FILENAME).".".
    pathinfo($match_url, PATHINFO_EXTENSION);
  echo "$img\n";
  file_put_contents($img, file_get_contents($match_url));
  // http://searchnewscentral.com/20110928186/General-SEO/how-to-scrape-search-engines-without-pissing-them-off.html
  sleep(rand(15,60));
} 
return 0;

?>

Then call it with something like:

php scrape-sbi.php src/

where src is full of jpgs. This will create match/images/ and fill it with the first result for each search by image search. Source 1 Source 2

Google search current page bookmarklet

Thursday, May 23rd, 2013

Here’s a javascript bookmarklet for googlin’ the title of the current page your viewing:


javascript:(function(){window.location.href="http://google.com/search?q="+document.title;})()

Drag me onto your bookmark bar.

Then when you’re at a sit that blocks regular visiting but allows entrance through a google search—cough, cough, nytimes.com—you can quickly google the title and click the inevitably top link.

Switch search to google scholar bookmarklet

Monday, March 25th, 2013

I upgraded to Safari 6 and was happy to see the search bar gone and keyword search directly in the address bar. However I was annoyed to see that when searching you don’t see the full google url but just the query keywords. This nullified my previous hack to switch a google search to a google scholar search.

Instead here’s a little bookmarklet to switch a google search to a google scholar search:


javascript:(function(){window.location.href=window.location.href.replace("search?", "scholar?");})()

Just paste that into you address bar and create a bookmark for it. Then any time you do a normal google search, you can switch it to a google scholar search by hitting the bookmark.

source

Make each title in LaTeX bibliography references link to google search of that title

Thursday, August 2nd, 2012

When ever I’m reading a new paper I’m constantly looking up the articles referenced in the bibliography. Sometimes bibliographies have links or urls but there so often dead or domain restricted. Instead, my modus operandi is to just google search the title and click on the first PDF that comes up in the results.

To cut down on the steps I thought it would be nice if the PDF of the article I’m reading already had the google search set up for me. Then the title in the reference could be a link to a google search of itself.

Here’s a bibtex .bst function that can be modded into the acmsiggraph.bst file. Just replace:


FUNCTION {format.title}
{ title empty$
    { "" }
    { title "t" change.case$ }
  if$
}

with:


INTEGERS{ l }
FUNCTION{ string.length }
{ 
  #1 'l := 
  {duplicate$ duplicate$ #1 l substring$ = not}
    {l #1 + 'l :=}
  while$
  pop$ l
}

STRINGS{replace find text}
INTEGERS{find_length}
FUNCTION{find.replace}
{ 'replace :=
  'find :=
  'text :=
  find string.length 'find_length :=
  ""
    { text empty$ not }
    { text #1 find_length substring$ find =
        { 
          replace *
          text #1 find_length + global.max$ substring$ 'text :=
        }   
        { text #1 #1 substring$ *
          text #2 global.max$ substring$ 'text :=
        }         
      if$       
    }         
  while$    
}         


FUNCTION {google}
{ duplicate$ empty$
    { pop$ "" }
    { "{\href{http://www.google.com/search?q=" swap$ duplicate$ " " "+"
    find.replace "}" "" find.replace "{" "" find.replace "\" "" find.replace
    "$" "" find.replace "^" "" find.replace swap$ "}{" swap$ "}}" * * * *}
  if$
}

FUNCTION {format.title}
{ title empty$
    { "" }
    { title "t" change.case$ google}
  if$
}

I’m reposting all my papers with these links:
Check it out

Update: You may want to be sure to set up your external links to be non-colored:


\hypersetup{colorlinks,linkcolor=blue,urlcolor=}

Switch Google web search to scholar search

Friday, May 11th, 2012

Google removed “Scholar” from the drop down list of choices when searching the web. I had become very used to searching for something, either from the main google page or my browsers address bar and then switching the search to google scholar. Now I would have to first go to scholar.google.com and retype the search query or copy and paste the query.

Finally instead I found the way to quickly change the URL at the top of the web search to switch it to a scholar search. If this is your web search url:


http://www.google.com/search?hl=en&client=safari&rls=en&q=Fast+Automatic+Skinning+Transformations&oq=Fast+Automatic+Skinning+Transformations&aq=f&aqi=p-p1&aql=&gs_l=serp.3..35i39.2032.2203.0.2388.2.2.0.0.0.0.70.124.2.2.0...0.0.wzP9uU0hsCc

just replace search with scholar


http://www.google.com/scholar?hl=en&client=safari&rls=en&q=Fast+Automatic+Skinning+Transformations&oq=Fast+Automatic+Skinning+Transformations&aq=f&aqi=p-p1&aql=&gs_l=serp.3..35i39.2032.2203.0.2388.2.2.0.0.0.0.70.124.2.2.0...0.0.wzP9uU0hsCc

Death Instinct

Sunday, August 28th, 2011

septermber

mixed fem google images search

Sunday, July 18th, 2010

I was mindlessly searching on google for “mixed fem”, as in “Mixed Finite Elements Method”, and when I switched to searching images I was surprised by the results:
screen shot of searching mixed fem on google images
Textbook covers, heat maps, marijuana and semi-nude wrestling. See for yourself!

Two thousand results on google for “How to turn off google buzz” only three days after release

Monday, February 22nd, 2010

2010 results for how to turn off google buzz three days after release

Only three days after its release (one day after google’s “skip this ad” on gmail), I searched for “How to turn of google buzz” (in quotes) and found about 2010 pages containing that quote.