You are not logged in.
any sed/regex gurus out there? i made a little script to pull the word of the day from dictionary.com's rss feed:
#!/bin/sh
URL=http://feeds.reference.com/DictionarycomWordOfTheDay
w3m -dump $URL | grep 'description.[[:alpha:]]*:' | sed 's/.*description.\(.*\)<.*/\1/'
which works fine (todays word: torpor: lethargic indifference; apathy. fyi). but i know only slightly more about using sed and regular expressions than, say.. a chimp. so i can't help but think that i could do something more simple/elegant to pull the relevant sentence from the rss feed. my thought process was: i) grep for the relevant line; ii) do some sed magic to get just the right sentence from that line, because it also has other junk in it. and then i tinkered with it, tried to get rid of the grep call and do it all in sed---with less than stellar results. so i've left it like this (so it will actually work!), but i'm wondering how else it could be accomplished? hopefully somebody here can teach me a new trick
edit: just realized i could pull the feed with w3m rather than wget
Last edited by upsidaisium (2010-01-13 03:51:43)
I've seen young people waste their time reading books about sensitive vampires. It's kinda sad. But you say it's not the end of the world... Well, maybe it is!
Offline
Script to generate a list of updates in format 'name current_version -> new_version'. Suitable for embedding in conky or some such.
#!/bin/bash
nu=0
pacman -Qu | while read name ver; do
let ++nu
test $nu -gt "$1" && break
newver="`pacman -Si "$name" | sed -n 's/Version\s*:\s*\(.*\)$/\1/p'`"
echo "$name $ver -> $newver"
done
test "`pacman -Qu | wc -l`" -gt "$1" && echo '...'
The first argument is the number of entries you want to display. If it's less than the total number of updates, an ellipsis will be appended.
Note: the script is abysmally slow, so you'll probably want to ${execi 60 ...} it. Could probably speed it up, but my regex-fu was rusty.
Last edited by Peasantoid (2010-01-14 02:40:11)
Offline
Offline
I still feel a shell-fu style site would be superior. I laid out some brainstorming somewhere earlier in the thread. Patches welcome
Edit:
Something like shell-fu would be best here... Sounds like a great project for someone to make!
It should have sorting/listing and searching based on tags, script name, and a brief description. It should have language-aware syntax highlighting, which would hopefully try to guess (asking the user to confirm language). It should have a discussion area for someone to submit comments and suggestions for the script. The script should be editable by the user who submitted it, with a versioned history (I'm thinking like the mediawiki page history listing). User comments should be tagged somehow with the version they commented against, so that it's clear what they are referring to. It should also have a spot for the author to provide notes or a longer description.
So, who's going to make it?
Last edited by Daenyth (2010-01-16 00:46:38)
[git] | [AURpkgs] | [arch-games]
Offline
You are just too cool <3
For the tagging, maybe try to add an alias feature. For example, if you put "mtg" as a game tag in your profile on NearbyGamer.net, it automatically sets the tag as "Magic: The Gathering". Might help tag overlap issues.
[git] | [AURpkgs] | [arch-games]
Offline
any sed/regex gurus out there? i made a little script to pull the word of the day from dictionary.com's rss feed:
How does this work for you:
wget -q -O - http://feeds.reference.com/DictionarycomWordOfTheDay | sed '/description.*</!d; s/.*>\(.*\)<.*/\1/'
/etc/rc.d/ is where daemons reside. Beware.
Offline
Strange seeing this here, now ...
I had the same thing set up for a while, but my regex sucks even more than previously thought possible. Mine goes like this:
#! /bin/sh
if [ ! -f /tmp/wotd ]; then
wget http://feeds.reference.com/DictionarycomWordOfTheDay --quiet -O - | grep '^.*\<description\>.[[:alpha:]]*\:' | sed 's/\(.*\)>//' | sed 's/\&\(.*$\)//' > /tmp/wotd
fi;
cat /tmp/wotd
You gotta save bandwidth these days
Last edited by Hiato (2010-01-17 15:45:15)
Offline
upsidaisium wrote:any sed/regex gurus out there? i made a little script to pull
the word of the day from dictionary.com's rss feed:How does this work for you:
wget -q -O - http://feeds.reference.com/DictionarycomWordOfTheDay | sed '/description.*</!d; s/.*>\(.*\)<.*/\1/'
works like a charm! so, let's see if i understand.. /description.*</!d; deletes
everything but the line that matches that regex?? and then the second part finds the word of the
day (+ definition) in the line that wasn't deleted? seems to make sense! and most importantly,
it works
I've seen young people waste their time reading books about sensitive vampires. It's kinda sad. But you say it's not the end of the world... Well, maybe it is!
Offline
Literally whipped this up in 3 minutes, but I find it quite useful. It's for organizing images.
#!/bin/zsh
case $1 in
-add)
mkdir -p ~/.picdb/$2
mv $*[3,-1] ~/.picdb/$2 ;;
-get)
find ~/.picdb/$2 -type f 2>/dev/null || {
print "No pictures with that tag" >&2
return 1
} ;;
*)
print "Usage: $(basename $0) -add [TAG] [PICS] or -get [TAG]"
return ;;
esac
Some examples:
View all images that match a tag name:
imageviewer $(picdb -get tagname)
Shuffle between wallpapers:
Add some pictures to "wallpapers" with picdb -add wallpapers picshere, then add this to .xinitrc:
while true; do
feh --bg-center "$(picdb -get wallpapers | shuf -n 1)"
sleep 15m
done &
edit: fixed bug
edit2: improvement
Last edited by JohannesSM64 (2010-01-22 12:48:01)
Offline
Local absget with completion. Works with globs and more than one search term:
absget() {
local repo
[[ $1 == -r ]] && { repo=$2; shift 2; } || repo=@(community|core|extra)
until (( $# == 0 )); do
find /var/abs/$repo -name "$1" -type d -exec cp -r {} . \;
shift
done
}
_absget() {
local cur=`_get_cword`
COMPREPLY=($(compgen -W "$(if [[ ${COMP_WORDS[1]} == '-r' ]]; then
command pacman -Slq "${COMP_WORDS[2]}"
else
command pacman -Slq
fi)" -- "$cur"))
}
complete -F _absget absget
e: group that shift 2 ;)
Last edited by res (2010-01-19 18:04:44)
Offline
This solves a very specific problem. My web server in my uni absolutely must connect through wifi. It doesn't get much traffic, so it frequently gets kicked off the network.
#!/bin/bash
while true
do
sleep 10m
curl google.com &> /dev/null
done
Why not use ping? It's filtered, just like at every other learning institution I've been to. It's not a cry out for help. It does its job with what is probably the least wasted bandwidth possible. Just
sh keepalive.sh &
and forget. Yes, it's trivial, but I find it useful.
Update: Didn't work. I suspect other problems with my university.
Last edited by urist (2010-01-19 14:15:59)
Offline
To save resources, may I suggest a cron entry for "curl google.com" instead of a separate script?
I only use scripts for occurances less than 1 minute (which cron cannot manage)
Offline
I think you can give curl a range so that you could tell it to only fetch the first few bytes.
[git] | [AURpkgs] | [arch-games]
Offline
Here's mine for calculating the correct font dpi for your screen resolution and size.
Example usage: ./dpi 1280 1024 19
Where: 1280 is the horizontal resolution, 1024 is the vertical resolution, and 19 is the size of the screen in inches (measured from one corner of the screen to the opposite diagonal corner).
Disclaimer: The script depends on your inputs and may not yield the most optimal result! For best results, use the native resolution of your screen (consult the technical manual) and actual viewable area of the screen. Keep in mind that 72dpi and 96dpi are the two standard dpi sizes fonts are typically designed for.
#! /usr/bin/env python
import sys, math
def calculatedpi():
hres = float(sys.argv[1])
vres = float(sys.argv[2])
dsize = float(sys.argv[3])
dpi = hres / (hres / math.sqrt(hres**2 + vres**2) * dsize)
print "Your screen's dpi =", int(dpi)
print ""
def main():
argerror = False
if len(sys.argv) < 4:
argerror = True
else:
for arg in sys.argv[1:]:
if arg.isdigit() == False:
argerror = True
if argerror == True:
print "DPI calculator"
print "Usage: dpi hres vres size"
print "Where:"
print " hres = horizontal resolution in pixels"
print " vres = vertical resolution in pixels"
print " size = size of screen in inches"
print "Example:"
print " dpi 1280 1024 19"
print " Your screen's dpi = 86"
print ""
else:
calculatedpi()
if __name__ == "__main__":
main()
Last edited by samjh (2010-01-19 23:17:48)
Offline
Interesting script samjh, tells me my proper DPI is 86...maybe thats why my fonts aren't great as I use 96 DPI...
Be careful with it, told me that my 26" Bravia @ 1360x768 was 60dpi - tried to configure my stuff as such but was an absolute nightmare, gave up and went back to 96.
Offline
What if it's a laptop screen? Eg. 13.3" or 12.1" etc
Offline
kourosh wrote:Interesting script samjh, tells me my proper DPI is 86...maybe thats why my fonts aren't great as I use 96 DPI...
Be careful with it, told me that my 26" Bravia @ 1360x768 was 60dpi - tried to configure my stuff as such but was an absolute nightmare, gave up and went back to 96.
Hmm, just worked out to see if xorg recognises my dimensions correctly..bit of pythagoras later and it says I have a 17" screen...I have a 19" screen...still running on 96 dpi for now but I might give 86 a go. Is xorg detecting my screen size wrong?
Sorry, bit OT but the script itself seems to work out correctly.
Offline
Display a random 15 mp3 files:
$ find ~/Music -name "*.mp3" | shuf -n 15
I use this because my music collection contains many songs in there twice, one MP3 & one FLAC, depending on what I want to do with it. Ahh, the joys of a 1.5TB hard drive And I've yet to find a music player that treats a song with all the same tags, and just a different extension, as the same song.
Offline
What if it's a laptop screen? Eg. 13.3" or 12.1" etc
I hadn't considered that possibility!
The script gives the mathematically correct dpi for a user-provided specification, but this may not actually be the most optimal. Each screen has its native resolution and viewable area (not necessarily the same as the physical monitor size, although it should be the same for most LCD monitors), and the dpi should actually be calculated using those values.
Also, there are two standard dpi values: 72dpi, which is used for Mac monitors and is the typographical standard (the size of a "point" used in publishing most closely match the pixel size of those monitors, in theory); and 96dpi, which is what is used by Windows (typical of Microsoft to come up with their own). Fonts tend to be designed around those two standards.
I got the idea of making a script like it when I was distro-hopping between Ubuntu and Fedora, and realised that the two distros were using different dpi settings. Then I started using Xfce and discovered that Xorg sometimes detects the wrong dpi and makes fonts look extremely small. My screen's correct physical dpi is 86dpi (1280x1024 native resolution and 19" viewable area), which is calculated correctly by my script.
Offline
Xorg apparently won't let me override DPI, but since Windows uses 96 DPI, and its autodetected 96, I'm going to go with that. I've probably got a monitor manual about but I've lost it. Nice script though.
Offline
Simple BASH function for doing quick decimal/hexadecimal color conversions:
function color {
if [[ $1 =~ ([[:xdigit:]]{2})([[:xdigit:]]{2})([[:xdigit:]]{2}) ]]
then
printf "(%d, %d, %d)\n" \
0x${BASH_REMATCH[1]} 0x${BASH_REMATCH[2]} 0x${BASH_REMATCH[3]}
elif [[ $1 =~ ([[:digit:]]{1,3}),([[:digit:]]{1,3}),([[:digit:]]{1,3}) ]]
then
printf "#%02x%02x%02x\n" ${BASH_REMATCH[1]} ${BASH_REMATCH[2]} ${BASH_REMATCH[3]}
fi
}
Usage:
$ color 0,255,127
#00ff7f
$ color 00ff7f
(0, 255, 127)
Last edited by mikesd (2010-01-22 11:58:01)
Offline
Display a random 15 mp3 files:
$ find ~/Music -name "*.mp3" | shuf -n 15
I use this because my music collection contains many songs in there twice, one MP3 & one FLAC, depending on what I want to do with it. Ahh, the joys of a 1.5TB hard drive And I've yet to find a music player that treats a song with all the same tags, and just a different extension, as the same song.
thanks, i took this and expanded on it abit
you use this like :
randommp3.sh 5
where 5 is the number of random songs you want to play.
#!/bin/bash
find ~/torrents/music/ -name "*.mp3" | shuf -n $1 > .mp3s
mpg123 -@ .mp3s
rm .mp3s
Desktop: E8400@4ghz - DFI Lanparty JR P45-T2RS - 4gb ddr2 800 - 30gb OCZ Vertex - Geforce 8800 GTS - 2*19" LCD
Server/Media Zotac GeForce 9300-ITX I-E - E5200 - 4gb Ram - 2* ecogreen F2 1.5tb - 1* wd green 500gb - PicoPSU 150xt - rtorrent - xbmc - ipazzport remote - 42" LCD
Offline