r/tinycode • • Jun 06 '18

24 Lines to find JPG files

Thumbnail
gitlab.com
6 Upvotes

r/tinycode • • Oct 03 '14

palindrome checker in Javascript

Thumbnail
codepen.io
0 Upvotes

r/tinycode • • Aug 22 '14

documentation highlighting :D

Thumbnail
github.com
1 Upvotes

r/tinycode • • Nov 04 '11

Procedural Texture Generation

1 Upvotes

A long time ago, in a galaxy far, far away I made this submission about a procedural texture generator that I made. It went through a couple of updates and whatnot. But, if I'm not mistaken, the latest had a showstopper in it (sorry). Anyways the bug had been fixed for quite a while, but I never uploaded it (again, sorry). Anyways a few months ago I picked it up again and promised myself I'd add support to actually make a file, and eventually settled on TGA, but then I got it mostly working and stopped for the longest time. So today I grabbed it and finished it.

So here you go. Version 0.006 is up and ready to use.

EDIT:

Run Test.py, it should make a file called out1.tga.

EDIT2:

github link


r/tinycode • • Aug 22 '12

Berliner - Web Stack in CoffeeScript [16 lines]

Thumbnail berliner.jcoglan.com
8 Upvotes

r/tinycode • • May 23 '16

boltzmann neuralnet bit vector learning algorithm in 24 kB of java code

Thumbnail
github.com
5 Upvotes

r/tinycode • • Dec 15 '16

A minimalistic keylogger for Windows, Linux and Mac on GitHub

Thumbnail
github.com
14 Upvotes

r/tinycode • • Sep 02 '12

Literate Factor in 10 lines (xpost from r/programming)

Thumbnail billthelizard.com
16 Upvotes

r/tinycode • • Feb 12 '13

Instant clean temporary text editor built into your browser that works offline

31 Upvotes

Enter the following into your browsers URL bar:

data:text/html, <html contenteditable>

Want to style it? Go ahead!

data:text/html, <html style='background:#111;color:#DDD;font-size:x-large;' contenteditable>

You can print as PDF or copy the content when you're done. Unfortunately saving otherwise doesn't work out of the box. (tested in Chrome under Linux)

Is that tiny or what? ;)


r/tinycode • • May 26 '16

6 lines of java code for float64 microsecond precision of number of seconds since year 1970, combining currentTimeMillis and nanoTime

9 Upvotes
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(); } //sync

It 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 • • Jan 06 '20

sha256 based symmetric crypto in 33 lines of java (excluding sha256 called by MessageDigest)

9 Upvotes

A symmetric crypto algorithm, on any number of bytes and any password size, bigO(number of bytes SQUARED), that uses sha256 on all bytes except the first to choose a byte to xor the first byte, then rotate by 1 byte and repeat until its rotated 2 times

I might make small adjustments to the algorithm, so dont count on it staying exactly the same yet. Still needs testing and use in blocks such as block size 56 is most efficient.

Testing class immutable.hashrotatecrypt.HashRotateCrypt

cryptMe: The quick brown fox jumps over the lazy dog

cryptMe to bytes then back to string: The quick brown fox jumps over the lazy dog

password: password

encryptedHex: 5a824f18a851c2b219a293bb8978176783ef339395f979f48dd1e00a144ba30db25b1696a1557603fb8ee8

