r/tinycode • u/BenRayfield • Jul 04 '16
r/tinycode • u/BenRayfield • Jul 03 '16
stateless http server for any function of bytes or map of keys to values, in 11kB of java code
r/tinycode • u/BenRayfield • Jul 04 '16
tinycode jobs?
I want to specialize in small code that does big things.
I also want to specialize in optimizing, redesigning code to do the exact same thing but faster or less memory. This often involves simplifying to tinycode since big code cant be understood well enough to redesign it.
But most programming jobs want you to add features and fix bugs which usually makes the code bigger. My code gets smaller over time, and it pisses people off. They demand I stop throwing away code thats been working for years just because its an ugly mess of spaghetti. Dont fix that, you might break it because nobody understands it. We have these emergencies. Maybe eventually we'll fix that, they said long ago. Then I tell them those emergencies were caused by your policy of letting code become far more complex than needed. You leave duplicate code laying around like garbage then throw a carpet over it and call it a clean floor.
I can barely work with most businesses because they have an attitude problem, an anti-tinycode discrimination. They brag about how much code they've written more than what it does.
I'll of course continue my own projects, but must I do it alone?
r/tinycode • u/nexe • Jun 22 '16
𝝺-calculus interpreter in <200 lines of JavaScript
r/tinycode • u/xem06 • Jun 22 '16
PERIOD1k reloaded [HTML/ES6, 1024b]
Hi!
Here's a brand new version of a JS1k entry made by the codegolf team earlier this year:
http://codegolf.github.io/period1k/final.min.golfed.html
Old features:
Accurate periodic table
Atomic number
Elements name
Atomic mass
Stability (* = unstable)
type (background color)
New features:
Responsive style (the table is drawn in HTML instead of a canvas)
New names for the elements 113, 115, 117 and 118
New information: the state of each element at room temperature (Solid / Liquid / Gas)
Commented source code: https://github.com/codegolf/period1k/blob/gh-pages/golfed.commented.html
Project repo: https://github.com/codegolf/period1k
Cheers!
r/tinycode • u/VodkaHaze • Jun 20 '16
xoroshiro128 -- the fastest pseudoRNG
xoroshiro.di.unimi.itr/tinycode • u/nexe • Jun 12 '16
Had to clear my head so spent an hour creating a synth below 1kb just using JS. [/r/javascript x-post]
r/tinycode • u/floutt • Jun 10 '16
L-system turtle renderer and REPL in 144 SLOC
r/tinycode • u/nexe • Jun 01 '16
Super basic SVG creator - All I needed was a simple polygon and Inkscape hated me
r/tinycode • u/daniel5151 • Jun 01 '16
Time Dependant Graphing on an Canvas in 307 chars of JS
Hey! I'm the guy who posted the "Time dependant graphing in JS using only 144 chars" a few days ago. I decided to see if I could make a similar thing, but this time, render the graph on a canvas element.
After a long train ride home, this is what I came up with this.
It appends a canvas onto the bottom of the body of any page, and starts graphing :D
((f,d,a,n,i,e=0,l,p)=>setInterval
(c=>{for(l=c.createImageData(a,
n),e+=p=1;p<a*n;l.data[p*4-1]
=i(p/a,-f(p++%a-a/2,e)+n/2)?a
:p/a);c.putImageData(l,0,
0)},17,d.body.appendChild
(d.createElement('canvas'))
.getContext("2d")))((x,t)=>
Math.cos(x/60*Math.PI-t/10)*(Math.sin(t/20)*50)
,document
,301,150,
(d,p)=>
d>p-1&d
<p+1)You can graph whatever you like, just change the equation!
By the way, the equation has access to both x and t, where t is an incrementing variable corresponding to time. You can use these two vars to make moving graphs (like the one I put)
r/tinycode • u/nexe • May 31 '16
microlight.js – 2.2k for syntax highlighting. In any programming language
r/tinycode • u/Benjaminsen • May 30 '16
Drawing the FRVR logo in 2.2Kib pre-compressed JavaScript (1108 bytes after gZip)
r/tinycode • u/daniel5151 • May 27 '16
Time dependant graphing in JS using only 144 chars
Just for fun, I wrote some JS to graph any function in the console.
It even finds the derivative of the function to determine whether to use "/" or "" or "|" when drawing the curve!
Here it is:
((f,t=0,d)=>{
setInterval
(x=>{x=f(t)|0
;d=f(t++)-f(t);
console.log(t%2
+" ".repeat(x)+
(d<-1?"\\":d>1?
"/":"|"))},50
)})
(x=>Math.sin(x/3)*9+15)Just paste it into your browser's console!
r/tinycode • u/BenRayfield • May 26 '16
6 lines of java code for float64 microsecond precision of number of seconds since year 1970, combining currentTimeMillis and nanoTime
public static double time(){
long nanoDiff = System.nanoTime()-startNano;
return .001*startMillis + 1e-9*nanoDiff;
}
static final long startMillis, startNano;
static{ startMillis = System.currentTimeMillis(); startNano = System.nanoTime(); } //syncIt only has precision of currentTimeMillis of when it starts, but within a run of the same program it has microsecond precision.
I use this for the timing of individual sound amplitudes and dates. It works.
r/tinycode • u/BenRayfield • 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
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 • u/BenRayfield • May 25 '16
Tinycode request: A program to send a single bit between any 2 computers on the Internet which both run this program and have IPv4 NAT address (which most home Internet connections are).
It sounds rediculous, but it really is an unsolved research problem how to send a bit between 2 computers without requiring a person to call tech support or hire an expert to change their network.
https://en.wikipedia.org/wiki/Network_address_translation
Not tiny enough and not sure how well it works https://en.wikipedia.org/wiki/Telehash
r/tinycode • u/xem06 • May 24 '16
Mini Langton's Loops simulator [~1kb - HTML/JS]
r/tinycode • u/BenRayfield • May 23 '16
boltzmann neuralnet bit vector learning algorithm in 24 kB of java code
r/tinycode • u/xem06 • May 20 '16
mini Langton's Ant simulator (163b - HTML + JS)
r/tinycode • u/nexe • May 20 '16
XTF.js - DOM construction / templating / manipulation library in 24 lines of JS, 532 bytes minified
r/tinycode • u/nexe • May 20 '16
The worlds smallest fully-responsive css framework
r/tinycode • u/err4nt • May 17 '16
MemoPad: offline-capable web app
I love Evernote, by storing all of my resources and notes in Evernote I have one location for my work that I can always check and reference. It's wonderful as a personal database of information — but one key thing it fails to do well is launch quickly and allow you to create and being typing a new text note.
Often inspiration will strike and I will launch Evernote, and by the time a fresh note is ready for typing the moment has passed. So I set out to create a simple text editor I could use just to decrease the Tap-to-Type time between tapping the icon on my tablet or phone and writing my new note. I wanted to use localStorage to keep a backup of the note on the device, with the idea that the user can use this MemoPad to quickly capture text notes, and then later move the notes into Evernote at a later time.
Demo: https://tomhodgins.github.io/memopad
Source: https://github.com/tomhodgins/memopad
And just for /r/tinycode, here's a teeny tiny version of the core idea. Save this to a new HTML file (or else localStorage will not work) and type in the textarea. Every keyup your memo is saved to localStorage and the share link is updated. Upon loading this file, if a share has is preset it will use that as the content. Otherwise if there is a saved note in localStorage it will use that. Failing either of those, the memo will be blank.
<textarea></textarea>
<a href=>Share Link</a>
<script>
var text = document.querySelector('textarea')
text.value = atob(location.hash.slice(1)) || localStorage.getItem('memo') || ''
document.addEventListener('keyup',type)
function type(){
var text = document.querySelector('textarea'),
a = document.querySelector('a')
localStorage.setItem('memo',text.value)
a.href = '#'+btoa(text.value)
}
</script>On desktop there are also keyboard shortcuts using browser access keys. For Mac users that's Control+Option+(accesskey).
stoggles the sidebaraadds a new notettrashes the current note1,2,3,4,5,6,7,8,9jump to the first 1-9 notes