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!
Any QUALITY is allowed. No bullying!
/**
* 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);
}
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
def setcolor(label, color):
if label and color:
fgcolors[label] = color
#!/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;
}
}
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');
#!/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;
}
sudo time cat /dev/sdb9 | grep -Uboa -P `xxd -l14 -p 1.dat |sed 's/../\0\\x/g'` | tee search
#!/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;
}
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)
#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;
}
$ 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
def add5(x)
return x + 5;
y f = f $ y f
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++;
}
twojar = @(x, y, z) x(z(y));
ycell = @(a, b, x, y, z) z(x(a) !xor! y(b))
int
main (int argc, char *argv[])
{
return EXIT_SUCCESS;
}
#include <stdlib.h>
int
main(
int argc,
char **argv
)
{
return(EXIT_SUCCESS);
}