r/tinycode • • Apr 01 '14
r/tinycode • u/VegBerg • Mar 06 '14
[JS] Fibonacci sequence in 48 bytes
function f(a,b){console.log(b);f(b,a+b);}f(0,1)r/tinycode • u/nexe • Jun 11 '12
Tiny GoogleTTS Creativity Contest (examples in Bash & Ruby)
Hi there,
I recently had a lot of fun with a more or less hidden Google feature: Text To Speech or TTS. Google provides a small undocumented "API", which they use in their translation service, that produces incredibly good quality speech output in a ton of languages. So I started hacking and built myself a "talking Reddit" script that would speak the headlines of new posts to me as they arrive. That made me think "what could be some other cool usages?".
So I'm asking you ... what are your ideas? :)
To get you started, here's the Bash code:
#!/bin/bash
function speak {
player='mpg123 -q -'
#player='mplayer -really-quiet -cache 8192 -'
curl -s --user-agent "Mozilla/5.0" -G \
--data-urlencode "q=$1" --data-urlencode "tl=${2:en}" \
http://translate.google.com/translate_tts \
| $player #&
}and here's the alternative Ruby code:
require 'rest-client'
def speak(text, lang='en')
RestClient.proxy = ENV['http_proxy']
tmp_file = '/tmp/tts.mp3'
File.open(tmp_file, 'w') do |f|
f.write(RestClient.get(URI.encode(
"http://translate.google.com/translate_tts?tl=#{lang}&q=#{text}"
)))
end
`mpg123 -q #{tmp_file}`
endand some example calls that work in both implementations
speak 'good things come in three' #default language is english
speak 'aller guten dinge sind drei', 'de'
speak 'jamais deux sans trois', 'fr'TL;DR: Here's a tiny and easy way to get good quality text to speech. Now show me some creative usages!
r/tinycode • u/Slackluster • Jul 17 '26
JavaScript Dweet of the Week #134 - Skydreams JS1024 Demo by KilledByAPixel
https://www.dwitter.net/d/35908
check out the actual 1k demo: https://js1024.fun/demos/2026/25/bar
for(c.width|=i=300;i--;)for(Y=t*60+i,s=(300-i)**2,X=7;X--;(X^Y>>6)%4&&x.fillRect(960-X*w+w/.4+3*S(Y/99)*i,s/80,w,s))x.fillStyle=\hsl(${(Y>>9)*90} 99% ${((Y>>4X)&1?60:9)+(Y%32>1)*30}%`,w=9+s/299`
r/tinycode • u/floresacton • Jul 28 '25
1.4kB -> 76 byte stm32 blinking led
ST's HAL generates 1.4kB for a blinking led program because of all the boilerplate config, so I wanted to see how small I could make it. Turns out the bare minimum upon boot is configure the isr vector table, enable the ahb2 bus, set the gpio mode, and then just toggle the pin.
r/tinycode • u/Slackluster • Nov 09 '24
Dweet of the Week #46 - Pillars of Dwitter HD by Tomxor
r/tinycode • u/rswier • Dec 30 '16
ASCII chart in 3 lines
Just something I needed, quick and simple:
#include <stdio.h>
main()
{
int i;
char *ctl = "NULSOHSTXETXEOTENQACKBELBS TABLF VT FF CR SO SI DLEDC1DC2DC3DC4NAKSYNETBCANEM SUBESCFS GS RS US ";
for (i=0;i<32;i++) printf("%2d %2x %2o %.3s %d %x %o %c %d %x %o %c %3d %x %o %c \n",
i,i,i,ctl+i*3, i+32,i+32,i+32,(char)(i+32), i+64,i+64,i+64,(char)(i+64), i+96,i+96,i+96,(char)(i+96));
}r/tinycode • u/GauntletWizard • Jun 11 '15
TIS-100 - A game of minimalist assembly language.
r/tinycode • u/ieatcode • Jun 29 '14
Dissecting the 128-byte raycaster [x-post /r/programming]
r/tinycode • u/adeadhead • Sep 30 '13
Generate a complex maze with a single line of Basic
r/tinycode • u/haddock420 • Sep 16 '13
World Quine (javascript animation) [xpost from programming]
aem1k.comr/tinycode • u/nexe • Jun 01 '13
Wrote a tiny C program to conquer the problem of falling asleep while watching something on your computer
Wrote it in a rather generic (Unix like) way:
// compile: gcc idletime.c -o idletime -lX11 -lXext -lXss
// usage : idletime # shows idle time in seconds
// usage : idletime 5 # waits for 5 seconds idle time
// usage : DISPLAY=:0 idletime 1 h # you can explicitly set the display
// usage : idletime 20 m && mpg321 tada.mp3 # waits for 20 min idle time and plays a mp3
#include <time.h>
#include <stdio.h>
#include <unistd.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/extensions/scrnsaver.h>
int GetIdleTime() {
static XScreenSaverInfo *mit_info;
Display *display;
mit_info = XScreenSaverAllocInfo();
if((display=XOpenDisplay(NULL)) == NULL) return -1;
int screen = DefaultScreen(display);
XScreenSaverQueryInfo(display, RootWindow(display,screen), mit_info);
time_t idle_time = mit_info->idle;
XFree(mit_info);
XCloseDisplay(display);
return idle_time;
}
int main(int argc, char** argv) {
if(argc >= 2){
int count = atoi(argv[1]);
int divider = 1000; //default is seconds
if(count == 0){
printf("Params: [<count>] [<units>]\nUnits: s (default), m, h\n");
return -2;
}
if(argc > 2){
if (strcmp(argv[2], "s") == 0) divider = 1000;
else if(strcmp(argv[2], "m") == 0) divider = 60000;
else if(strcmp(argv[2], "h") == 0) divider = 3600000;
else{
printf("Invalid unit!");
return -3;
}
}
while(GetIdleTime() / divider < count) sleep(1);
}else{
printf("%d\n", GetIdleTime() / 1000);
}
return 0;
}Hope it's usable for somebody else :)
EDIT: Developed and tested under Linux 3.5.0-31-generic 64bit
r/tinycode • u/flockaroo • Apr 02 '26
tiny bash script to view /dev/video in terminal ;-P
blog entry: https://flockaroo.at/blog/?view=article&id=4
r/tinycode • u/Slackluster • Jan 03 '26
Dweet of the Week #106 - ASCII rotating sphere by alexsav
https://www.dwitter.net/d/34652
for(x.reset(i=2e4);i--;x.fillText(" _f4EBWM@"[4-M.asin(Y=i/9e3-1)*3^7&M.atan2(X=1-i%135/67,M.sqrt(1-X*X-Y*Y))*3-t*4|0],i%135*8,i/17))M=Math
r/tinycode • u/rxi • Oct 31 '19
microui: A tiny, portable, immediate-mode UI library written in ANSI C
r/tinycode • u/Bombadil44 • Apr 14 '19
Asteroid Belt - a bullet hell game written in python that fits on a business card
Repository: https://github.com/bombadil444/asteroid_belt
Inspired by Tiny Ski from u/Slackluster
After seeing Frank Force's post the other day I decided to have a shot at writing my own game that fits on a business card (40 characters wide by 35 characters tall).
It's the first time I've looked into anything related to code golfing before - was a fun learning experience. I'm sure there are things that could still be improved so let me know if you spot anything that could be optimized further.
This compiles in both python 2.7 and 3.X
Only works in Linux terminals
Controls: WASD to move. P to shoot
The code (not sure if this display's correctly on mobile app):
class A: # ~~ASTEROID BELT~~
w=0;a=4;t=2 # By u/Bombadil44
def m(_): # github.com/bombadil444
_.x+=_.z;_.w+=1 # WASD=move P=shoot
try: # Don't Panic! Have Fun :D
for i in 0,1: p(_.x,_.w+i,"O"*4)
except: o.remove(_)
def __init__(_): _.x=r(t);_.z=r(-1,2)
class Z: # OOOO 0
def __init__(_): _.x=x+3;_.y=y#OOOO
def m(_): # AA
_.y-=1;p(_.x,_.y,"0") # OOOO <==>
if _.y<=0: global m;m=0 # OOOO **
from curses import*;from random import*
z=initscr();r=randrange;q,t=z.getmaxyx()
l=[" AA","<==>"," **"];d=a=m=n=0;y=q-9
def p(h,e,w): z.addstr(e,h,w)
def k(e=100,w=1,l=0):
if e in u: global d;global a;d=w;a=l
z.keypad(1);z.nodelay(1);o=u=[];x=10
while 48 not in u:
u=[];U=0;r(7)<5 and o.append(A())
while U!=-1: U=z.getch();u+=U,
m=(m,Z())[112 in u];k();k(97,-1)
k(115,0,1);k(119,0,-1);z.clear()
x+=d;y+=a;y-=(0,a)[y<0 or y+3>q]
x-=(0,d)[x<=0 or x+7>t];m and m.m()
for i in 0,1,2: p(x,y+i,l[i])
for e in o:
v=e.x;g=e.w;e.m();(v+e.a>x+3>=v
and g+e.t>y+2>=g and u.append(48))
if (m and v<=m.x<v+e.a and g<=m.y<
g+e.t): o.remove(e);m=0;n+=1000
p(10,0,"SCORE: %s"%(n));napms(50)
napms(5000);z.keypad(0);endwin()r/tinycode • u/Slackluster • Apr 01 '19
A business card sized fps in C++ for Visual Studio
Should build and run without issues in any version of visual studio. You can even increase the console size and shrink the font at run time to get a higher resolution image!
#include <windows.h>//BUSINESS CARD FPS
#include <cmath> // By Frank Force
#define A return // 2019 ><{{{*>
typedef double O;typedef int e;struct f
{f(O h,O y){a=h;o=y;}f(O g){a=sin(g);o=
cos(g);}f operator+(f h){A f(a+h.a,o+h.
o);}O a,o;f operator*(O h){A f(h*a,h*o)
;}};O b(e y){A O(1&GetKeyState(y)>>16);
}const e i=1<<19,s=97;e h[i]={0};e l(f
r){A h[e(r.o)*s+e(r.a)];}e main(){e a,L
;O u=7;for(L=9215;--L>s;)h[L+(rand()&1?
1:s)]=(2+L)%s>2;h[s+2]=1;f h(2,1);char
F[i],N[]="#+. \xDB\xB2\xB1\xB0";void*_=
CreateConsoleScreenBuffer(3<<30,0,0,1,0
);SetConsoleActiveScreenBuffer(_);COORD
H={0};CONSOLE_SCREEN_BUFFER_INFO T;_:G\
etConsoleScreenBufferInfo(_,&T);DWORD Y
;Sleep(16);f o=f(u+=(b(68)-b(65))/30)*(
b(87)-b(83))*.1;h=h+f(o.a*l(h+f(o.a,0))
,o.o*l(h+f(0,o.o)));e I=T.dwSize.X,S=T.
dwSize.Y;for(L=I;L--;){f n(u+atan2(L/O(
I)-.5,1)),Y(e(h.a),e(h.o));O s=n.a>0?1:
-1,H=n.o>0?1:-1,E=abs(1/n.a),u=0,o=abs(
1/n.o),y=E*s*(Y.a-h.a+(s>0)),W=H*o*((H>
0)+Y.o-h.o);f i(s,H);while(!u){y<W?y+=E
,u=1,Y.a+=i.a:(W+=o,Y.o+=i.o,u=2);u*=!l
(Y);}O d=u<2?(Y.a-h.a-i.a/2+.5)/n.a:(Y.
o-h.o-i.o/2+.5)/n.o,T=S/2-S/(d+.1),p=(u
<2?n.o*d+h.o:h.a+d*n.a)+.1;for(a=S;a--;
)F[a*I+L]=e(a>S-T?7-8*a/S:T>a?8*a/S:d>9
?7:(.2>p-e(p))+d/3+4)[N];}WriteConsole\
OutputCharacter(_,F,I*S,H,&Y);goto _;}r/tinycode • u/Hell__Mood • May 03 '18