The Wiert Corner – irregular stream of stuff

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

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

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

    Join 1,860 other subscribers

Archive for the ‘PHP’ Category

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:


<?php
echo "<h1>gd_info</h1>";
$gdInfo = gd_info();
echo "<table>";
foreach($gdInfo as $key=>$value) {
echo "<tbody>";
echo "<tr>";
echo "<td class='e'>" . $key . "</td>";
echo "<td class='v'>" . $value . "</td>";
echo "</tbody>";
}
echo "</table>";
?>

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


{
"id": 1,
"gravatarHtml": {
},
"profileUrl": "http:\/\/superuser.com\/users\/1\/jeff-atwood",
"displayName": "Jeff Atwood",
"reputation": "14,561",
"badgeHtml": "<span title=\"24 gold badges\"><span class=\"badge1\">&#9679;<\/span><span class=\"badgecount\">24<\/span><\/span><span title=\"79 silver badges\"><span class=\"badge2\">&#9679;<\/span><span class=\"badgecount\">79<\/span><\/span><span title=\"109 bronze badges\"><span class=\"badge3\">&#9679;<\/span><span class=\"badgecount\">109<\/span><\/span>"
}

view raw

1.json

hosted with ❤ by GitHub

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:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
.valuable-flair .userInfo .username a, .valuable-flair .mod-flair
{
color: #1086A4;
}
</style>
<link rel="stylesheet" href="//sstatic.net/flair-Default.css" />
</head>
<body>
<div class="valuable-flair">
<div class="gravatar">
<a title="See my profile on Super User" target="_blank" href="http://superuser.com/users/1/jeff-atwood"><div class="gravatar-wrapper-50"><img src="https://www.gravatar.com/avatar/51d623f33f8b83095db84ff35e15dbe8?s=50&amp;d=identicon&amp;r=PG&quot; alt="" width="50" height="50"></div></a>
</div>
<div class="userInfo">
<span class="username"><img src="http://superuser.com/favicon.ico&quot; width="16" /><a href="http://superuser.com/users/1/jeff-atwood&quot; target="_blank">Jeff Atwood</a><span class="mod-flair" title="moderator">&#9830;</span></span>
<br />
<span class="reputation-score" title="reputation score">14,561</span>
<br />
<span title="24 gold badges"><span class="badge1">&#9679;</span><span class="badgecount">24</span></span><span title="79 silver badges"><span class="badge2">&#9679;</span><span class="badgecount">79</span></span><span title="109 bronze badges"><span class="badge3">&#9679;</span><span class="badgecount">109</span></span>
</div>
</div>
</body>
</html>

view raw

1.html

hosted with ❤ by GitHub

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, Linux, openSuSE, PHP, Pingback, Power User, Scripting, Software Development, Stackoverflow, SuSE Linux | Leave a Comment »

Hosting Grumpydev Imageflair locally

Posted by jpluimers on 2017/04/06

Even though StackOverflow and StackExchange now have implemented their own ImageFlair, I still like the original imageFlair that Grumpydev made at Stack Overflow – Share Your Flair – Now in PNG! | GrumpyDev

Grumpydev Imageflair

Stackoverflow imageflair

Stackoverflow imageflair

Alas, the Grumpydev site doesn’t properly support https and Grumpydev cannot change it because of shared hosting limitations, so I wanted to host ImageFlair locally and even see if I could make it StackExchange aware:

Stackexchange flair

Stackexchange flair

Well, I need to do that propertly another time as the first thing I bumped into was this:

PHP Fatal error: Call to undefined function imagecreatefrompng() in /srv/www/vhosts/pluimers.com-ssl/stackoverflow/imageFlair/imageFlair.php on line 42

For now I’ve fixed the first by installing php5-gd (although an SO answer suggests php-gd, openSuSE uses the php-version number for installing modules).

zypper install php5-gd
php -m
rcapache2 stop
rcapache2 start
rcapache2 status

This will install the module, check with php if it is indeed installed, then restart apache to let it use the updated module.

After that, I bumped into a second thing: the image is blank.

Blank imageFlair

Blank imageFlair

I also bumped into a third thing: the .htaccess file rewrite doesn’t work:

https://www.pluimers.com/stackoverflow/imageFlair/so/1.png gave me a 404 error whereas https://www.pluimers.com/stackoverflow/imageFlair/imageFlair.php?userid=1&mode=so “works” (i.e. generates a blank image).

That one was sort of easy to solve.

First of all, apparently I didn’t have all the required apache modules installed. The not-so-easy part is that apache uses two different aliases for modules: the ones listed by apache2ctl -M 2>&1 | sort are in a different format than the ones you mention in .htaccess and .conf files. Oh and of course the -M (nor the -t -D DUMP_MODULES) aren’t listed ore hinted in the apachectl documentation: that would be too easy. They are listed in the httpd2 documentation.

