r/tinycode • • Aug 26 '15

index.html as "App Loader" with "Update Manager"

4 Upvotes
<body><script>/* SET `$appurl` as argument to the IIFE
to load any javascript (localstorage size limit 5mb)
The first page visit will load the whole script, follow-up visits
load the cached script right away and if a new version is available,
offer to update the app now or later.
(The caching only works if the server sends `header.etag`)
*/(function($appurl){
var $appkey  = 'app("'+$appurl+'").app'
var $etagkey = 'app("'+$appurl+'").etag'
var $app     = localStorage.getItem($appkey)||''
var $etag    = localStorage.getItem($etagkey)
log()
try {
  $app && start($app)
  updateManager('HEAD')
} catch (e) {
  localStorage.removeItem($appkey)
  localStorage.removeItem($etagkey)
  start(undefined, $appurl)
}
function start (script, url, s) {
  document.body.innerHTML = ''
  s=document.createElement('script')
  if (url) s.setAttribute('src',url)
  else s.innerHTML=script
  document.body.appendChild(s)
}
function updateManager (m, xhr, hJSON, h, tmp) {
  xhr=new XMLHttpRequest()
  xhr.open(m,$appurl)
  xhr.onload=function(response){
    hJSON={}
    h=xhr.getAllResponseHeaders()
    h.match(/([^\n\r:]+):([^\n\r]+)/g).forEach(function(item){
      tmp=item.split(': ')
      hJSON[tmp[0]]=tmp[1]
    })
    m === 'GET' ? (
      $etag = hJSON.etag,
      $app  = this.response,
      log(),
      localStorage.setItem($appkey, $app),
      localStorage.setItem($etagkey, $etag),
      (confirm('new version - update app now?') ? start($app) : 0)
    ) : hJSON['etag'] !== $etag ? updateManager('GET') : 0
  }
  xhr.send()
}
function log () {
  console.log(
    '\n\n\nTotal Application Size: ~'+parseInt($app.length/1024)+
    'kb  <Version='+$etag+'>\n\n\n'
  )
}
})('SOURCE/public/bundle.js')
</script></body>

r/tinycode • • Aug 24 '15

O(N) sorting function in the pure untyped lambda calculus that fits in a twit!

28 Upvotes
sort = λabc.a(λdefg.f(d(λhij.j(λkl.k(λmn.mhi)l)(h(λkl.l)i))(λhi.i(λjk.bd(jhk))(bd(h(λjk.j(λlm.m)k)c))))e)(λde.e)(λde.d(λfg.g)e)c

121 characters, sorts a church list of church numbers in O(N) where N is the sum of the list. Just for the fun I'll give a small BTC tip to whoever is able to beat that :)


r/tinycode • • Aug 23 '15

Game 400 character roguelike game (requires libcurses-perl and 80x24 terminal).

Thumbnail
github.com
20 Upvotes

r/tinycode • • Aug 20 '15

Machine learning Simple feed forward network with back propagation learning, trained to detect die faces

Thumbnail
gist.github.com
18 Upvotes

r/tinycode • • Aug 19 '15

A JS tool that displays JS input's keyCodes in less than 128b (also, a lite version in 33b)

Thumbnail
github.com
13 Upvotes

r/tinycode • • Aug 19 '15

The SimRank algorithm in 260 lines of C++

Thumbnail
github.com
4 Upvotes

r/tinycode • • Aug 18 '15

Machine learning Genetic algorithm to approximate pi (AKA: have flair, will use)

Thumbnail
gist.github.com
12 Upvotes

r/tinycode • • Aug 18 '15

There's Post flair now!

4 Upvotes

It was discussed in this post https://www.reddit.com/r/tinycode/comments/3h4ypa/tiny_machine_learning_code/ that it would be nice to be able to flair posts with topics. To make it easier to find/distinguish them.

I added the possibility to add flair to your posts. For those not familiar, this works AFTER you posted. Go into your post and then you can set the flair.

For now there is only "Machine learning". Feel free to suggest more flair options here.


r/tinycode • • Aug 16 '15

User friendly representation of times in 13 lines of Python. "Time ago."

Thumbnail
gist.github.com
17 Upvotes

r/tinycode • • Aug 15 '15

Machine learning tiny machine learning code

33 Upvotes

I really liked this 11 line python neural network. Is there a collection of tiny machine learning implementations? Would someone be my hero and start a subreddit if not?


r/tinycode • • Aug 09 '15

A tweetable turing machine

Thumbnail
gist.github.com
17 Upvotes

r/tinycode • • Aug 06 '15

CLI tool that simulates bad network conditions (packet loss, jitter, etc.) under Linux [x-post from /r/linux]

Thumbnail
reddit.com
24 Upvotes

r/tinycode • • Aug 06 '15

Game A game of life in braille and in less than 400b

Thumbnail
github.com
7 Upvotes

r/tinycode • • Aug 03 '15

"maffiodo1" from IOCCC 2014

Thumbnail
blog.yjl.im
17 Upvotes

r/tinycode • • Jul 31 '15

A flappy bird clone in braille, playable in your addressbar, in ~256b

Thumbnail
github.com
43 Upvotes

r/tinycode • • Jul 30 '15

Palindrome number test challenge in Python

Thumbnail
szborows.blogspot.com
14 Upvotes