The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My work

  • My badges

  • Twitter Updates

  • My Flickr Stream

    20140508-Delphi-2007--Project-Options--Cannot-Edit-Application-Title-HelpFile-Icon-Theming

    20140430-Fiddler-Filter-Actions-Button-Run-Filterset-now

    20140424-Windows-7-free-disk-space

    More Photos
  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,733 other followers

Archive for the ‘bash’ Category

opensuse – How to run my script after SuSE finished booting up? – Unix & Linux Stack Exchange

Posted by jpluimers on 2017/04/21

For future research: opensuse – How to run my script after SuSE finished booting up? – Unix & Linux Stack Exchange

Reason? Want to show the output of this as the last boot sequence line:

hostname
ip route
echo
ip address | grep -w 'UP\|flags\|inet\|inet6'
echo more detailed info through "ip address" and "ip route"
cat /etc/resolv.conf | grep nameserver

–jeroen

Posted in *nix, *nix-tools, bash, Linux, openSuSE, Power User, SuSE Linux, Tumbleweed | Leave a Comment »

Hosting Grumpydev Imageflair locally – part 2 – trying to get the text and images to display

Posted by jpluimers on 2017/04/12

Blank imageFlair

Blank imageFlair

Hosting Grumpydev Imageflair locally ended with two issues left: an empty image and my wish to include more complete StackExchange bits like the current StackExchange flair does.

I thought fixing the empty image would take a rainy day. It actually took a few rainy hours.

No text

The culprit is that I didn’t have the Microsoft Core Fonts for the Web installed. Which was no coincidence as the free download of those from Microsoft terminated in 2002. The upside is that because of their licenses, they are available as open source and most linux distributions have a script package that will download these fonts. OpenSuSE has fetchmsttfonts for this.

Alternatively, you can use the web.archive.org to download manually, but that’s a tad tedious. But if you love tedious: Free downloads – TrueType core fonts for the Web.

zypper install fetchmsttfonts

That installs the fonts in:

/usr/share/fonts/truetype

The drawback of having fetchmsttfonts is that the original Microsoft versions of these fonts are downloaded from corefonts.sourceforge.net each time the fetchmsttfonts package is updated, potentially overwriting newer versions of the fonts in that directory. If you don’t want that, use the trick at  (not yet archived at the WayBack machine) font handling – install fetchmsttfonts, copy fonts, rpm -e fethmsttfonts, copy fonts back.

Having the fonts installed, I thought the only thing I needed to fix were the multiple references in config.php from that pointed to Arial.TTF. I took the poor man’s approach and just did this being in the directory of config.php:

cp /usr/share/fonts/truetype/arial.ttf Arial.TTF

Filled Imageflair

That didn’t work either: still no text showed.

So I decided to run imageFlair.php from the command line after setting $imageflair_debug = true; in config.php which then resulted in all sorts of warnings like

PHP Warning: imagettftext(): Could not find/open font

After reading I decided to build a small php-gd.tester.php script containing phpinfo(); and gd_info showing these portions for PHP GD (non-relevant bits stripped):

Additional .ini files parsed /etc/php5/conf.d/ctype.ini,
/etc/php5/conf.d/dom.ini,
/etc/php5/conf.d/gd.ini,
/etc/php5/conf.d/iconv.ini,
/etc/php5/conf.d/json.ini,
/etc/php5/conf.d/mysql.ini,
/etc/php5/conf.d/mysqli.ini,
/etc/php5/conf.d/pdo.ini,
/etc/php5/conf.d/pdo_mysql.ini,
/etc/php5/conf.d/pdo_sqlite.ini,
/etc/php5/conf.d/sqlite3.ini,
/etc/php5/conf.d/tokenizer.ini,
/etc/php5/conf.d/xmlreader.ini,
/etc/php5/conf.d/xmlwriter.ini

gd

GD Support enabled
GD headers Version 2.1.1
GD library Version 2.1.1
FreeType Support enabled
FreeType Linkage with freetype
FreeType Version 2.6.3
GIF Read Support enabled
GIF Create Support enabled
JPEG Support enabled
libJPEG Version 8
PNG Support enabled
libPNG Version 1.6.21
WBMP Support enabled
XPM Support enabled
libXpm Version 30411
XBM Support enabled
WebP Support enabled

And the gd_info dump:

GD Version 2.1.1
FreeType Support 1
FreeType Linkage with freetype
T1Lib Support
GIF Read Support 1
GIF Create Support 1
JPEG Support 1
PNG Support 1
WBMP Support 1
XPM Support 1
XBM Support 1
WebP Support 1
JIS-mapped Japanese Font Support

Too bad though: no information on where it sources the fonts from.

No image

Having no solution for the font rendering yet, I focussed at the lack of profile picture.

In the past, the images were generated with gravatar information in the JSON, but now that is empty. See for instance the output of http://superuser.com/users/flair/1.json versus his image http://superuser.com/users/flair/1.png

That reveals quite a change in the JSON that imageFlair expects. Actually there is a lot of HTML in there.

So decided to try http://superuser.com/users/flair/1 in addition to http://superuser.com/users/flair/1.json with this result:

