SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#51 2012-01-07 23:32:58

rhowaldt
#!*$%:)
Registered: 2011-03-09
Posts: 4,396

Re: shell script bits & pieces thread

@johnraff: yes, i figured out those redundant 'CEILING's in the meantime, but thanks anyway smile
as to what it is for:

i am building a script which might seem quite stupid and useless to most. however, i'll explain anyway (and explain my use of it after that). it is best explained by showing you just the input and the (current) output:

[23:44:41]$ word_disrupt disruption
d i s r u p t i o n
2 1 2 1 1 1 1 1 3 3
d d i s s r u p t i o o o n n n
, . - . _ , : , : - - .. .. _

ok, what happens here?
1. the input-word gets spliced into an array of separate letters. in this case, 10 letters.
2. another array (containing the first 4 values of the Fibonnaci-sequence, ie. 1 1 2 3) is read out multiple times, creating an array of 10 numbers (in this case, 1 1 2 3 1 1 2 3 1 1). this array is then randomized to provide the output you see echo'd above. what i'm doing here is assigning a number to each individual letter (not through associative arrays, just two separate ones)
3. the number coupled with each letter determines the amount of times it will be repeated. you can see the result of that action on the 3rd line of output. this new word is 16 letters long.
4. i also have an array filled with some characters (- , . _ : ..). now i use the code i posted above to iterate over this array back and forth, until i have extracted the amount of characters corresponding to the amount of letters (in this case, 16 characters).
5. (this step still needs to be built in, as you can see from the output) - the script will grab a (partially) random amount of characters from that string and distribute them in some way over the word. this will result in something like this (incorrect example): d-diisrupt.tion..

you're probably now going 'wtf? WHY?'.
well, first of all, i like it - disrupted words and stuff. second of all, i like it so much that i once wrote poetry and stuff incorporating these kinds of disrupted words. eventually (probably gonna be a while!) i'd like to incorporate all this into a poetry-writing-script. my detect_syllables-project is another (much much bigger) part of that.

so, i hope that is all clear. to summarize: there is weird stuff going on in my head and i enjoy it and also enjoy scripting so i want to script it in some way. i don't know. being creative here smile

Offline

Help fund CrunchBang, donate to the project!

#52 2012-01-08 04:04:19

aiBo
#! CrunchBanger
Registered: 2010-11-08
Posts: 243

Re: shell script bits & pieces thread

Offline

#53 2012-01-09 15:06:09

johnraff
nullglob
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 4,148
Website

Re: shell script bits & pieces thread

john@raffles3:~$ text='CrunchBang Linux could possibly make your computer go CRUNCH! BANG!'
john@raffles3:~$ translate "$(translate "$text" ja)"
CrunchBang Linux could make your computer go crunch perhaps

Offline

#54 2012-01-09 15:31:47

rhowaldt
#!*$%:)
Registered: 2011-03-09
Posts: 4,396

Re: shell script bits & pieces thread

^ heh, that looks pretty cool. i might think of using something like that. i still have no clear idea of how all different parts might come together in the end, so any input is always appreciated.

Offline

#55 2012-02-10 18:01:46

johnraff
nullglob
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 4,148
Website

Re: shell script bits & pieces thread

process | sed 's/string/replacement' | sed 's/otherthing/changetothis/' | ...

Last edited by johnraff (2012-08-06 16:47:24)

Offline

#56 2012-08-06 17:06:55

johnraff
nullglob
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 4,148
Website

Re: shell script bits & pieces thread

somecommand | tee -a logfile 2>&1

Offline

#57 2013-02-01 03:53:47

johnraff
nullglob
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 4,148
Website

Re: shell script bits & pieces thread

[[ -d /path/to/folder ]] || return_error

Offline

#58 2013-02-02 08:33:15

r0n d0n
New Member
From: 'mericuh
Registered: 2012-11-19
Posts: 8

Re: shell script bits & pieces thread

I've put together this from several sources a while back (can't remember where), and I really only understood it enough to make it work. I've put this in my .bashrc to make it permanent, but you can enter this in the terminal to test it out before you commit.

I may be forgetting some things,  but this will display "user@host : )" in green on the terminal prompt when a command exits with no errors, and the smiley will turn into a ": ( " and become red when the command exits with errors. Also, the current directory is up on the title bar.

export PS1="\[\e]2;\u@\H \W\a\e[32;1m\]\[\e[01;32m\]\u@\h \[\e[01;34m\] \`if [ \$? = 0 ]; then echo -e '\e[01;32m:)'; else echo -e '\e[01;31m:('; fi\` \[\e[01;34m\]$\[\e[00m\]\[\e[0m\] "

>lurk moar

Offline

#59 2013-02-03 15:51:56

pvsage
Internal Affairs
From: North Carolina
Registered: 2009-10-18
Posts: 13,970

Re: shell script bits & pieces thread

Problem:  avconv/ffmpeg puts invalid XING headers on converted mp3 files, both CBR and VBR, resulting in an mp3 that isn't properly searchable on some portable mp3 players and reports incorrect song length in some media player software.

Workaround:  Have avconv/ffmpeg write to temporary file, process through vbrfix, delete temporary file.  (EDIT:  You can specify the same filename for both input and output; vbrfix writes to a temporary file.  This negates the need to remove your initial temporary file.  Also, if you use the -always switch with vbrfix, it will fix CBR mp3s as well.)

Example:

#!/bin/bash
for i in *.mp3
do
  avconv -i "$i" -acodec libmp3lame -aq 0 "${i%.flv}-temp.mp3"
  vbrfix -always "${i%.flv}.mp3" "${i%.flv}.mp3"
done

This is a known bug in avconv/ffmpeg that keeps cropping up; hopefully the developers will nail this down eventually. roll

Last edited by pvsage (2013-02-03 16:24:52)

Offline

#60 2013-06-03 17:58:56

Doomicide
#! Junkie
From: the Nightosphere
Registered: 2011-06-24
Posts: 472
Website

Re: shell script bits & pieces thread

@johnraff: Hint taken, I'll just use this post for some stuff from my mkshrc:

function repeat() {
        for i in {1..${1}}; do
                "${2}"
        done
}


function calc() {
 
        awk "BEGIN{ print $* }"
}

function sprunge() {
        for arg in ${@}; do
                cat $arg | curl -F 'sprunge=<-' http://sprunge.us
        done
}

function trans() {
        lynx -nonumbers -nolist -nolog -dump "http://odict.leo.org/ende?search=$1" \
        | sed -n "/Direct matches/,/[NoaA]*dditional matches$/ { s/\[_\]\s*//; p}" \
        | sed '1d;$d'
}

Last edited by Doomicide (2013-06-04 09:47:51)

Offline

#61 2013-06-04 04:01:57

johnraff
nullglob
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 4,148
Website

Re: shell script bits & pieces thread

Thanks Doomicide! A full-blown, and useful, script like this might deserve its own thread in fact, so people can comment or make suggestions...

To be honest, I really envisaged this thread for handy scraps of code that don't really merit their own thread. That said, all contributions are welcome! smile

Offline

#62 2013-11-15 03:37:50

cloverskull
#! Junkie
Registered: 2013-10-26
Posts: 377

Re: shell script bits & pieces thread

Old thread, sorry, just found it smile  In my bashrc, I put the following:

eval `dircolors`

That way, when I ssh from another box, the colors are actually readable on a black background.

Offline

#63 2015-12-10 05:16:44

johnraff
nullglob
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 4,148
Website

Re: shell script bits & pieces thread

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.
Server: bleh

Debian Logo