Skip to content

Instantly share code, notes, and snippets.

@tylor
Created July 9, 2012 23:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tylor/3079697 to your computer and use it in GitHub Desktop.
Save tylor/3079697 to your computer and use it in GitHub Desktop.
Simply code to rate limit your stdout.
/*
* Simply code to rate limit your stdout.
*
* Compile:
* - $ gcc limit.c
* Fun uses:
* - $ find ~/Sites/thisisourstop/ -name "*.js" -exec cat {} \; | ./a.out 1000
* - $ ./a.out < /dev/random
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char**argv){
int c;
useconds_t stime=10000; // defaults to 100 Hz
if (argc>1) { // Argument is interperted as Hz
stime=1000000/atoi(argv[1]);
}
setvbuf(stdout,NULL,_IONBF,0);
while ((c=fgetc(stdin)) != EOF){
fputc(c,stdout);
usleep(stime);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment