Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Every time you visit for the FIRST TIME today... [Part 1]

Name: Anonymous 2013-10-20 22:56

Post a random function that you made. May be from any project you've done or make one impromptu.

Any QUALITY is allowed. No bullying!

Name: Anonymous 2013-10-29 22:46

/**
* Initialize the contents of the frame.
*/
private void initialize() {
editWindow = new JFrame();
editWindow.setTitle("Edit Item");
editWindow.setBounds(100, 100, 313, 250);
editWindow.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
editWindow.getContentPane().setLayout(null);

nameField = new JTextField();
nameField.setHorizontalAlignment(SwingConstants.RIGHT);
nameField.setColumns(10);
nameField.setBounds(92, 57, 158, 20);
editWindow.getContentPane().add(nameField);

priceField = new JTextField();
priceField.setHorizontalAlignment(SwingConstants.RIGHT);
priceField.setColumns(10);
priceField.setBounds(92, 88, 158, 20);
editWindow.getContentPane().add(priceField);

quantityField = new JTextField();
quantityField.setHorizontalAlignment(SwingConstants.RIGHT);
quantityField.setColumns(10);
quantityField.setBounds(92, 120, 158, 20);
editWindow.getContentPane().add(quantityField);

JLabel label = new JLabel("Name");
label.setHorizontalAlignment(SwingConstants.RIGHT);
label.setBounds(36, 60, 46, 14);
editWindow.getContentPane().add(label);

JLabel label_1 = new JLabel("Price");
label_1.setHorizontalAlignment(SwingConstants.RIGHT);
label_1.setBounds(36, 91, 46, 14);
editWindow.getContentPane().add(label_1);

JLabel label_2 = new JLabel("Quantity");
label_2.setHorizontalAlignment(SwingConstants.RIGHT);
label_2.setBounds(36, 123, 46, 14);
editWindow.getContentPane().add(label_2);

JButton button = new JButton("Change");
button.setBounds(102, 162, 89, 23);
editWindow.getContentPane().add(button);
}

Name: Anonymous 2013-10-29 22:53

unsigned int yoba(unsigned int x) { return ((unsigned long long)(x)*0x4325c53f)>>36;}

Name: Anonymous 2013-10-30 12:04

phi :: FStructure -> Maybe Constituent
phi fs
| Just (CAT Sent XP) <- fs # Category = do
ARG (subjKey : _) <- fs # Arguments
subj <- phiOn fs subjKey
rest <- phi $ fs `with` [(Category, CAT Verb XP)]
return $ Phrase fs [subj, rest]

| Just (CAT Verb XP) <- fs # Category = do
ARG argList <- fs # Arguments
let objs = drop 1 argList -- Ignore subject
verb <- phi $ fs `with` [(Category, CAT Verb X)]
args <- mapM (phiOn fs) objs
return $ Phrase fs (verb : args)

| Just (LEX w) <- fs # Lexeme = Just (Head fs w)

phi _ = Nothing

Name: Anonymous 2013-10-31 18:43

def setcolor(label, color):
if label and color:
fgcolors[label] = color

Name: Anonymous 2013-11-18 7:36

I stuck this in a cronjob repeated a few times, and it downloads a random Touhou doujin CD from the TLMC to the pwd (which is set in the cronjob to be my mp3 player's SD card, if I have it plugged in overnight) so that I have some new random albums to listen to the next day at work. It's probably one of the worst pieces of code I've ever written, because I don't actually know Perl, so I just cobbled it together from help pages on CPAN.

#!/usr/bin/perl -w

use strict;
use warnings;
use Encode qw(decode_utf8);
use File::Temp qw(tempdir tempfile);
use File::Path qw(make_path);
use HTML::Parser;
use LWP::Simple qw(getstore);
use LWP::UserAgent;
use URI::Escape qw(uri_unescape);

my $ua = LWP::UserAgent->new;
$ua->agent("Some kind of randomized wget machine/0.2.1");
my $pl_parser = HTML::Parser->new( api_version => 3,
start_h => [\&pl_start, "tagname, attr"],
end_h => [\&pl_end, "tagname"],
marked_sections => 1,
);
my $req = HTTP::Request->new(GET => 'http://otokei-douj.in/');
my $pl_in_playlist = 0;
my @playlist = ();

my $res = $ua->request($req);
if ($res->is_success) {
$pl_parser->parse(decode_utf8($res->content));
} else {
die ($res->status_line . "\n");
}

if ($#playlist < 0) {
die ("Couldn't get any elements - has the site changed layout?");
}

my $subpage = "http://otokei-douj.in/" . $playlist[rand @playlist];
$req = HTTP::Request->new(GET => $subpage);
@playlist = ();
$res = $ua->request($req);
if ($res->is_success) {
$pl_parser->parse(decode_utf8($res->content));
} else {
die ($res->status_line . "\n");
}

if ($#playlist < 0) {
die ("Couldn't get any elements - has the site changed layout?");
}

my $dlpage = "http://otokei-douj.in/download.php" . $playlist[rand @playlist];
my $dir = tempdir( CLEANUP => 1 );
my ($fh, $filename) = tempfile( DIR => $dir, SUFFIX => '.7z' );
my @title_parts = ($dlpage =~ /link=%2F(.*)&album=(.*)/);
system("wget -q \"$dlpage\" -O \"$filename\"");

# One side effect of not pulling the link exactly is that '+' is
# present where '%20' would be if a second page were followed. Actual
# '+' characters are still represented as %2B, so this will not harm
# actual filenames
$title_parts[0] =~ s/\+/%20/g;
$title_parts[0] = decode_utf8(uri_unescape($title_parts[0]));
make_path($title_parts[0]);
system("7z x \"-o$title_parts[0]\" \"$filename\"");

# ----------------------------------------------------------------------
# Parsing functions:
sub pl_start {
my ($tagname, $attr) = @_;
if ($tagname eq "ul" && $attr->{'class'} eq "playlist") {
$pl_in_playlist = 1;
} elsif ($tagname eq "a" && $pl_in_playlist == 1) {
push (@playlist, $attr->{'href'});
}
}

sub pl_end {
my ($tagname) = @_;
if ($tagname eq "ul") {
$pl_in_playlist = 0;
}
}

Name: Anonymous 2013-11-18 15:12

>>85
Touhou vocals are shit.

Name: Anonymous 2013-11-18 16:28

>>82
I can't tell what the heckie this is supposed to do!

Name: Anonymous 2013-11-19 0:44

>>85
use HTML::TreeBuilder::XPath;

my $tree = HTML::TreeBuilder::XPath->new;
my $host = 'http://otokei-douj.in';

my $res = $ua->request(HTTP::Request->new(GET => "$host/"));
die "$res->status_line" unless $res->is_success;

$tree->parse(decode_utf8($res->content));
my @playlist = $tree->findnodes('//ul[@class="playlist"]/li/a');
my $album_url = $playlist[rand @playlist]->attr('href');

Insert error handling as desired, also you might want to make this a sub since you call it a couple of times (once for the main page, once for the artist(?) page)

Name: Anonymous 2013-11-19 4:55

>>85
N-n-nice find.
How do you guys even find these? That server is is so fast, and that page is so fucking parsable. Isn't it all a php|perl a script? I want to embed HTSQL so badly to it. If someone donates me 200, I'll download everything, and make a schema.

But I agree with >>86, vocals are shit, no matter the song.

Do they even have fakumen's work?:
https://www.youtube.com/watch?v=t0PcB9RzBnU&list=PL8F1671253111E1D6
https://www.youtube.com/watch?v=SQQy8W-gUb4&list=RDSQQy8W-gUb4

Facepalm:
http://fuuka.otokei-douj.in
Whomever is admin, is boss.

Name: Anonymous 2013-11-19 5:05

>>89
s/fakumen/fukumen|フクメン/ (mask)/
and no.

Name: Anonymous 2013-11-19 5:07

>>85-89
check thii2 2hiit out

#!/usr/bin/env perl

use v5.10;
use warnings;

use Mojo::UserAgent;
use File::Path qw(make_path);
use File::Temp qw(tempfile);

my $ua = Mojo::UserAgent->new;
$ua->transactor->name('Touhoulicious v2.h.u');

my $host = 'http://otokei-douj.in';
my $artist_url = choose("$host/")->attr('href');
my $album = choose("$host/$artist_url");
my $album_name = $album->text;
my $album_url = $album->attr('href');
make_path($album_name);

sub choose {
my $sel = 'ul.playlist > li > a';
return $ua->get(shift)->res->dom($sel)->shuffle->first;
}


I'm having trouble actually downloading the file though

Name: Anonymous 2013-11-19 13:44

>>88, 91
Thanks - I was kind of hoping somebody who knows shit might actually step in and put my shit out of its misery.

Name: Anonymous 2013-11-19 20:57

just some stupid shell scripting today
sudo time cat /dev/sdb9 | grep -Uboa -P `xxd -l14 -p 1.dat |sed 's/../\0\\x/g'` | tee search

Name: Anonymous 2013-11-19 20:59

>>93
forgot to mention that bgrep is lame piece of shitware, beware

Name: Anonymous 2013-11-19 22:26

>>92
No big deal. Here, I even commented some of it:

#!/usr/bin/env perl

use v5.10;
use warnings;

use Mojo::UserAgent;
use File::Path qw(make_path);
use File::Temp qw(tempdir tempfile);

binmode STDOUT, ":encoding(UTF-8)";

# Allow 1GB file downloads. Most of the albums should be smaller than this.
# Increase it if you think you'll find bigger ones.
$ENV{MOJO_MAX_MESSAGE_SIZE} = 1024 * 1024 * 1024;

my $ua = Mojo::UserAgent->new;
$ua->transactor->name('Touhoulicious v2.h.u');

my $host = 'http://otokei-douj.in';

my (undef, $tmpname) = tempfile(SUFFIX => '.7z', OPEN => 0);

# If you need to run this script multiple times each night, you might as well
# make the loop as small as possible and not schedule the cron job repeatedly.
my $num_runs = 1;
for (1 .. $num_runs) {
my $artist_url = choose("$host/")->attr('href');
my $album = choose("$host/$artist_url");
my $album_name = $album->text;
my $album_url = "$host/download.php" . $album->attr('href');

# Mojolicious already creates a temp file when saving downloads, but I
# haven't figured out how to repurpose it instead of making our own.
say "Downloading...";
$ua->get($album_url)->res->content->asset->move_to($tmpname);
say "Got $album_name";

make_path($album_name);

# Try using File::Unpack for this.
# (I wasn't able to build it but you might have better luck.)
`7z x -o"$album_name" "$tmpname"`;
die "Couldn't extract: $!" if $?;
}

unlink $tmpname;

sub choose {
my $sel = 'ul.playlist > li > a';
return $ua->get(shift)->res->dom($sel)->shuffle->first;
}

Name: Anonymous 2013-11-20 15:45

>>93
Why do you have nine partitions on /dev/sdb?

Name: Anonymous 2013-11-22 9:53

>>96
not nine but stil a lot
system, old/new home, swap, videos, random garbage and there is still some unallocated space.
that hdd is just a dumpster now.

Name: Anonymous 2013-11-23 14:20

>>97
your lack of an organized storage scheme pisses me off

Name: Anonymous 2013-11-23 18:04

def fixedXORbin(bin1, bin2):
assert len(bin1) == len(bin2)
final = bytearray()
for i in range(len(bin1)):
final.append(bin1[i] ^ bin2[i])
return bytes(final)

Name: Anonymous 2013-11-23 21:17

>>98
my time management skills will probably make your head explode then.

Name: Anonymous 2013-11-25 5:57

A lain spammer.


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <poll.h>

#include <signal.h>

#define BUFFER_LENGTH 1024
#define LAIN_LENGTH 5
char* lain = "LAIN\n";

char* program_name;

void signal_handler(int number) {
printf("%s: signal handler saw signal %d\n", program_name, number);
}

int write_buffer(int fd, const void* buf, size_t count) {
unsigned char* cbuf = (unsigned char*)buf;
unsigned int offset = 0;
int rc;

for(;;) {
size_t remaining_count = count - offset;
rc = write(fd, cbuf + offset, remaining_count);
if(rc < 0){
return rc;
}
else if(rc != remaining_count) {
offset += rc;
}
else {
return count;
}
}
}

#define SIGNALLED_TO_STOP_READING 1
int read_stream_buffer(
int fd, void* buf, size_t count,
int (*reader)(void*, size_t, void*), void* userdata) {
int rc;
int reader_rc;

for(;;) {
rc = read(fd, buf, count);
if(rc <= 0) {
return rc;
}
else {
reader_rc = reader(buf, rc, userdata);
if(!reader_rc) {
return SIGNALLED_TO_STOP_READING;
}
}
}
}

int read_stream_buffer_impatiently(
int fd, void* buf, size_t count,
int (*reader)(void*, size_t, void*), void* userdata,
int timeout) {
int rc;
int reader_rc;
struct pollfd poll_fd;
poll_fd.fd = fd;
poll_fd.events = POLLIN;

for(;;) {
rc = poll(&poll_fd, 1, timeout);
if(rc <= 0) {
// rc == 0 implies timeout exceeded.
// rc < 0 implies an error occured.
return rc;
}

rc = read(fd, buf, count);
if(rc <= 0) {
// if rc == 0, there is nothing more to read
// if rc < 0, an error occured.
return rc;
}

// rc is bytes read.
reader_rc = reader(buf, rc, userdata);
if(!reader_rc) {
return SIGNALLED_TO_STOP_READING;
}
}
}

int echo_reader(void* buf, size_t size, void* userdata) {
printf("Read %u bytes: ", size);
fwrite(buf, size, sizeof(char), stdout);
printf("\n");
}

int main(int argc, char** argv) {
int rc;

program_name = argv[0];

char recv_buff[BUFFER_LENGTH];

signal(SIGPIPE, signal_handler);

if(argc != 3) {
fprintf(stderr, "%s: server-hostname server-port\n", program_name);
exit(1);
}

char* server_host = argv[1];
int server_port = atoi(argv[2]);

int socket_fd = socket(AF_INET, SOCK_STREAM, 0);
if(socket_fd < 0) {
fprintf(stderr, "%s: could not open socket: %d\n", program_name, socket_fd);
exit(2);
}

struct hostent* server_host_entry = gethostbyname(server_host);
if(server_host_entry == NULL) {
fprintf(stderr, "%s: host: %s not found.\n", program_name, server_host);
exit(3);
}

struct sockaddr_in server_address;

bzero(&server_address, sizeof(struct sockaddr_in));

server_address.sin_family = AF_INET;
bcopy((char*) server_host_entry->h_addr,
(char*) &(server_address.sin_addr.s_addr),
server_host_entry->h_length);
server_address.sin_port = htons(server_port);

rc = connect(socket_fd, (struct sockaddr*) &server_address, sizeof(struct sockaddr_in));
if(rc < 0) {
fprintf(stderr, "%s: could not connect: %d\n", program_name, rc);
exit(4);
}

for(;;) {
rc = write_buffer(socket_fd, lain, LAIN_LENGTH);
if(rc < 0) {
printf("%s: lain write failed: %d\n", program_name, rc);
fflush(NULL);
break;
}
rc = read_stream_buffer_impatiently(
socket_fd, recv_buff, BUFFER_LENGTH,
echo_reader, NULL,
1000);
if(rc < 0) {
printf("%s: read failed: %d", program_name, rc);
fflush(NULL);
break;
}
}

close(socket_fd);
return 0;
}

Name: Anonymous 2013-11-25 6:03

This is kind of fun.


$ torsocks client www.google.com 80
Read 498 bytes: HTTP/1.0 400 Bad Request
Content-Type: text/html; charset=UTF-8
Content-Length: 925
Date: Mon, 25 Nov 2013 06:58:56 GMT
Server: GFE/2.0

<!DOCTYPE html>
<html lang=en>
<meta charset=utf-8>
<meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
<title>Error 400 (Bad Request)!!1</title>
<style>
*{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:
Read 570 bytes: 180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}
</style>
<a href=//www.google.com/><img src=//www.google.com/images/errors/logo_sm.gif alt=Google></a>
<p><b>400.</b> <ins>That’s an error.</ins>
<p>Your client has issued a malformed or illegal request. <ins>That’s all we know.</ins>

client: signal handler saw signal 13
client: lain write failed: -1
$ torsocks client www.yahoo.com 80
Read 217 bytes: <HEAD><TITLE>Invalid HTTP Request</TITLE></HEAD>
<BODY BGCOLOR="white" FGCOLOR="black">
<FONT FACE="Helvetica,Arial"><B>
Bad request syntax</B></FONT>

<!-- default "Invalid HTTP Request" response (400) -->
</BODY>

client: signal handler saw signal 13
client: lain write failed: -1

Name: Anonymous 2013-11-26 12:28


def add5(x)
return x + 5;

Name: Anonymous 2013-11-26 23:17

y f = f $ y f

Name: Anonymous 2013-11-29 22:18

Splits a string into a double array

void split_data(double *data, char *s, int fields) {
char buff[DATA_MAX];
int j = 0, i;

while(*s) {
while((*s == ' ' || *s == '\t') && *s)
*s++;

i = 0;
while(!(*s == ' ' || *s == '\t') && *s)
buff[i++] = *s++;
buff[i] = 0;

data[j++] = atof(buff);

if(j == fields)
return;
*s++;
}

Name: Anonymous 2013-11-30 6:22

how do i post labview code?

Name: Anonymous 2013-11-30 10:18

twojar = @(x, y, z) x(z(y));

Name: Anonymous 2013-11-30 10:23

ycell = @(a, b, x, y, z) z(x(a) !xor! y(b))

crypto primitives ^^

Name: Anonymous 2013-11-30 13:44

Oh look, Luke got tired of the old prague again and he came back.

Name: Anonymous 2013-12-01 10:48

for some reason i just thought of that shnappi song

Name: Anonymous 2013-12-04 21:32

>>109
Hey! I'm his father.

Name: VIPPER 2013-12-07 14:27

int
main (int argc, char *argv[])
{
return EXIT_SUCCESS;
}

Name: Anonymous 2013-12-07 14:36

>>112
EXPERT ANONIX IMPLEMEN-TATER

Name: Anonymous 2013-12-08 4:15

>>112

int
main(..

What the fuck

Name: Anonymous 2013-12-08 5:14

>>114
Have you never seen C before in your life?

Name: Anonymous 2013-12-08 20:48

>>115
Is that first edition C?

Name: Anonymous 2013-12-08 21:16

>>116
Are you guys serious? It's any edition C. White space is ignored, in fact


#include <stdlib.h>

int
main(
int argc,
char **argv
)

{
return(EXIT_SUCCESS);
}



is perfectly legal. Some people even separate arguments like that if they're very long and easier to organize that way.

Name: Anonymous 2013-12-08 21:22

>>117
I'm not talking legal, I'm talking standard.

Name: Anonymous 2013-12-08 21:54

>>118
The standards don't specify a style.

Name: VIPPER 2013-12-11 19:49

>>112
NICE VIP quality GNU-style C!

>>114,116,118
You are a [i]nigger[i].

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List