The .htaccess file needs mod_rewrite and mod_expires, but apache2ctl names them rewrite_module and expires_module.

Enabling these was easy, but you have to remember that a2enmod strips the prefix/suffix of the module name (I already had expires_module (shared) installed so this only shows how to enable mod_rewrite):

a2enmod rewrite
rcapache2 stop
rcapache2 start
rcapache2 status

NB: mod_rewrite wasn’t enable by default and before enabling it, read about the risks of mod_rewrite.

Then it still didn’t work, and then it occurred to me that likely I didn’t even have Apache2 allow for using .htaccess as the regexes in the .htaccess were fine. And indeed: .htaccess wasn’t enabled according to the steps at Making sure .htaccess and mod_rewrite are working as they should | Bolt Documentation. And indeed, the Apache documentation indicates when (not) to use .htaccess.

By setting the AllowOverride to both FileInfo as specified by RewriteRule and Indexes as specified by ExpiresActive (trying to refrain from AllowOverride All) for only this specific directory, I think I struck the right balance:


<Directory "/srv/www/vhosts/pluimers.com-ssl/stackoverflow/imageFlair">
# for .htaccess in that directory
AllowOverride FileInfo Indexes
</Directory>

And the final thing is that the logic around StackExchange flair is a tad more complex than I hoped for. And on that bombshell…

–jeroen

Posted in *nix, Apache2, Development, Linux, openSuSE, PHP, Power User, Scripting, Software Development, SuSE Linux | 1 Comment »

reStructuredText notes (.rst file extension)

Posted by jpluimers on 2016/04/28

Thanks to Eric Grange who asked Which lightweight markup language? I learned about reStructuredText (no cap R!) from a few comments Joseph Mitzen made.

