Latest Posts

Keith Devlin, The Man of Numbers (2011)

themanofnumbers_keithdevlin_2011 Keith Devlin, The Man of Numbers (2011) is a largely historical biography about Leonardo Bigollo (~1170 – ~1250 CE), better known in his own time as Leonardo Pisano or in our time as Leonardo Fibonacci.

Fibonacci is best known for the sequence of Fibonacci numbers (1,2,3,5,8,13,21… etc), whose limit of ratios we know as the Divino Proportion coined by Luca Pacioli (1445-1517), the Golden Ratio coined by Martin Ohm (1792-1811), or as it is called in Euclid’s Elements, the extreme and mean ratio. Fibonacci numbers are only one of several mathematical puzzles posed in his Liber Abaci (1202), the Book of Calculation, a teaching book for mercantile administration, in which Leonardo describes the basics of the Hindu-Arab counting system, at the time largely unknown in Europe, where the Roman and medieval systems were still dominant. Devlin argues that the Liber Abaci caused a mathematical revolution that facilitated the mercantile boom of the Renaissance.

The book by Devlin is a little light on facts and mathematics, though none are absent, maybe because there are only few historic facts known about Leonardo, and because most of the math in our time sounds like very basic modern mathematics described in very cryptically described textual puzzles. If you really want to know everything about Fibonacci’s influence, you should read the translation of the Liber Abacci. If you really want to know everything about the mercantile revolution, you should read perhaps about Cosimo de’ Medici (1389-1464), or about the scientific revolution, you should read perhaps about Galileo Galilei (1564-1642).

 

Send a multipart/form-data request in PHP

GET

To List your current indexes with ‘standard’ flavor use a GET request to the List Indexes API.


$url_listindexes = 'https://api.idolondemand.com/1/api/sync/listindexes/v1';
$params1 = 'flavor=standard&apikey='.$apikey;
$response = file_get_contents($url_listindexes .'?'.$params1);
if($response) { $json = json_decode($response); if($json){ $indexes = $json->index; } return $indexes; }

POST

POST multipart/form-data with native PHP


function send_multipart_post_message($sync_or_async, $json1){
$url = "https://api.idolondemand.com/1/api/".$sync_or_async."/addtotextindex/v1";
// using WordPress custom functions to retrieve index and apikey
$index1 = wp_idolondemand_get_setting('index');
$apikey = wp_idolondemand_get_setting('apikey');
$eol = "\r\n";
$data = '';
$mime_boundary=md5(time());
//
$data .= '--' . $mime_boundary . $eol;
$data .= 'Content-Disposition: form-data; name="apikey"' . $eol . $eol;
$data .= $apikey . $eol;
$data .= '--' . $mime_boundary . $eol;
$data .= 'Content-Disposition: form-data; name="index"' . $eol . $eol;
$data .= $index1 . $eol;
$data .= '--' . $mime_boundary . $eol;
$data .= 'Content-Disposition: form-data; name="json"; filename="allposts.json"' . $eol;
$data .= 'Content-Type: application/json' . $eol;
$data .= 'Content-Transfer-Encoding: base64' . $eol . $eol;
$data .= base64_encode($json1) . $eol;
// alternatively use 8bit encoding
//$data .= 'Content-Transfer-Encoding: 8bit' . $eol . $eol;
//$data .= $json1 . $eol;
$data .= "--" . $mime_boundary . "--" . $eol . $eol;
$params = array('http' => array(
'method' => 'POST',
'header' => 'Content-Type: multipart/form-data; boundary=' . $mime_boundary,
'content' => $data
//'proxy' => 'tcp://localhost:8888' //use with Charles to catch http traffic
));
$ctx = stream_context_create($params);
$response = file_get_contents($url, FILE_TEXT, $ctx);
return $response;
}

(more…)

Vignettes of Lost Men: Stephen Crane

Stephen Crane wrote ‘we are the most successful in art when we approach the nearest to nature and truth.’ He described the inconsistent vocation of the soul of man and the incapacity of man to uphold a straight moral line. His novel the Red Badge of Honor gave him considerable success, and is perhaps a great read to reflect on the choices of former POW Bowe Bergdahl. Now forgotten and sinking to the lesser bowels of history, another unconventional thinker and a flickering light of guidance, lost to our collective memory. We are all in an open boat, at risk to capsize as soon as we shift our positions, so we stay put and drift along.

New Yorker: The Hectic Career of Stephen Crane

[JavaScript] Find Related Concepts as D3js Bubble Chart

The Find Related Concepts API from IDOL OnDemand returns the most relevant terms and concepts from related documents. Here’s represented as a D3 Bubble Chart. Thanks to incredibly good work by Mike Bostock. For a description of the API go here https://www.idolondemand.com/developer/apis/findrelatedconcepts#overview
For D3 Data-Driven Documents go here: http://d3js.org

HTML5 and JavaScript: Flip an Image using HTML5 Canvas

See the working code example on jsfiddle.


