4Chan API – Cross-Domain Image Fetcher – Usage + Examples

The following example on my GitHub project-page, shows, hopefully a clear way, on how to do some Ajax requests on client side, fetching each of the threads in a board, in which all the posts, and all the image links within, 4chan_api

after fetching the information, a Handlebars-Mustache logicless template is using the aggregated data (images) to build a simple gallery,
which uses jQuery’s lazy-loading, so only images within the close-range of the browser’s VIEWPORT will be fetched from 4Chan (saving their’s data plan).

this is mainly academic, since the 4Chan-API documentation is quite poorly explained..

Protected: צבע אדום API

This content is password protected. To view it please enter your password below:

Enter your password to view comments.

Cross-Servers Output – Make IIS ASP.Net Unicode Play Nice With PHP UTF-8


An IIS server outputs a JSON I want to use,
this is the story’s beginning…

The first investigation is to open the resource with Developer-Tools (Chrome) or Firebug (Firefox) or Fiddler opened in the background and look for the server and X-Powered-By headers.
in my case my *suspiciousness* proven worthy "server: Microsoft-IIS/6.0" "X-Powered-By: ASP.NET"

-try to read the remote-JSON, using PHP’s file_get_contents
then you’ll output it to your text/plain, UTF-8 page,
and you’ll see it *all* break.

why the example breaks, why PHP does not read it properly?

for this we should answer another question first:
why viewing content on your browser “simply works” ?
well, it does not “simply works”, browsers tend to be very (very!) content-smart, providing on-the-ply pre-process encoding heuristics to fix incompatibilities and essentially can sort-of ‘read the result’ and decide if the result is properly displayed (if not, an alternative encoding will be used..)

all goes well for PHP if your content is UTF-8 and you’re applying needed changes or if your input is English-like based characters (even extended ASCII will do, basically the native interrupter is ISO-8859-1),

That IIS outputs a JSON that its content includes non-English (Hebrew), non-UTF-8 characters,
Non-English characters are basically non-fallback’able (I’ve just made that word.. but I promise you, that you’ll be using it yourself in a second you’ll be using it yourself in your next staff meeting.),

its UNICODE, and not the good one..
did you ever made a PHP script to handle the new XLS (XLSX) or DOCX format? nightmare right?
there are some ugly hacks but basically you’ll need to push some bits,
writing BOM (as in Unicode’s BOM) before writing the text..

understanding this, make reversing the process more reasonable,

first lets set OUR (as in.. our php script) to be normal, UTF-8 charset and encoded content.
next read the content of the remote JSON, and trim that UNICODE BOM prefix
next, echo some of the UTF-8 BOM (optional) and use mb_convert_encoding to change that horrible UTF-16LE into lovely UTF-8, echo the result,

and you’ve just made yourself some middleman interruptor, you can use it like this, or wrap it with some URL arguments to provide extra features (JSONP’s callback method, diffrent-mimetype, post-processing, all the response-headers as DEBUG-mode, etc…)



bootstrap.htaccess filter_module error on GoDaddy

The following part from https://github.com/billpatrianakos/matvre/blob/master/bootstrap.htaccess does not seems to be working with GoDaddy’s servers so remove it… unless you like the “Server Error 500” thing…

# HTML, TXT, CSS, JavaScript, JSON, XML, HTC:

  FilterDeclare   COMPRESS
  FilterProvider  COMPRESS  DEFLATE resp=Content-Type $text/html
  FilterProvider  COMPRESS  DEFLATE resp=Content-Type $text/css
  FilterProvider  COMPRESS  DEFLATE resp=Content-Type $text/plain
  FilterProvider  COMPRESS  DEFLATE resp=Content-Type $text/xml
  FilterProvider  COMPRESS  DEFLATE resp=Content-Type $text/x-component
  FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/javascript
  FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/json
  FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/xml
  FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/xhtml+xml
  FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/rss+xml
  FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/atom+xml
  FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/vnd.ms-fontobject
  FilterProvider  COMPRESS  DEFLATE resp=Content-Type $image/svg+xml
  FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/x-font-ttf
  FilterProvider  COMPRESS  DEFLATE resp=Content-Type $font/opentype
  FilterChain     COMPRESS
  FilterProtocol  COMPRESS  DEFLATE change=yes;byteranges=no

also this..

# Rename session cookie to something else, than PHPSESSID
php_value session.name coolcookiename

Wamp 2.2 (Apache 2.4.2) SSL Support – the new version of wamp

part #1. create a nice fat crt.
(pre: download openssl, install, add to bin/ folder to path, create new folder c:\tmp, cd c:\tmp, exe. commands)


openssl req -new> webserver.csr
openssl rsa -in privkey.pem -out webserver.key
openssl x509 -in webserver.csr -out webserver.cert -req -signkey webserver.key -days 99999


openssl genrsa -out webserver.csr 4096
openssl req -nodes -newkey rsa:4096 -keyout privkey.pem -out webserver.cert
openssl rsa -in privkey.pem -out webserver.key

result is: .rnd, privkey.pem, webserver.cert, webserver.csr, webserver.key

part #2:
new folder C:\wamp\OpenSSL\
inside: new folders: certs, crl, newcerts, private

copy:

c:\tmp\webserver.cert -> C:\wamp\OpenSSL\certs\
c:\tmp\webserver.csr -> C:\wamp\OpenSSL\certs\
c:\tmp\webserver.key -> C:\wamp\OpenSSL\certs\

c:\tmp\.rnd -> C:\wamp\OpenSSL\private\
c:\tmp\privkey.pem -> C:\wamp\OpenSSL\private\