Vertical label creation

Problem

You want to generate a vertical image, with text over the top.



Solution

Here is some code I wrote, which is used extensively on my sites:



Example




Reference

Give it a blast on this site, like this: http://coding-school.com/common/label-up.php?label=your+text+here

Automatically calculates size required. You can also add font=# – where # is 1 to 5, like this:

http://coding-school.com/common/label-up.php?label=your+text+here&font=3

I’ve now created an online tool, using this code



libcurl lookup taking long time

Problem

You notice for some hosts curl and/or libcurl are taking 7 or so secs to lookup the host. But nslookup or dig respond almost immediately.



Solution

Try doing curl -4 -w “time_namelookup: %{time_namelookup}n” …. and try without the -4. If you see drastic differences, you could be falling foul of the IPV6 bug. To work around this, you can either just use -4 with curl or set CURLOPT_IPRESOLVE with libcurl.



Example


I spents hours and hours and hours, trying to get this working with libcurl and perl. It turned out I need to upgrade to WWW::Curl::Easy version 3.0 – as opposed to version 2. Do a search on search.cpan.org for Curl and it will tell you how to check your version.

Then if you like me upgrade, you need to also modify all your code from: Curl::easy::setopt($curl, … to $curl->setopt( …



Reference



10 simple techie tips for lazy people

Problem

Don’t know about you, but I’m generally quite lazy. Why roll the mouse and click the screen,
when with a quick control c I can copy some text. 🙂



Solution

Learn 10 simple short cuts, which can save you hours.



Example


1.

Copy some text – select it then control c
Now it is in the clipboard.

2.

Click where you want to paste it and control v to paste it. 😉

You can also right click with your mouse to cut and paste.

3.

Minimise all windows, by holding down the windows key and press m

4.

Kick off explorer, by holding down windows key and press e

5.

Do a find by holding down windows key and press f

6.

Switch between windows by holding down alt and pressing tab

7.

Reverse tab through a HTML form, by holding down the shift key.

8.

Open a web link in a new window, by holding down shift and clicking it

9.

To type in a new web address, hold down alt and press d

10.

Save a document with control s, print it with control p, undo a change with control z – sorry got carry away. 🙂



Reference



HTTP Basic Auth with HTTP headers and libcurl

Problem

Came across an interesting problem with curl.

For curl to perform HTTP Basic Authentication, it is easy to pass –user to the curl command, but harder with libcurl.

Suspect there is an attribute that can be set, but I monitor a multitude of web sites through some perl scripts and libcurl. I did n’t want to have to modify my wrapper scripts, which mesh perl hashes with the code that drives curl (via libcurl).

I do allow for headers though, having needed to pass different things through, like HTTP_REFERER, LAST_MODIFIED, etc.

Therefore I just needed to pass the HTTP BASIC Authentication through as a header.



Solution

First off you need to base64 encode the user and password.

Use Google’s tool



Example


We then strip out the equals and pass following through to curl or libcurl:

@myheaders=('Authorization: Basic YWRtaW46YWRtaW4');Curl::easy::setopt($curl, Curl::easy::CURLOPT_HTTPHEADER, @myheaders);

Or from the command line:

curl ... -H'Authorization: Basic YWRtaW46YWRtaW4'

Obviously you need to put your user, followed by a colon and your password – to obtain the correct base64 encoding back – strip the equals out and away you go.



Reference



Simple Basic Encryption – Main differences between algorithms

Problem



Solution



Example




Reference

Symmetric Algo – one key to encrypt and decrypt.

Asymmetric Algo – separate key to encrypt and decrypt.

Stream ciphers – encrypt each bit in sequence.

Block ciphers – encrypt specific blocks of bits.

Hash/Message Digests – one way ciphers, create fingerprints of data.



Simple Basic Encryption – Most commonly used algorithms

Problem

Want to know the encryption short or long names.



Solution

DES – Digital Encryption Standard. Symmetric block encryption algorithm

3DES – Triple DES. Symmetric block algo – uses DES three times.

RC4 – Rivest Cipher #4. Symmetric algo uses stream encryption.

RSA – Rivest, Shamir, Adelman. Symmetric block algo.

IDEA – International Data Encryption Algo, symmetric block algo – used by PGP.

AES – Advanced Encryption Standard (Rijndael) – symmetric block algo.



Example


Demo of des3, rc4 and aes256 – using abc123 as password and thecatsatonthemat

$ echo thecatsatonthemat |  openssl enc -des3 -a -e -k abc123U2FsdGVkX1/I03dG1d8bGYycfojc4x/S5uU1YIf1QRPRw+9AgKhVCw==$ echo "U2FsdGVkX1/I03dG1d8bGYycfojc4x/S5uU1YIf1QRPRw+9AgKhVCw==" | openssl enc -des3 -a -d -k abc123thecatsatonthemat$ echo thecatsatonthemat |  openssl enc -rc4 -a -e -k abc123U2FsdGVkX1+NuZk94r5kJdFfw8gsjlO9ZV7BDXLwm+3PNg==$ echo "U2FsdGVkX1+NuZk94r5kJdFfw8gsjlO9ZV7BDXLwm+3PNg==" |  openssl enc -rc4 -a -d -k abc123thecatsatonthemat$ echo thecatsatonthemat |  openssl enc -aes256 -a -e -k abc123U2FsdGVkX1/bGQ0rtpGi6CjkeAyyEgQjnxkSWBQ6q7XLgAApdWHA5BdEuK24r/NY$ echo "U2FsdGVkX1/bGQ0rtpGi6CjkeAyyEgQjnxkSWBQ6q7XLgAApdWHA5BdEuK24r/NY" |  openssl enc -aes256 -a -d -k abc123thecatsatonthemat


Reference

Wiki links



Ldap reference – ldap result codes

Problem

Getting errors in LDAP



Solution

Click on LDAP error number below to see LDAP error description.



Example


0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,16,
17,18,19,20,21,32,
33,34,35,36,48,
49,50,51,52,53,54,64,
65,66,67,68,69,70,71,76

NumberMeaning
0Success
1Operations error
2Protocol error
3Timelimit exceeded
4Sizelimit exceeded
5Compare false
6Compare true
7Authentication method not supported
8Strong authentication required
9Parital results and referral received
10Referral received
11Administrative limit exceeded
12Unavailable critical extension
13Confidentiality required
14SASL bind in progress
16No such attribute
17Undefined attribute type
18Inappropriate matching
19Constraint violation
20Type or value exists
21Invalid syntax
32No such object
33Alias problem
34Invalid DN syntax
35Object is a leaf
36Alias deferenencing problem
48Inappropriate authentication
49Invalid credentials
50Insufficient access
51Server is busy
52Server is unavailable
53Server is unwilling to perform
54Loop detected
64Naming violation
65Object class violation
66Operation not permitted on non-leaf entry
67Operation not permitted on a RDN
68Entry already exists
69Cannot modify object class
70Results too large
71Affects multiple servers
76Virtual list view error


Reference



Simple Basic UNIX – more advanced vi tips

Problem

Continuing along with more vi tips, these can help you out of a jam or just save you time – going back to command line, etc.

Saving a file, which is read-only? Running java, Perl, PHP from within vi.



Solution

Use chmod.



Example


Have you ever edited a file, made your changes only to find the file is write only? Then in zsh at least, it won't save it.

Here is a simple work around:

:!chmod u+w %

Percent is a shortcut in vi to the current file.

How about shell programming or PHP, Perl or even Java. You want to run the code, just like this:

!./%!javac %;java `echo % | sed 's/.java//'`!php -q %


Reference