Category Archives: Languages

PHP: Get URL Content Using PHP Curl

/* gets the data from a URL */ function get_data($url) { $ch = curl_init(); $timeout = 5; curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout); $data = curl_exec($ch); curl_close($ch); return $data; } Source: http://davidwalsh.name/download-urls-content-php-curl

Posted in Languages | Tagged , | Leave a comment

Perl: Error Handling Try Catch Using Eval

eval { … }; if ($@) { errorHandler($@); }

Posted in Languages | Tagged , , , , | Leave a comment

Bash: How To Get Absolute Value Using BASH

echo ‘-12′ | nawk ‘{ print ($1 >= 0) ? $1 : 0 – $1}’

Posted in Languages, Linux | Tagged | 1 Comment

PHP: How To Convert UTC to Local Time

How to convert your MySQL timestamps from UTC to local time: $gmdatetime = gmdate(“Y-m-d H:i:s”); print “gmdatetime: $gmdatetime\n”; list($gmdate, $gmtime) = explode(‘ ‘, $gmdatetime); list($gmyear, $gmmon, $gmday) = explode(‘-’, $gmdate); list($gmhour, $gmmin, $gmsec) = explode(‘:’, $gmtime); print “gmmktime($gmhour, $gmmin, $gmsec, … Continue reading

Posted in Languages | Tagged , , , | Leave a comment

Perl: How To Write Dynamic Subroutines

Dynamic Functions in Perl #!/usr/bin/perl use strict; { no strict ‘refs’; my $good_name = “foo”; *{ $good_name } = sub { print “Hi, how are you?\n” }; my $remote_name = “Some::Module::foo”; *{ $remote_name } = sub { print “Hi, are … Continue reading

Posted in Languages | 1 Comment

How To Log to Multiple Files Using Log4perl

How to log to multiple files using a single Log4perl logger. Example: you have an INFO level logger, but you want to log warnings and errors to separate files. You also want to log to the screen. ### Throw everything … Continue reading

Posted in Languages | Tagged | 1 Comment