Two downsides here:

  1. This doesn’t work for the combined stackexchange flair: http://stackexchange.com/users/flair/1.png works, but http://stackexchange.com/users/flair/1 gives a 404.
  2. Rendering HTML servers side to PNG requires a lot of work.

Time for another rainy day (:

–jeroen

Read the rest of this entry »

Posted in *nix, *nix-tools, bash, Development, PHP, Pingback, Power User, Scripting, Software Development, Stackoverflow | Leave a Comment »

Recursively convert WMA files to MP3 using ffmeg on a Mac OS X bash shell

Posted by jpluimers on 2017/04/05

A friend of mine made the mistake to capture some CDs using WMA files and throwing away the CDs. His old Nokia could play them, but not his new iOS and Android devices.

ffmeg and bash to the rescue:

find . -iname "*.wma" -execdir bash -c 'NAME="{}" && ffmpeg -y -i "$NAME" -ab 192k "${NAME/.wma/.mp3}" -map_metadata 0:s:0 && rm "$NAME"' \;

Tricks used:

–jeroen

Source:

via: command line – How to use Ffmpeg to convert wma to mp3 recursively, importing from txt file? – Ask Ubuntu

Posted in *nix, *nix-tools, Audio, bash, bash, Development, Power User, Scripting, Software Development | Leave a Comment »

sed: convert Google Drive urls to direct download ones

Posted by jpluimers on 2017/03/14

RegEx Fu

RegEx Fu

One of the things after moving most of my things from copy.com to Google Drive was the direct (public) download URLs that copy.com provides. DropBox has them as well, but Google Drive lacks them in the UI.

There is a URL format that does allow for direct download though:

While Google aims for Drive to be a competent Dropbox competitor, there’s one small but key feature that isn’t easy: sharing direct download links. Fortunately, you can create your own.

Source: Share Direct Links to Files in Google Drive and Skip the Web Viewer

You can do a similar replacement for Google Doc URLs: How to Create Direct Download Links for Files on Google Drive

The Google Drive conversion seems straightforward as they convert from either of

https://drive.google.com/file/d/FILE_ID/edit?usp=sharing
https://drive.google.com/file/d/FILE_ID/view
https://drive.google.com/open?id=FILE_ID

to

https://drive.google.com/uc?export=download&id=FILE_ID

There are tons of RegEx examples for doing the first conversion at Regex to modify Google Drive shared file URL – Stack Overflow, but

  1. they don’t cover the two conversions
  2. they use the non-greedy (.*?) capturing groups which are tricky, introduce question mark escaping issues in hash and many sed implementations fail to implement non-greedy

Since I’m a command-line person, I’ve opted for a sed conversion that wasn’t in the above list. I choose sed because it allows you to convert either a line or a complete file at one time.

There are a few indispensable resources to get my regex expressions right:

So here it goes, starting with fixing https://drive.google.com/open?id=FILE_ID as it’s the most simple replacement because the FILE_ID is at the end.

First of all, these code fragments below are part of bash functions as bash functions remove the quoting hell you have with bash aliases.

Where bash aliases have no parameters (i.e. the arguments are put after the end of the expansion), functions have parameters. So if you want to pass all function parameters to a command inside a function, you have to use “$@” to pass all parameters.

This fragment fixes https://drive.google.com/open?id=FILE_ID printing each fix on one line using the p for printing command in sed:

sed -n 's@https://drive.google.com/open?id=@https://drive.google.com/uc?export=download\&id=@p' "$@"

A few remarks:

The second fragment fixes https://drive.google.com/file/d/FILE_ID/edit?usp=sharing and https://drive.google.com/file/d/FILE_ID/view again printing each fix:

sed -n 's@https://drive.google.com/file/d/\([^.]*\)/.*@https://drive.google.com/uc?export=download\&id=\1@p' "$@"

Some more remarks:

  • The FILE_ID is obtained from a capturing group during the match using \([^.]*\) and using the value in the replace with \1 as reference.
  • There is backslash escaping of the parentheses because that’s the sed way.
  • I’ve used a non-greedy \(.*?\) capturing group (sed can’t do that) but \([^.]*\)/ which matches any non-slash inside the capturing group until the first slash outside that group.

The final part is combing both replacement into one sed command:

sed 's@https://drive.google.com/open?id=@https://drive.google.com/uc?export=download\&id=@;s@https://drive.google.com/file/d/\([^.]*\)/.*@https://drive.google.com/uc?export=download\&id=\1@' "$@"

Final remarks:

–jeroen

Posted in *nix, *nix-tools, bash, bash, Development, Power User, Scripting, sed, sed script, Software Development | Leave a Comment »

bash – how do I list the functions defined in my shell? – Stack Overflow

Posted by jpluimers on 2017/03/07

Nice: “you can get both aliases and functions with compgen -a -A function

It uses the compgen completion generator. Simply brilliant (:

Source: bash – how do I list the functions defined in my shell? – Stack Overflow

–jeroen

Posted in *nix, *nix-tools, bash, bash, Development, Power User, Scripting, Software Development | Leave a Comment »

 
%d bloggers like this: