[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Post worthless scripts you've made

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 15
Thread images: 1

File: hacker-stock-photo-9.jpg (30KB, 400x357px) Image search: [Google]
hacker-stock-photo-9.jpg
30KB, 400x357px
Here's a script to convert image so they can be displayed as 1x1 colored elements in html

from PIL import Image

im = Image.open("image.jpg")

x = im.size[0]
y = im.size[1]
listo = []
w = 0
h = 0

pix = im.load()

for j in range(y):
for i in range(x):
listo.append( '#%02x%02x%02x' % (pix[i,j]))

width = int(input('Please enter width: ')) - 2
q = open('output.html', 'w')

for i in listo:
if w > width:
w = 0
h += 1
elif 'ffffff' in i:
w += 1
else:
q.write('<div style="position: absolute; left: {0}px; top: {1}px; width: 1px; height: 1px; background-color: {2};"></div>'.format(str(w), str(h), i))
w += 1

q.close()


And remember, 4chan is not thea place for bullying.
>>
why not post this as a gist or something? there are things that you could update to make this script less susceptible to breaking.

also
>listo as variable name
ugh
>>
> 1x1 colored elements in html
Were you the OP in that thread from awhile ago asking about that, or are you somebody who decided to make it for them?
>>
>>57481606
Both
>>
made a crappy little wrapper for apt, since i was tired of doing update, upgrade, clean, etc.
>>
>>57481752
>what are aliases
>>
>>57481764
it's a little function in a script that i added to my bin folder.

so just barely above an alias.
>>
import time
print("""long cat is\n /\___/\\1 \n / \\2 \n | # # |3\n \ @ |4\n \ _|_ /5\n / \______6\n / _______ ___ \\7\n |_____ \ \__/8\n | \__/9\n | |10""")
count = 10
time.sleep(2.0)
while True:
count = count +1
if count > 8995:
break
print(" | |"+str(count))
print(" | |8996\n / \ 8997\n / ____ \ 8998\n | / \ |8999\n | | | |9000\n / | | \ 9001\n \__/ \__/)"+"Long!")

>>
You have to have the requests module and openmpt123 (or any other MOD player) installed. Then, pure bliss.

import requests
import subprocess

def save_module(): #Gets a module and saves it to audio_out
page_file = requests.get("http://lite.modarchive.org/index.php?request=view_by_random")
page = page_file.text
i = page.index("eid=") #We want to know the XXXXXXX and "eid=" is the closest unique string
mod = requests.get("http://api.modarchive.org/downloads.php?moduleid="+(page[i+4:page.index("#", i)]), stream=True)
with open("audio_out", "wb") as file:
for chunk in mod.iter_content():
file.write( chunk )

while(1):
save_module()
player = subprocess.call("openmpt123 audio_out",shell=False)
>>
>>57481834
funny but ugly code
>>
>>57481834
Get cancer and die
>>
>>57481501
script to automatically scrape videos from my subscribed youtube channels and save them to my disk for later viewing

#!/bin/env ruby

require 'json'
require 'uri'
require 'shellwords'

rate = "10M"
template = '/z/youtube/%(uploader)s/%(title)s-%(id)s.%(ext)s'

queue = JSON.parse(`notmuch show --format=json tag:rssqueue`)

queue.each do |thread|
msg = thread[0][0]
body = msg['body']
url = URI.extract(body[0]['content'])[1]


system "youtube-dl -r #{rate} -o #{Shellwords.escape template} #{Shellwords.escape url}"
system "notmuch tag -rssqueue +rss -- id:#{Shellwords.escape msg['id']}"
end
>>
#!/usr/bin/env perl
# tmpx - extract archive to temp dir
use strict;
use warnings;
use autodie;
use File::Temp qw(tempdir);
use File::Path qw(remove_tree);

my $filename = $ARGV[0];
die "Usage: $0 <archive>\n" unless $filename and -e $filename;

open my $fp, "<:bytes", $filename;
read $fp, my $magic, 4;
close $fp;
$magic = unpack 'H8', $magic;

my $dir = tempdir() or die "Unable to create temporary directory\n";

my %signatures = (
"504b0304" => "unzip \'$filename\' -d $dir",
"52617221" => "unrar x \'$filename\' $dir",
"377abcaf" => "7z x \'$filename\' -o$dir", # untested
);

eval {
my $command = $signatures{$magic} or die "Unknown archive signature $magic\n";
system("$command > /dev/null"); die "Error $? running $command\n" if $?;
}; remove_tree($dir) and die $@ if $@;
print "$dir\n";

I use it to read manga, together with this shell script and my image viewer (meh):
#!/bin/sh
tmpfolder=$(tmpx "$1")
if [ ! $? -eq 0 ]; then
echo "error running tmpx on $1"
exit 1
fi
find "$tmpfolder" -type f | sort -g | meh -list
rm -rf "$tmpfolder"
>>
>>57481501
ran that on jpg

got

dan@cat:~/m$ ls *.jpg
mu.jpg
dan@cat:~/m$ ts
Traceback (most recent call last):
File "/home/dan/m/ts", line 16, in <module>
listo.append( '#%02x%02x%02x' % (pix[i,j]))
TypeError: not enough arguments for format string
user@cat:~/m$ ts
Traceback (most recent call last):
File "/home/user/m/ts", line 16, in <module>
listo.append( '#%02x%02x%02x' % (pix[i,j]))
TypeError: not enough arguments for format string
user@cat:~/m$

why
>>
>>57483397
c:
Thread posts: 15
Thread images: 1


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.