r/tinycode • • Oct 01 '13

Parse Lisp in five lines of code (and it's not written in Lisp)

5 Upvotes

It's Lua (5.1 or greater) and LPeg (0.12):

lisp = require "re".compile [[
prog    <-       {| list*                        |}
list    <- space {| '(' (atom / list)* space ')' |}
atom    <- space {  [^%s();]+                     }
space   <- (%s / ';' [^%nl]* %nl)*
]]

The resulting Lisp code is stored in a nested Lua table.


r/tinycode • • Jul 02 '11

The Best bit of obfusicated c++ code I've even seen

11 Upvotes

r/tinycode • • Jul 13 '12

Remove all .svn folders from your code tree

11 Upvotes

find . -name .svn -exec rm -rf {} ;


r/tinycode • • May 28 '13

Ridiculously small and minimal Brainfuck interpreter in C.

Thumbnail
github.com
23 Upvotes

r/tinycode • • Jun 20 '15

redvoat - A tiny bookmarklet to copy r/tinycode posts to v/tinycode

Thumbnail pastie.org
0 Upvotes

r/tinycode • • Sep 21 '15

NLP, Toki Pona and Ruby - Tiny Code for a tiny Language?

Thumbnail greyblake.com
1 Upvotes

r/tinycode • • Jul 10 '11

Outside IP one-liner.

9 Upvotes

curl http://checkip.dyndns.com/ 2>/dev/null | sed 's/.*: \(.*\)<\/b.*/\1/'


r/tinycode • • Aug 31 '22

Minimalistic Data Structure Sketches

Thumbnail
okso.app
9 Upvotes

r/tinycode • • Jun 30 '11

Python simple http webserver. One liner.

Thumbnail
linuxjournal.com
4 Upvotes

r/tinycode • • Dec 05 '14

When somebody says 'some great program' in xxx-small number of bytes in C...

0 Upvotes

...how about when it's compiled? 150k? 1.5meg?

Those are not small.


r/tinycode • • Jun 14 '14

What the internet will look like without net-neutrality! [off topic]

Thumbnail
jointhefastlane.com
0 Upvotes

r/tinycode • • Aug 30 '15

JavaScript “maze generator” in a tweet • /r/programming

Thumbnail
np.reddit.com
6 Upvotes

r/tinycode • • Jun 22 '20

I created a perfect AI for Fruit Ninja

Thumbnail
youtube.com
25 Upvotes

r/tinycode • • Aug 16 '19

Any good C++ 1/2/3-liner useful for competitive programming ?

0 Upvotes

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 • • Nov 19 '15

fenc: a tool to just f^H^H^H^H^H^Hully encrypt a file

Thumbnail
github.com
13 Upvotes

r/tinycode • • May 16 '15

Super simple PStore based key/value store for minimal DB needs [ruby]

Thumbnail
gist.github.com
3 Upvotes

r/tinycode • • Jun 08 '15

An object model supporting inheritance in under30 lines of python

0 Upvotes

here's the link

Been working on this for a few days, the only parts relevant to the actual functionality are bind_method, new_object, and new_class, which take up around 30 lines. Everything else is just implementing example objects and testing.

It support basic inheritance. I should likely add error handling on the init method, and static variables, but wanted to post it now because its functional and really small.

EDIT: oh wait, you can do class/static data by saying static_value=15 in new_class


r/tinycode • • Mar 07 '13

FizzBuzz One-Liner (X-Post from /r/ReadableCode)

0 Upvotes

Original Post

Ok, I know this is the opposite of "ReadableCode" but I love refactoring little challenges like this (and Project Euler ones). Shame on me, but it's a PHP solution.

for($i=1;$i<=100;$i++)print((($i%15==0)?'FizzBuzz':(($i%5==0)?'Buzz':(($i%3==0)?'Fizz':$i)))."\n");

FizzBuzz for those interested.


r/tinycode • • Oct 22 '15

Bootable seek/multi-read in 382 bytes (6502 asm)

Thumbnail
github.com
0 Upvotes

r/tinycode • • Nov 06 '13

Simplistic extensible vector within 60 lines of C

Thumbnail
gist.github.com
0 Upvotes

r/tinycode • • Jul 19 '13

Four lines to make conditional operators in C and C++ (a little bit) more readable

0 Upvotes
#define CIF(expr)    ((expr)
#define CTHEN        ?
#define CELSE        :
#define CENDIF       )

Bam. That's it. And to prove that it works, a stupidly primitive pattern matcher: http://ideone.com/tvDOga

In short, I wrote it to make constexpr functions in C++ a little bit less spaghetticode-ish. I find it easier to read and maintain, that is.
The pattern matcher isn't really useful and just a side product, but a nice exercise, and also a nice way to dive into constexpr. I doubt anyone'll ever find any use in it, considering that C++11 has <regexp>. :-)


r/tinycode • • May 26 '16

The tiniest game for measuring general intelligence of AIs - Lets have a programming competition. What rules? such as code size, limiting max compute cycles and memory

2 Upvotes

Its so tiny that 2 independently created games have the exact same rules:

https://en.wikipedia.org/wiki/Matching_pennies

https://en.wikipedia.org/wiki/Odds_and_evens

Its the 2 choice version, without ties, of https://en.wikipedia.org/wiki/Rock-paper-scissors which has 3 choices.

The intelligence of it is bluffing to look more predictable than you are to fool the other player into doing something you can predict later.

The "equal" player wants the 2 bits to equal. The "xor" player wants them to not equal. 1 point per cycle. Both players see that they acted correctly when input bit equals the last bit they output.

var player = function(data){
    var bit = data.bit;
    data.state = ... observe then update this private player state with new thoughts ...;
    data.bit = ...return a bit, of 2 possible actions each player does each cycle...;
};

var play = function(playerEq, playerDataEq, playerXor, playerDataXor, cycles){
    var score = 0;
    for(i=0; i<cycles; i++){
        playerEq(playerDataEq);
        playerXor(playerDataXor);
        var eqOut = playerDataEq.bit == true; //compare to true in case its not a bit
        var xorOut = playerDataXor.bit == true;
        var eqWon = eqOut==xorOut;
        score += eqWon ? 1 : -1;
        playerDataEq.bit = xorOut;
        playerDataXor.bit = !eqOut; //so if play against self there is no nash-equilibrium
    }
    return score/Math.sqrt(cycles); //1 standard deviation if they play randomly
}

If I put this and some examples in https://en.wikipedia.org/wiki/Node.js where we could import other players with a single line of javascript, would that still count as tinycode?


r/tinycode • • Apr 02 '17

Question Looking for a live updating (photo) gallery script

0 Upvotes

I'm looking for a script, which allows people to upload images via a website to a local server which also runs a gallery script to display a live updating slideshow in a browser.

The setup is for an offline event, where I bring a tiny Debian box and attach it to a screen and make it an access point for people to upload to.

I google around but could so far only find very powerful gallery scripts aimed at pre-set folders or not on live updates


r/tinycode • • Apr 08 '18

A replacement for Make in 1/1000th the size.

Thumbnail
github.com
9 Upvotes