It looks like reStructuredText has been around for much longer than Markdown, has better features (#1 for me: it is unambiguous, : native support on GitHub), but isn’t as popular. I think the latter is because finding editors supporting a live preview for it is a bit hard and tools are scattered around the net.

So here are a few notes on how I got reStructuredText to work on my Mac using OS X.

The hardest part was getting the reStructuredText preview for Atom to work:

  1. Verify you have recent apm/npm
  2. Download, then install the latest Mac Pandoc release (filename like “pandoc-*-osx.pkg”).
  3. Open Atom
  4. Menu “Atom” -> “Preferences” to open a “Settings” tab in the Atom user interface
  5. In the list “Settings”, “Keybindings”, “Packages”, “Themes”, “Updates”, “Install”, choose the last one: “Install”
  6. In the “Search packages” textbox, type “language-restructuredtext”, then hit Enter
  7. Wait a few seconds until “language-restructuredtext” appears in the list, then click the “Install”  button next to it
  8. In the “Search packages” textbox, type “rst-preview-pandoc”, then hit Enter
  9. Wait a few seconds until “rst-preview-pandoc” appears in the list, then click the “Install” button next to it
  10. To enable spell checking:
    1. In “Settings”, go to “Packages”
    2. Search for “spell-check”
    3. Click “settings”
    4. Add “gfm.restructuredtext” to the “Grammars” list
    5. Note you get “gfm.restructuredtext” from the “language-restructuredtext” package as described in Spell check in Atom – Atom quick tip #3 – Atom Editor Tips and Tricks.
  11. Restart Atom from the command-line (otherwise it will not find pandoc *)
  12. Open a reStructuredText file
  13. Press Ctrl-Shift-e to show the preview
  • pandoc error:

The error you get when pandoc cannot be found is this one:

‘pandoc’ could not be spawned. Is it installed and on your path? If so please open an issue on the package spawning the process.

It is easy to solve by modifying the Atom startup shell script and then don’t start Atom.app, but start atom from the command-line in a terminal window:

atom

For Windows:

  1. Install Chocolatey Gallery.
  2. Follow the steps at Hello Windows.
  3. Fails horribly: “The term ‘Install-ChocolateyPackage’ is not recognized as the name of a cmdlet”.
    1. Split-Path bug preventing Chocolatey to install a package · Issue #686 · chocolatey/chocolatey · GitHub.

A later try to get Pandoc installed on Windows was much easier: there is a Pandoc for Windows installer now.

Settings changes

I made a few, for instance:

  1. Ensure Tab to expands to spaces: See Soft Tabs and Tab Length under Settings > Editor Settings. via github – Atom – Change indentation mode – Stack Overflow.

Tables

Tables are always a hard thing in any markup. Luckily truben.no/table/ has a good table editor (it’s the same as table-editor.com) and can emit reStructuredText, Markdown, HTML and other formats.

More in the future

Give me some time, and I will post more about using the format and how it compares to my Markdown past.

Note that pandoc does not fully support reStructuredText (for instance not all table features are supported), but docutils rst2html.py does and also gives better warning/error information when parsing.

Here are some links about the reStructured syntax and how they can be rendered by rst2html.py:

For now, I’ll end with the goals of reStructuredText which I really like:

Read the rest of this entry »

Posted in Development, MarkDown, Perl, PHP, Power User, Python, reStructuredText, Scripting, Software Development | Leave a Comment »

Dynamic DNS through NO-IP: keeping your hosts current, and your NO-IP account happy.

Posted by jpluimers on 2015/05/19

Now that DynamicDNS moved itself to a fully payed service, named it DynDns Pro, then renamed it Remote Access and limiting it to 30 hosts for USD 25 a year, I looked for alternatives, and noticed NO-IP.

I like it for a few reasons:

OK, last year, there was this Microsoft Legal Action and Controversy, but I think that is a once time thing (some people even argue that Microsoft wasn’t thinking), so I created the last script below in PowerShell.

A few open-source scripts to keep your NO-IP account happy (that also work on most other DDNS providers like Duck DNS):

Read the rest of this entry »

Posted in *nix, *nix-tools, bash, CommandLine, Development, Perl, PHP, Power User, PowerShell, Scripting, Software Development | 1 Comment »

RosettaCode: cool way to improve your coding skills

Posted by jpluimers on 2015/01/22

Wow: I feel like having lived under a stone for 8 years, as RosettaCode has been alive since it was founded in 2007 by Mike Mol.

The idea is that you solve a task and learn from that, or learn by seeing how others have solved tasks or draft tasks.

So in a sense it is similar to the Rosetta stone: it has different languages phrasing the same tasks.

There are already a whole bunch of languages on RosettaCode (of which a few are in the categories below), and you can even suggest or add your own languages.

When you want to solve tasks, be sure to look at the list unimplemented tasks by language that leads to automatic reports by language (for instance two of the languages I use most often: C# and Delphi).

I’m sure there are lots of programming chrestomathy sites, even beyond the ones, and it feels very similar to programming kata sites.

–jeroen

Posted in .NET, APL, Awk, bash, Batch-Files, C, C#, C++, COBOL, CommandLine, Delphi, Development, Fortran, FreePascal, Java, JavaScript/ECMAScript, Lazarus, Object Pascal, Office VBA, Pascal, Perl, PHP, PowerShell, PowerShell, Prism, Scripting, sed script, Sh Shell, Software Development, Turbo Prolog, VB.NET, VBS, VBScript, Visual Studio and tools, Web Development | Leave a Comment »

Choose your chart type & Amount of profanity in git commit messages per programming language (via: andrewvos.com)

Posted by jpluimers on 2014/03/07

Funny charts at andrewvos.com – Amount of profanity in git commit messages per programming language.

The source is online too: AndrewVos/github-statistics.

And it led me to this really nice way of choosing your chart type.

Click to enlargeRead the rest of this entry »

Posted in .NET, C#, C++, Development, Java, JavaScript/ECMAScript, Perl, PHP, Ruby, Scripting, Software Development, Web Development | 2 Comments »

Cyber-Dojo: practice unit-tested programming in pairs/groups using Katas

Posted by jpluimers on 2013/11/07

Wow, I’ve been living under a stone (:

Just discovered the online Cyber-Dojo by Jon Jagger. It is an online manifestation of a Coding Dojo. Both have been there for years, and I think both are brilliant.

They take the concept of a Dojo as being a place to practice sports like martial arts in a pair or group setting with a series of Katas or practices.

Katas in a Dojo are a means for performing deliberate practice in order to learn new things. For instance, acquire new movement techniques, learn about your balance, gain strength, all in both a physical and mental way.

The aim of both is do more deliberate practice.

When performing Coding and Cyber Dojo, you should use Test Driven Development using pair programming and BabySteps. Those help you to slow down, as one of the Dojo Principles is for Katas to slow down. It reminds me of the “if you are in a hurry, sit down” mantra and is a key part of the Coding/Cyber Dojo Principles too.

The aim is to learn, and part of that is to first un-learn and open you to new thoughts. That’s why it is so cool that the Cyber-Dojo provides you with:

  • a bunch of pre configured programming languages*,
  • preformulated practices** (including a few cyber-dojo refactorings),
  • a small boilter plate to get started.

You’d think they speed you up, but that is not their aim. Like a regular Dojo it gives you an pre-set environment and gives you piece of mind to get started.

The Cyber Dojo does without a Sensei, whose purpose in a Coding Dojo is to ask questions in order to guide the participants.

That’s why it is good to use the Cyber Dojo as part of a Coding Dojo: basically the Cyber Dojo provides a standardizes set of tools to quickly setup a Coding Dojo.

Cyber Dojo languages

(a prime number, so the table is a bit distorted)

C Go PHP
C# Haskell Perl
C++ Java-Approval Python
Clojure Java-Cucumber Ruby
CoffeeScript Java-JUnit Ruby-Rspec
Erlang Javascript

Cyber Dojo practices

Many of the practices come from rosettacode.org.

100 doors Harry Potter Print Diamond
Anagrams LCD Digits Recently Used List
Bowling Game Leap Years Reversi
Calc Stats Mine Field Roman Numerals
Count Coins Monty Hall Tennis
Diversion Number Names Unsplice
Fizz Buzz Phone Numbers Verbal
Game of Life Poker Hands Yahtzee
Gray Code Prime Factors Zeckendorf Number

–jeroen

via:

Posted in .NET, Agile, C, C#, C++, Development, Java, JavaScript/ECMAScript, Perl, PHP, Scripting, Software Development, Unit Testing | 3 Comments »

C#: any c# – .NET Enumeration allows comma in the last field – Stack Overflow

Posted by jpluimers on 2012/12/06

Thanks Nick Craver for answering this on StackOverflow.

Array initializers can be specified in field declarations (§17.4), local variable declarations (§15.5.1), and
array creation expressions (§14.5.10.2).

The array initializer can end in a comma, which makes some things way easier (boy, I wish I had this in other programming languages).

From Nick’s answer:

It has no special meaning, just the way the compiler works, it’s mainly for this reason:

[FlagsAttribute]
public enum DependencyPropertyOptions : byte
{
Default = 1,
ReadOnly = 2,
Optional = 4,
DelegateProperty = 32,
Metadata = 8,
NonSerialized = 16,
//EnumPropertyIWantToCommentOutEasily = 32
}
[/language]By comment request: This info comes straight out of the ECMA C# Specification (Page 363/Section 19.7)

“Like Standard C++, C# allows a trailing comma at the end of an array-initializer. This syntax provides flexibility in adding or deleting members from such a list, and simplifies machine generation of such lists.”

–jeroen

via c# – .NET Enumeration allows comma in the last field – Stack Overflow.

Posted in .NET, C#, C# 1.0, C# 2.0, C# 3.0, C# 4.0, C# 5.0, C++, Delphi, Development, Java, JavaScript/ECMAScript, PHP, Software Development, VB.NET | 5 Comments »

Great session on how to prevent SQL Injection Myths and Fallacies

Posted by jpluimers on 2012/08/15

A few weeks ago, Bill Karwin did a must watch webinar on the prevention SQL Injection titled  “SQL Injection Myths and Fallacies“.

Bill Karwin (twitter, new blog, old blog, Amazon) is famous for much work in the SQL database community, including InterBase/Firebird, mySQL, Oracle and many more.

He also:

Anyway, his webinar is awesome. Be sure to get the slides, watch the replay, and read the questions follow up.

Watching it you’ll get a better understanding of defending against SQL injection.

A few very valuable points he made: Read the rest of this entry »

Posted in .NET, .NET 3.5, .NET 4.5, .NET ORM, ASP.NET, Batch-Files, C#, C# 1.0, C# 2.0, C# 3.0, C# 4.0, C# 5.0, C++, Cloud Development, COBOL, CommandLine, Database Development, Delphi, Delphi for PHP, Delphi x64, Delphi XE2, Development, EF Entity Framework, F#, Firebird, FireMonkey, History, InterBase, iSeries, Java, JavaScript/ECMAScript, Jet OLE DB, LINQ, LLBLGen, MEF, Microsoft Surface, Mobile Development, PHP, PowerShell, Prism, Scripting, SharePoint, SilverLight, Software Development, SQL, SQL Server, SQL Server 2000, SQL Server 2005, SQL Server 2008, SQL Server 2008 R2, SQL Server 2012, SQL Server 7, VB.NET, VBS, Visual Studio 11, Visual Studio 2002, Visual Studio 2003, Visual Studio 2005, Visual Studio 2008, Visual Studio 2010, Visual Studio and tools, Web Development, Windows Azure, WinForms, WPF, XAML, xCode/Mac/iPad/iPhone/iOS/cocoa | 1 Comment »

which kind of IsHex() function do you like most, and why?

Posted by jpluimers on 2012/07/10

Though the sample question is in C#, it applies to almost any language and framework: for relatively simple checks like IsHex(), you can go the RegEx way, or the compound if-statement way.

Which kind of function do you like most?

I’m not only interested in the percentages, so let me know in the comments why.

–jeroen

PS: if you want to use RegEx in .NET, you can compile them to IL, but be very cautious for the compilation overhead.

Posted in .NET, C#, COBOL, Delphi, Development, JavaScript/ECMAScript, PHP, RegEx, Scripting, Software Development, VB.NET | 8 Comments »