Skip to content

Instantly share code, notes, and snippets.

View zwetan's full-sized avatar
🌀
getting shit done

Zwetan Kjukov zwetan

🌀
getting shit done
View GitHub Profile
@zwetan
zwetan / test_mkdirp.as
Created April 22, 2015 11:29
Create a new directory and intermediate directories as required
#!/usr/bin/as3shebang --
/* Note:
mkdir() creates directoy
but can not creates directory tree
the command line "$ mkdir -p" allows that
so here a small util function to emulate that
behaviour
*/
@zwetan
zwetan / colored.as
Last active August 29, 2015 14:19
ANSI colors in your AS3 scripts ;)
#!/usr/bin/as3shebang --
// see http://en.wikipedia.org/wiki/ANSI_escape_code
package ansi
{
import flash.utils.describeType;
import shell.Program;
public class controls
{
#!/usr/bin/as3shebang --
/* Note:
Again the joy of using POSIX from AS3 :p
see:
Copy a file in an sane, safe and efficient way
http://stackoverflow.com/questions/10195343/copy-a-file-in-an-sane-safe-and-efficient-way
BUFSIZ
@zwetan
zwetan / index3.as3
Created November 2, 2014 23:41
debugging CGI
try
{
import C.stdio.*;
import flash.utils.ByteArray;
function write( message:String = "" ):void
{
var bytes:ByteArray = new ByteArray();
bytes.writeUTFBytes( message );
@zwetan
zwetan / display.as
Created October 31, 2014 20:13
CGI example 3
import C.stdio.*;
import flash.utils.ByteArray;
import shell.FileSystem;
import shell.Program;
/* NOTE:
trace() add a carriage return
better use Program.write() to
control exactly the char return at end of line
*/
@zwetan
zwetan / index.as
Last active August 29, 2015 14:08
CGI example 2
/* build:
import redbean.*;
import shell.FileSystem;
compile( "src/index.as" );
if( FileSystem.exists( "index.abc" ) )
{
@zwetan
zwetan / index.as
Created October 31, 2014 19:00
CGI example 1
/* build:
import redbean.*;
import shell.FileSystem;
compile( "src/index.as" );
if( FileSystem.exists( "index.abc" ) )
{
@zwetan
zwetan / getaddrinfo usage2
Created October 14, 2014 15:58
obtain all the IP addresses of the localhost
import C.errno.*;
import C.arpa.inet.*;
import C.netdb.*;
import C.sys.socket.*;
import C.stdlib.*;
import C.unistd.*;
var hostname:String = gethostname();
trace( "hostname = " + hostname );
@zwetan
zwetan / getaddrinfo usage
Last active August 29, 2015 14:07
obtain all the IP addresses of a hostname
import C.errno.*;
import C.arpa.inet.*;
import C.netdb.*;
import C.sys.socket.*;
import C.stdlib.*;
import C.unistd.*;
var hostname:String = "www.google.com";
trace( "hostname = " + hostname );
@zwetan
zwetan / test_getsockopt.c
Last active August 29, 2015 14:07
strangely getsockopt() return 4 instead of 1 for some options
//...
struct addrinfo hints, *res;
int sockfd;
memset(&hints, 0, sizeof hints);
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_PASSIVE;
int result = getaddrinfo(NULL, "3490", &hints, &res);