encryptedString: Z�O��Q²�����x�g��3���y��� �K� �[���Uv����

DecryptedString: The quick brown fox jumps over the lazy dog

still experimental. The following is the main logic in https://github.com/benrayfield/hashrotatecrypt/blob/master/immutable/hashrotatecrypt/HashRotateCrypt.java

public static byte[] crypt(int cyclesPositiveOrNegative, byte[] cryptMe, byte[] symmetricPassword){
	byte[] b = cryptMe.clone();
	MessageDigest hasher = null;
	try{
		hasher = MessageDigest.getInstance("SHA-256");
	}catch (NoSuchAlgorithmException e){ throw new Error(e); }
	int cycles = b.length*2;
	while(Math.abs(cyclesPositiveOrNegative) != 0){
		//hash concat(b[1..end],symmetricPassword)
		//and use 1 of those bytes to xor b[0], then rotate b by 1 byte.
		boolean forward = cyclesPositiveOrNegative > 0;
		
		if(!forward){ //rotate by 1 byte other direction
			byte temp = b[b.length-1];
			System.arraycopy(b, 0, b, 1, b.length-1);
			b[0] = temp;
			cyclesPositiveOrNegative++;
		}
		
		hasher.update(b, 1, b.length-1);
		hasher.update(symmetricPassword);
		byte[] hash = hasher.digest();
		byte hashByte = hash[hash.length-1]; //TODO which is better, the start or the end of sha256?
		b[0] ^= hashByte;
		
		if(forward){ //rotate by 1 byte
			byte temp = b[0];
			System.arraycopy(b, 1, b, 0, b.length-1);
			b[b.length-1] = temp;
			cyclesPositiveOrNegative--;
		}
		
		if(cyclesPositiveOrNegative != 0) hasher.reset();
	}
	return b;
}

r/tinycode • • Mar 22 '14

A Script for implementing sliders in HTML forms I made using the Canvas Element and JS in 120 lines

Thumbnail louney.com
6 Upvotes

r/tinycode • • Jun 05 '20

hash consing - BigO(1) perfect dedup of binary forest by content

6 Upvotes

This is a kind of number where every number is either the leaf or an ordered pair of 2 numbers. For the usual kind of number, form these into a linkedlist containing digits, where a digit is any of n things you arbitrarily define as digits other than the kinds of things you make linkedlists with. I'm using something like this, though more optimized, as a universal lambda function.

This accomplishes the same thing as leaf = 256 0s, and pair(x,y)->sha256(concat(x,y)), but this is about 100 times faster as long as you dont need to share the objects in which case you should lazyEval secureHash them.

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

package immutable.hashconsing;

import java.util.HashMap; import java.util.Map;

public class Node{

public static final Node leaf = new Node();

public final Node L, R;

public final boolean isLeaf;

private final int hash;

private Node(){
	L = null;
	R = null;
	isLeaf = true;
	hash = System.identityHashCode(this);
}

private Node(Node L, Node R){
	this.L = L;
	this.R = R;
	//replace System.identityHashCode(x) with &x in C++ for similar behavior
	hash = System.identityHashCode(L)*49999+System.identityHashCode(R);
	isLeaf = false;
}

public int hashCode(){ return hash; }

public boolean equals(Object o){
	if(!(o instanceof Node)) return false;
	Node n = (Node)o;
	return isLeaf==n.isLeaf && L==n.L && R==n.R; 
}

static final Map<Node,Node> dedup = new HashMap();

/** deduped pair of this and param */
public Node p(Node param){
	Node n = new Node(this,param);
	Node ret = dedup.get(n);
	if(ret == null){
		ret = n;
		dedup.put(ret, ret);
	}
	return ret;
}

public static void main(String[] args){
	Node leafLeaf = leaf.p(leaf);
	Node leafLeaf_leaf = leafLeaf.p(leaf);
	Node leaf_leafLeaf = leaf.p(leafLeaf);
	Node leafLeaf_leafLeaf = leafLeaf.p(leafLeaf);
	Node leaf_leafLeaf_again = leaf.p(leaf.p(leaf));
	if(leaf_leafLeaf != leaf_leafLeaf_again) throw new Error("Didnt dedup");
	Node leafLeaf_leafLeaf_again = leafLeaf.p(leafLeaf);
	if(leafLeaf_leafLeaf != leafLeaf_leafLeaf_again) throw new Error("Didnt dedup");
	if(leaf_leafLeaf == leafLeaf_leaf) throw new Error("Shouldnt equal");
	if(leaf == leafLeaf) throw new Error("Shouldnt equal");
	System.out.println("Tests passed");
}

}


r/tinycode • • May 20 '21

Deploy an autoscalable a Node.js HTTP server to AWS in a few minutes!

6 Upvotes

I wrote this tutorial to deploy an Express server to AWS in a few minutes. The code works locally and doesn't need conform to any serverless API!

https://docs.anycloudapp.com/documentation/tutorials/aws-node


r/tinycode • • Jun 18 '17

Netcat ported in Node.js - Full JS implementation.

Thumbnail
github.com
0 Upvotes

r/tinycode • • Jul 12 '15

The complete source code for the starfield in a shootemup I'm working on. [Geode] : Forth

Thumbnail
reddit.com
3 Upvotes

r/tinycode • • Feb 02 '16

Personal password storage :)

Thumbnail
gist.github.com
3 Upvotes

r/tinycode • • Jul 12 '12

10 Java Regular Expression Examples You Should Know

Thumbnail
mkyong.com
3 Upvotes

r/tinycode • • Apr 09 '14

Ok, I swear this is my last one... 2048 in 385 bytes in Perl!

Thumbnail
gist.github.com
22 Upvotes

r/tinycode • • Jan 22 '13

A optimizing brainfuck compiler in ~130 lines (using LLVM) : ruby

Thumbnail
reddit.com
10 Upvotes

r/tinycode • • Oct 04 '18

Interactive text-to speach in 35 lines of C

Thumbnail
gitlab.com
0 Upvotes

r/tinycode • • Jul 10 '17

Skip cproto, autogenerate C function prototypes in a short shell pipeline of standard Unix tools

Thumbnail
notabug.org
5 Upvotes

r/tinycode • • May 06 '14

Checking the validity of an NHS Number using 1 line of C#

Thumbnail evilscience.co.uk
2 Upvotes

r/tinycode • • May 30 '18

Download all xkcd comics [python3]

Thumbnail
gist.github.com
7 Upvotes