<!DOCTYPE html>
<html>
<head>
<title>Flipping an Image Horizontally and Vertically</title>
<script src="jquery-1.11.1.min.js"></script>
<script type="text/javascript">
var imageurl = null;
//
$(document).ready( function() {
$('#loadimage').click(function() {
urlProvided();
});
$('#mirrorh').click(function() {
mirror(1,0);
});
$('#mirrorv').click(function() {
mirror(0,1);
});
});
//
function urlProvided() {
var userinput = document.getElementById('imageurl');
imageurl = userinput.value;
loadImage();
}
function loadImage(){
//
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
//
var img = new Image();
img.src = imageurl;
img.onload = function(){
ctx.drawImage(img,0,0);
};
//
var w = img.width;
var h = img.height;
canvas.width = w;
canvas.height = h;
}
//
function mirror(mirrorh,mirrorv){
//
var canvas=document.getElementById('canvas');
var ctx=canvas.getContext('2d');
//
var img = new Image();
img.src = imageurl;
//
ctx.clearRect(0,0,canvas.width,canvas.height);
ctx.save();
//
var w = img.width;
var h = img.height;
if(mirrorh){
ctx.scale(1, -1);
ctx.translate(0, -h);
}
if(mirrorv){
ctx.scale(-1, 1);
ctx.translate(-w,0);
}
ctx.drawImage(img,0,0,img.width,img.height,null,null,w,h);
ctx.save();
}
</script>
</head>
<body>
<div>
Your image URL: <input type="text" id="imageurl"></input><button id="loadimage">load image</button>
</div>
<div>
<button id="mirrorh">mirrorh</button>
<button id="mirrorv">mirrorv</button>
</div>
<div>
<canvas id="canvas"></canvas>
</div>
</body>
</html>

The Perception of Sea Time

she dances like bouncing particles
on top of the foaming waves
a venus rising out of passing water
from the splashed semen of Uranus

she moves like the soul a ship
a glazing stare of round fish eyes
hiding under the surface fleece
like the faring sea I see

then feel the sudden calm
before the rush of changing motion
a roaring gust of salty wind
that combs through her light blond hair

awning layers of hovering clouds
along the singing circles of air
casting a landscape of shadows
on the ocean’s running blues

CSharp: POST Request to Query API and JSON Parsing

Use the System.Net.WebClient object to make a POST request in C#. For parsing JSON, you can use Json.NET by James Newton-King. Install both packages using the NuGet Package Manager. This code example posts a search for the text ‘Dog’ to the Query API. This example uses the text parameter, if you want to use the file parameter to upload a document as a search parameter you will need to use multipart/form content type, with for instance RestSharp client for .NET.


string apiKey = "your-apikey";
string iodURL = "https://api.idolondemand.com/1/api/sync/query/v1";
WebClient webClient = new WebClient();
NameValueCollection formData = new NameValueCollection();
formData["apikey"] = apiKey;
formData["text"] = "Dog";
byte[] responseBytes = webClient.UploadValues(iodURL, "POST", formData);
webClient.Dispose();
UTF8Encoding enc = new UTF8Encoding();
string json = enc.GetString(responseBytes);
//Debug.WriteLine(json);

The JSON response is serialized using Json.NET into .NET Objects representing the JSON response as a DocumentList of Document type.


DocumentList documentList = JsonConvert.DeserializeObject(json);
List docs = documentList.Documents;
//
public class DocumentList
{
[JsonProperty("documents")]
public List Documents { get; set; }
}
public class Document
{
[JsonProperty("reference")]
public string Reference { get; set; }
[JsonProperty("weight")]
public double Weight { get; set; }
[JsonProperty("links")]
public List Links { get; set; }
[JsonProperty("index")]
public string Index { get; set; }
[JsonProperty("title")]
public string Title { get; set; }
[JsonProperty("content")]
public Object Content { get; set; }
}

The above code will parse the JSON response from IDOL OnDemand.


{
"documents" : [{
"content" : { },
"index" : "news_eng",
"links" : [ "DOG" ],
"reference" : "http://feeds.theguardian.com/c/34708/f/663840/s/3605393d/sc/38/l/0L0Stheguardian0N0Cchildrens0Ebooks0Esite0C20A140Cjan0C170Creview0Etom0Ewatson0Estick0Edog0Ewants0Ea0Ehot0Edog/story01.htm",
"title" : "Stick Dog Wants a Hot Dog by Tom Watson - review",
"weight" : 89.5
},{
"content" : { },
"index" : "news_eng",
"links" : [ "DOG" ],
"reference" : "http://feeds.theguardian.com/c/34708/f/663879/s/37621ce9/sc/38/l/0L0Stheguardian0N0Ccommentisfree0C20A140Cfeb0C210Cdog0Eattacks0Eon0Echildren0Etragic0Etriggers/story01.htm",
"title" : "Dog attacks on children are tragic – but we can try to understand the triggers | Deborah Orr",
"weight" : 88.010000000000005
}
]}

Access the properties as normal:


foreach (Document doc in docs)
{
Debug.WriteLine("doc.reference: " + doc.Reference);
}

To do a multipart/form-data POST request, the simplest way is to use a client like RestSharp, which you can install via NuGet:


string apiKey = @"your-apikey";
string iodURL = @"https://api.idolondemand.com/1/api/sync/query/v1";
string file = @"C:\Users\user1\Documents\iod\TheSecretSpiritualHistoryOfCalculus_ScientificAmerican.pdf";
var client = new RestClient(iodURL);
var request = new RestRequest("", Method.POST);
request.AddParameter("apikey", apiKey);
request.AddFile("file", file);
RestResponse response = (RestResponse) client.Execute(request);
string content = response.Content;
Debug.WriteLine("status: "+ response.StatusCode + ", content: " + content);

Brian Grinstead wrote a great article on a Multipart form post in C# implementation, for those who are interested.

Silhouettes (2) (Bengaluru)

A slim figure in an hotel uniform greets me, even among the aligned Indians waiting with name cards held up at the exit of the arrival hall, he looks remarkably slender. His cheekbones, his carved out, dark eyes, his black eyebrows that cover his stare, and his full mustache characterize his bony face. During the drive from the airport to the hotel, I mainly look at the strip of mirrored eyes, as he proudly tells the story of his love marriage. After five years, their child compelled his wife’s family to reconcile and compromise, but it was a long story he proudly tells.