How Tos | Brain Goo https://www.popmartian.com/tipsntricks Carpe Crap 'em Wed, 21 Oct 2026 14:52:32 +0000 en-US hourly 1 https://wordpress.org/?v=6.9.10 HOWTO Build and Install Mcrouter for RHEL, OL, CENTOS 7.x https://www.popmartian.com/tipsntricks/2016/04/26/howto-build-mcrouter-for-rhel-ol-centos-7-x/ https://www.popmartian.com/tipsntricks/2016/04/26/howto-build-mcrouter-for-rhel-ol-centos-7-x/#comments Tue, 26 Apr 2016 17:03:11 +0000 http://www.popmartian.com/tipsntricks/?p=398 How to build, package, and install mcrouter on Linux Continue reading →

The post HOWTO Build and Install Mcrouter for RHEL, OL, CENTOS 7.x first appeared on Brain Goo.

]]>
UPDATE: Unless you have a very specific environment, Facebook likely now has packages or updated compile instructions that will work better than this: https://github.com/facebook/mcrouter

The instructions below are likely out of date and may no longer work.

This post will show you how to build and install Mcrouter. Once complete, you will have a portable Mcrouter installation that you can apply to multiple machines via RPM.

Building Mcrouter is not easy, but this step-by-step process should get you to a collection of RPMs which make up a functional and upgrade-able Mcrouter environment.

About Mcrouter

Mcrouter is a memcached protocol router for scaling memcached (http://memcached.org/) deployments. It’s a core component of cache infrastructure at Facebook and Instagram where mcrouter handles almost 5 billion requests per second at peak.

Mcrouter is developed and maintained by Facebook.

You can get the source and more information here: https://github.com/facebook/mcrouter

You are going to do a lot of compiling and packaging.  Once you have this perfected, it is not a big stretch to hand it off to Jenkins or some other build tool for automation.

Getting Started

You need to build two environments.

Environment 1: Build Environment for compiling and packaging Mcrouter

  • An EL7 Server (RedHat, Oracle Linux, CentOS)
  • Yum updates to the latest stable everything (yum -y update, then reboot)
  • At LEAST 4GB RAM
  • At LEAST 4GB available disk space
  • A decent internet connection
  • Root access

Environment 2: Operating Environment for actually running Mcrouter

  • An EL7 Server (RedHat, Oracle Linux, CentOS)
  • Yum updates to the latest stable everything (yum -y update, then reboot)
  • Sufficient privilege to install RPMs (sudo, root, etc)

(Env 1) Setting up The Build Environment

NOTE 1: All of the following assumes you are root.  Insert your sudo where required if you aren’t just living and breathing as root.

NOTE 2: You are going to install a lot of crap on this system.  I assume you are OK with that.

Before we begin to build Mcrouter, we need to build a lot of the dependencies and install packages required for both running and building the software.

Install a bunch of packages

NOTE 1: Some of these will not exist. We will compile our own RPMs and grab some from Fedora.  All of it is outlined below.

yum -y install gcc-c++ ruby ruby-devel ragel cyrus-sasl cyrus-sasl-devel cmake bison python-libs python-devel numactl-libs numactl-devel scons snappy snappy-devel gflags gflags-devel glog-devel glog boost-devel automake autoconf libtool libevent libevent-devel openssl-devel libatomic flex rpm-build

Most likely the following packages are missing: ragel, scons, glfags, gflags-devel, glog, glog-devel.  Let’s get building and packaging for those.  If you are missing others, you’ll have to build and package them too.

Create a build location

This is where you need the disk space and where you will download, compile and package everything.

mkdir /build

Install fpm

(Effing package management! https://github.com/jordansissel/fpm)

We are going to use FPM to create RPMs as we go.

gem install fpm

If you see some errors at the end similar to this:
Parsing documentation for fpm-1.5.0
unable to convert "\xF3" from ASCII-8BIT to UTF-8 for lib/fpm/package/pyfpm/__init__.pyc, skipping
unable to convert "\xF3" from ASCII-8BIT to UTF-8 for lib/fpm/package/pyfpm/get_metadata.pyc, skipping

You can ignore them.

Build and package ragel

NOTE: Get the latest version of ragel here: http://www.colm.net/open-source/ragel/

Download

cd /build
curl -O http://www.colm.net/files/ragel/ragel-6.9.tar.gz

Build

cd /build
tar zxf ragel-6.9.tar.gz
cd ragel-6.9
./configure
make
make install

Package

mkdir /build/ragelpkg
make install DESTDIR=/build/ragelpkg
cd /build
fpm --verbose -f -s dir -t rpm -n ragel -v 6.9 -C /build/ragelpkg \
usr/local/bin \
usr/local/share/doc/ragel \
usr/local/share/man/man1

You should have an RPM that will install ragel.

Download and install scons, glfags, gflags-devel, glog, glog-devel

Download

cd /build
curl -O http://tenet.dl.sourceforge.net/project/scons/scons/2.5.0/scons-2.5.0-1.noarch.rpm
curl -O https://kojipkgs.fedoraproject.org//packages/gflags/2.1.1/6.el7/x86_64/gflags-2.1.1-6.el7.x86_64.rpm
curl -O https://kojipkgs.fedoraproject.org//packages/gflags/2.1.1/6.el7/x86_64/gflags-devel-2.1.1-6.el7.x86_64.rpm
curl -O https://kojipkgs.fedoraproject.org//packages/glog/0.3.3/8.el7/x86_64/glog-0.3.3-8.el7.x86_64.rpm
curl -O https://kojipkgs.fedoraproject.org//packages/glog/0.3.3/8.el7/x86_64/glog-devel-0.3.3-8.el7.x86_64.rpm

Install

rpm -ivh ./scons-2.5.0-1.noarch.rpm ./gflags-2.1.1-6.el7.x86_64.rpm ./glog-0.3.3-8.el7.x86_64.rpm ./gflags-devel-2.1.1-6.el7.x86_64.rpm ./glog-devel-0.3.3-8.el7.x86_64.rpm

Build and Package Double-Conversion

NOTE: Double-Conversion is a library from Google which provides binary-decimal and decimal-binary routines for IEEE doubles.  Details and source code here: https://github.com/google/double-conversion

Download

cd /build
git clone https://github.com/google/double-conversion.git

Build

cd /build/double-conversion
make
make test
scons install
chmod 0644 /usr/local/lib/libdouble-conversion*
mkdir /usr/local/include/double-conversion
cp double-conversion/*.h /usr/local/include/double-conversion/
chmod 0755 /usr/local/include/double-conversion/
chmod 0644 /usr/local/include/double-conversion/*

Package

cd /build
mkdir -p /build/dcpkg/usr/local/lib/
mkdir -p /build/dcpkg/usr/local/include/double-conversion/

cp -rp /usr/local/lib/libdouble-conversion* /build/dcpkg/usr/local/lib/
cp -rp /usr/local/include/double-conversion/* /build/dcpkg/usr/local/include/double-conversion/

cd /build/double-conversion
VER=$(git tag|tail -1)
cd /build

fpm --verbose -f -s dir -t rpm -n double-conversion -v $VER -C /build/dcpkg \
usr/local/lib/ \
usr/local/include/double-conversion/

You should have an RPM that will install double-conversion.

Build and Package Folly

Lots of information on Folly: https://github.com/facebook/folly

Folly (acronymed loosely after Facebook Open Source Library) is a library of C++11 components designed with practicality and efficiency in mind. Folly contains a variety of core library components used extensively at Facebook. In particular, it’s often a dependency of Facebook’s other open source C++ efforts and place where those projects can share code.

Download

cd /build
git clone https://github.com/facebook/folly

Build

cd /build/folly/folly
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
VER=$(git tag|tail -1)
autoreconf -ivf
LDFLAGS=-L/usr/local/lib CPPFLAGS=-I/usr/local/include ./configure
make -j2
make install

Package

cd /build/folly/folly
mkdir /build/follypkg
make install DESTDIR=/build/follypkg
cd /build
fpm --verbose -f -s dir -t rpm -n folly -v $VER -C /build/follypkg \
usr/local/include \
usr/local/lib

You should have an RPM that will install Folly.

Upgrade your Automake

NOTE: This is only required if you have a version of Automake lower than 1.15

curl -O https://kojipkgs.fedoraproject.org/packages/automake/1.15/1.fc22/noarch/automake-1.15-1.fc22.noarch.rpm
rpm -Uvh automake-1.15-1.fc22.noarch.rpm

Download and Install jemalloc

curl -O https://kojipkgs.fedoraproject.org/packages/jemalloc/3.6.0/1.el7/x86_64/jemalloc-3.6.0-1.el7.x86_64.rpm
curl -O https://kojipkgs.fedoraproject.org//packages/jemalloc/3.6.0/1.el7/x86_64/jemalloc-devel-3.6.0-1.el7.x86_64.rpm

rpm -ivh jemalloc-devel-3.6.0-1.el7.x86_64.rpm jemalloc-3.6.0-1.el7.x86_64.rpm

Build and Package Wangle

More on Wangle: https://github.com/facebook/wangle

Wangle provides a full featured, high performance C++ futures implementation.

Download

cd /build
git clone https://github.com/facebook/wangle

Build

cd /build/wangle/wangle
VER=$(git tag|tail -1)
sed -i -r -e "s@\ \ -lpthread@\ \ -lgflags\n\ \ -lgflags@" CMakeLists.txt
cmake .
make
make test
make install

Package

cd /build/wangle/wangle
mkdir /build/wanglepkg
make install DESTDIR=/build/wanglepkg
cd /build
fpm --verbose -f -s dir -t rpm -n wangle -v $VER -C /build/wanglepkg \
usr/local/include \
usr/local/lib

You should have an RPM that will install Wangle.

Build and Package FBThrift

Read lots about fbthrift here: https://github.com/facebook/fbthrift

FBThrift: Facebook’s branch of apache thrift

Download

cd /build
git clone https://github.com/facebook/fbthrift

Build

cd /build/fbthrift/thrift
VER=$(git tag|tail -1)
autoreconf -ifv
LDFLAGS=-L/usr/local/lib CPPFLAGS=-I/usr/local/include ./configure
make -j2
make install

Package

cd /build/fbthrift/thrift
mkdir /build/fbthriftpkg
make install DESTDIR=/build/fbthriftpkg
cd /build
fpm --verbose -f -s dir -t rpm -n fbthrift -v $VER -C /build/fbthriftpkg \
usr/local/bin \
usr/local/include \
usr/local/lib

You should have an RPM that will install Thrift.

FINALLY!!! Build and Package McRouter!

Download

cd /build
git clone https://github.com/facebook/mcrouter

Build

cd /build/mcrouter/mcrouter
VER=$(git tag|tail -1)
autoreconf -ifv
export THRIFT2_COMP_DIR=/usr/lib/python2.7/site-packages/thrift_py-0.9.0-py2.7.egg/thrift_compiler
LDFLAGS=-L/usr/local/lib CPPFLAGS=-I/usr/local/include ./configure --prefix=/usr/local/mcrouter
make -j2
make install

Package

cd /build/mcrouter/mcrouter
mkdir /build/mcrouterpkg
make install DESTDIR=/build/mcrouterpkg
cd /build
fpm --verbose -f -s dir -t rpm -n mcrouter -v $VER -C /build/mcrouterpkg \
usr/local/mcrouter

You should have an RPM that will install mcrouter

Defining Your Portable Installation

The following RPMs from this tutorial are required to operate a mcrouter environment. Set them aside.

As of this writing, my specific RPMs and versions are:

  • gflags-2.1.1-6.el7.x86_64.rpm
  • glog-0.3.3-8.el7.x86_64.rpm
  • jemalloc-3.6.0-1.el7.x86_64.rpm
  • ragel-6.9-1.x86_64.rpm
  • double-conversion-v2.0.1-1.x86_64.rpm
  • folly-v0.57.0-1.x86_64.rpm
  • wangle-v0.9.0-1.x86_64.rpm
  • fbthrift-v0.31.0-1.x86_64.rpm
  • mcrouter-v0.9.0-1.x86_64.rpm

(Env 2) Setting up The Operating Environment

In order to run mcrouter on another node, you will need to install a the following system packages and packages you downloaded and created:

Install Packages

System Packages

yum -y install cyrus-sasl python-libs numactl-libs snappy boost libtool libevent openssl libatomic

Downloaded Packages

rpm -ivh gflags-2.1.1-6.el7.x86_64.rpm glog-0.3.3-8.el7.x86_64.rpm jemalloc-3.6.0-1.el7.x86_64.rpm

Built Packages

rpm -ivh ragel-6.9-1.x86_64.rpm double-conversion-v2.0.1-1.x86_64.rpm folly-v0.57.0-1.x86_64.rpm wangle-v0.9.0-1.x86_64.rpm fbthrift-v0.31.0-1.x86_64.rpm mcrouter-v0.9.0-1.x86_64.rpm

Test Mcrouter

/usr/local/mcrouter/bin/mcrouter --version

Done!

Did you find this post useful or have questions or comments? Please let me know!

The post HOWTO Build and Install Mcrouter for RHEL, OL, CENTOS 7.x first appeared on Brain Goo.

]]>
https://www.popmartian.com/tipsntricks/2016/04/26/howto-build-mcrouter-for-rhel-ol-centos-7-x/feed/ 5
HOWTO use PHP getallheaders() under FastCGI (PHP-FPM, nginx, etc.) https://www.popmartian.com/tipsntricks/2015/07/14/howto-use-php-getallheaders-under-fastcgi-php-fpm-nginx-etc/ https://www.popmartian.com/tipsntricks/2015/07/14/howto-use-php-getallheaders-under-fastcgi-php-fpm-nginx-etc/#comments Tue, 14 Jul 2015 20:23:21 +0000 http://www.popmartian.com/tipsntricks/?p=371 If you use Nginx, PHP-FPM or any other FastCGI method of running PHP you've probably noticed that the function getallheaders() does not exist. Continue reading →

The post HOWTO use PHP getallheaders() under FastCGI (PHP-FPM, nginx, etc.) first appeared on Brain Goo.

]]>
If you use Nginx, PHP-FPM or any other FastCGI method of running PHP you’ve probably noticed that the function getallheaders() does not exist. There are many creative workarounds in the wild, but PHP offers two very nice features to ease your pain.

First, PHP has an internal function called function_exists() which lets you see if a function is already declared.  With namespaces and objects this isn’t a very big deal so many people don’t know about this little function, but when a built-in function comes and goes, it can be a lifesaver.

Second, PHP lets you declare a function that has global scope if you are inside a function that has global scope.

If we put them together, we have a few lines we can include before we process any headers that will declare getallheaders() if it does not exist. If it does exist, nothing changes.

if (!function_exists('getallheaders')) {
    function getallheaders() {
    $headers = [];
    foreach ($_SERVER as $name => $value) {
        if (substr($name, 0, 5) == 'HTTP_') {
            $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
        }
    }
    return $headers;
    }
}

This idea was shamelessly lifted from the user contributed comments at http://php.net/manual/en/function.getallheaders.php. Thanks joyview at gmail dot com

Did you find this post useful or have questions or comments? Please let me know!

The post HOWTO use PHP getallheaders() under FastCGI (PHP-FPM, nginx, etc.) first appeared on Brain Goo.

]]>
https://www.popmartian.com/tipsntricks/2015/07/14/howto-use-php-getallheaders-under-fastcgi-php-fpm-nginx-etc/feed/ 4
HOW TO Lower Case All Dictionary Keys in a Complex Python Dictionary https://www.popmartian.com/tipsntricks/2014/11/20/how-to-lower-case-all-dictionary-keys-in-a-complex-python-dictionary/ https://www.popmartian.com/tipsntricks/2014/11/20/how-to-lower-case-all-dictionary-keys-in-a-complex-python-dictionary/#comments Thu, 20 Nov 2014 22:03:03 +0000 http://www.popmartian.com/tipsntricks/?p=345 This tutorial shows you how to write and use a function that will iterate over complex, nested dictionary or list or combination of the two. For any dictionaries it finds, it will rename the keys to lower-case. This is useful … Continue reading →

The post HOW TO Lower Case All Dictionary Keys in a Complex Python Dictionary first appeared on Brain Goo.

]]>
This tutorial shows you how to write and use a function that will iterate over complex, nested dictionary or list or combination of the two. For any dictionaries it finds, it will rename the keys to lower-case.

This is useful when trying to match an known string with a key name returned from another source where the characters are correct, but may come back in camelCase or in the wrong or just unknown case.

First: Write the function.
def renameKeys(iterable):
    if type(iterable) is dict:
        for key in iterable.keys():
            iterable[key.lower()] = iterable.pop(key)
            if type(iterable[key.lower()]) is dict or type(iterable[key.lower()]) is list:
                iterable[key.lower()] = renameKeys(iterable[key.lower()])
    elif type(iterable) is list:
        for item in iterable:
            item = renameKeys(item)
    return iterable

Next, create some sort of test list:
somelist = [
  {
  'myKey': 'asdA',
  'ASDFASDurKey':
    [
      {'QDD' : 'booger'},
      'asdf',
      [1,2]
    ]
  }
]

Finally call it:
somelist = renameKeys(somelist)

CAUTION: If your dictionary has two elements with the same ascii characters in two separate cases such as mydict[‘key1’] and mydict[‘KEY1’], the function works on a last-match basis. That means whichever dictionary element gets renamed last wins.

Did you find this post useful or have questions or comments? Please let me know!

The post HOW TO Lower Case All Dictionary Keys in a Complex Python Dictionary first appeared on Brain Goo.

]]>
https://www.popmartian.com/tipsntricks/2014/11/20/how-to-lower-case-all-dictionary-keys-in-a-complex-python-dictionary/feed/ 1
HOW TO Build non-root FreeTDS for Linux https://www.popmartian.com/tipsntricks/2014/10/20/how-to-build-non-root-freetds-for-linux/ Mon, 20 Oct 2014 13:11:12 +0000 http://www.popmartian.com/tipsntricks/?p=333 This tutorial shows you how to build FreeTDS on any Linux (and probably Unix) system in a stand-alone fashion. No root or packages required. Prerequisites: You do need a compiler and functional build environment. If you can successfully ./configure && … Continue reading →

The post HOW TO Build non-root FreeTDS for Linux first appeared on Brain Goo.

]]>
This tutorial shows you how to build FreeTDS on any Linux (and probably Unix) system in a stand-alone fashion. No root or packages required.

Prerequisites:
You do need a compiler and functional build environment. If you can successfully ./configure && make && make install then you are all set.

Step 1: Get the software
Download the latest stable release from freetds.org

Step 2: Unpack
Unpack the software in to a directory different from the install directory.

In this example, I’m using /appserver/freetdsbuild/, but I will install in to /appserver/freetds-0.91/

mkdir /appserver/freetdsbuild/
cp freetds-stable.tgz /appserver/freetdsbuild/
cd /appserver/freetdsbuild/
gunzip freetds-stable.tgz
tar xf freetds-stable.tar
cd freetds-0.91

Step 3: Compile
Here we are going to configure it to install in to an alternate directory

./configure --prefix=/appserver/freetds-0.91 --exec-prefix=/appserver/freetds-0.91/ --enable-msdblib
make
make install

At this point it is safe to remove /appserver/freetdsbuild/ if you don’t need it.

Step 4: Make the symlink
The final stop is to make a symlink from /appserver/freetds-0.91 to /appserver/freetds. This lets you point your application to the freetds directory. If you need to modify to upgrade FreeTDS, you can build a new version and simply move the symlink. Your application won’t need to change.

ln -s /appserver/freetds-0.91/ /appserver/freetds/

Done!

P.S. You can find your config files in /appserver/freetds/etc/

Did you find this post useful or have questions or comments? Please let me know!

The post HOW TO Build non-root FreeTDS for Linux first appeared on Brain Goo.

]]>
HOW TO Install mcrypt for PHP on RedHat Linux 6 and Oracle Linux 6 https://www.popmartian.com/tipsntricks/2014/06/04/how-to-install-mcrypt-for-php-and-redhat-linux-6-or-oracle-linux-6/ https://www.popmartian.com/tipsntricks/2014/06/04/how-to-install-mcrypt-for-php-and-redhat-linux-6-or-oracle-linux-6/#comments Wed, 04 Jun 2014 15:05:42 +0000 http://www.popmartian.com/tipsntricks/?p=317 This tutorial shows you how to install libmcrypt and the companion PHP module under RedHat Linux 6 and Oracle Linux 6. By default, RHEL and OL do not provide mcrypt or libmcrypt packages for the 6.x release. Subsequently, they don’t … Continue reading →

The post HOW TO Install mcrypt for PHP on RedHat Linux 6 and Oracle Linux 6 first appeared on Brain Goo.

]]>
This tutorial shows you how to install libmcrypt and the companion PHP module under RedHat Linux 6 and Oracle Linux 6.

By default, RHEL and OL do not provide mcrypt or libmcrypt packages for the 6.x release. Subsequently, they don’t provide PHP5 mcrypt modules either. Many PHP apps including PHPMyAdmin and Magento make use of the better crypto support of libmcrypt.

So how do you install it? You have to build it.

Part 1: Building libmcrypt

Part 1, Step 1: Install your build environment
libmcrypt is written in C++ so you need a C++ compiler.
sudo yum install gcc-c++.x86_64
That will install the compiler and dependencies.

Part 1, Step 2: Get the software
Download it here: http://sourceforge.net/projects/mcrypt/files/
Remember, download libmcrypt, not mcrypt.

Part 1, Step 3: Pick a location and unpack it
Most people install software in to the default location, but I’m going to install in to somewhere that isn’t owned by root just to illustrate how to separate your custom app components from the OS.
mkdir /myappserver
cd /myappserver
cp /path/to/download/libmcrypt-2.5.8.tar.bz2 /myappserver/
bunzip2 libmcrypt-2.5.8.tar.bz2
tar xf libmcrypt-2.5.8.tar
mv libmcrypt-2.5.8 libmcrypt-install

Part 1, Step 4: Build it!
cd libmcrypt-install
./configure --prefix=/myappserver/libmcrypt-2.5.8 --exec-prefix=/myappserver/libmcrypt-2.5.8 --disable-posix-threads
make
make install

Part 1, Step 4: Make a Symlink
In order to make life easier for upgrades later, symlink libmcrypt to the version you built. This will let you compile a new version later and simply move the symlink. Anything else you build against this package will only need to know about the symlink.
ln -s /myappserver/libmcrypt-2.5.8/ /myappserver/libmcrypt

You have successfully installed libmcrypt. You can move it from server to server by simply copying /myappserver/libmcrypt-2.5.8/ to any other machine.

Part 2: Building the PHP Module
Building the PHP module can be done in one of two ways.

  1. Build your own PHP and copy the module to an existing PHP installation
  2. Build your own PHP and use it

I’m not going to do a full tutorial on building PHP here (Option 2). Just note that the steps are the same as Option 1, but instead of copying the extention in to your PHP installation, compile PHP with all the modules you need, then install and use the PHP you built.

Option 1: Build your own PHP and copy the module to an existing PHP installation

Part 2, Option 1, Step 1: Install your build environment
PHP is written in C so you need a C compiler.
sudo yum install gcc.x86_64
That should give you everything you need to compile PHP.

Part 2, Option 1, Step 2: Get the software
MAKE SURE YOU DOWNLOAD THE PHP VERSION THAT MATCHES YOUR INSTALLATION
Download it here: http://us3.php.net/downloads.php

For this tutorial, I used PHP 5.5.13

Part 2, Option 1, Step 3: Pick a location and unpack it
I’m going to use a non-standard location since I’m just building the software. I’m not going to use it from here.
mkdir /myappserver
cd /myappserver
cp /path/to/download/php-5.5.13.tar.bz2 /myappserver/
bunzip2 php-5.5.13.tar.bz2
tar xf php-5.5.13.tar
cd php-5.5.13

Part 2, Option 1, Step 4: Build it!
./configure --prefix=/myappserver/php-5.5.13 --exec-prefix=/myappserver/php-5.5.13 --with-mcrypt=/myappserver/libmcrypt
make

Note the --with-mcrypt=/myappserver/libmcrypt option. This points to the symlink above. If you need to upgrade libmcrypt later or rebuild the module for any reason, you don’t need to worry about what version of libmcrypt you have, just use the symlink!

You should now be able to find your module in /myappserver/php-5.5.13/ext/mcrypt

Part 2, Option 1, Step 5: Use it!

  • Copy the mcrypt directory above in to the ext directory in your PHP installation.
  • Restart your Apache server

Test it with a little PHP code:
<?php
extension_loaded('mcrypt') ? print 'Mcrypt is working' : print 'Mcrypt is not working';
?>

Did you find this post useful or have questions or comments? Please let me know!

The post HOW TO Install mcrypt for PHP on RedHat Linux 6 and Oracle Linux 6 first appeared on Brain Goo.

]]>
https://www.popmartian.com/tipsntricks/2014/06/04/how-to-install-mcrypt-for-php-and-redhat-linux-6-or-oracle-linux-6/feed/ 1
HOW TO Flush The Linux File Cache https://www.popmartian.com/tipsntricks/2014/05/19/how-to-flush-the-linux-file-cache/ Mon, 19 May 2014 16:44:52 +0000 http://www.popmartian.com/tipsntricks/?p=313 You can’t prevent Linux from using the file cache and you don’t want to. However, on occasion you may want to flush it. Here’s how: First, flush your filesystems to disk. Just run the command sync Then, echo 1, 2 … Continue reading →

The post HOW TO Flush The Linux File Cache first appeared on Brain Goo.

]]>
You can’t prevent Linux from using the file cache and you don’t want to. However, on occasion you may want to flush it. Here’s how:

First, flush your filesystems to disk. Just run the command sync

Then, echo 1, 2 or 3 in to /proc/sys/vm/drop_caches. It breaks down like this:

  1. free pagecache: echo 1 > /proc/sys/vm/drop_caches
  2. free dentries and inodes: echo 2 > /proc/sys/vm/drop_caches
  3. free pagecache, dentries and inodes: echo 3 > /proc/sys/vm/drop_caches

Did you find this post useful or have questions or comments? Please let me know!

The post HOW TO Flush The Linux File Cache first appeared on Brain Goo.

]]>
HOW TO Extract the contents of a .scexe file https://www.popmartian.com/tipsntricks/2014/01/17/how-to-extract-the-contents-of-a-scexe-file/ https://www.popmartian.com/tipsntricks/2014/01/17/how-to-extract-the-contents-of-a-scexe-file/#comments Fri, 17 Jan 2014 21:18:31 +0000 http://www.popmartian.com/tipsntricks/?p=307 HP Releases self-extracting firmware update files for Linux as .scexe files. These files usually contain an installer and a bunch of XML controlls. A -h flag provides a couple options for running the installer, but sometimes you don’t want to … Continue reading →

The post HOW TO Extract the contents of a .scexe file first appeared on Brain Goo.

]]>
HP Releases self-extracting firmware update files for Linux as .scexe files. These files usually contain an installer and a bunch of XML controlls. A -h flag provides a couple options for running the installer, but sometimes you don’t want to run it, you want to get at the contents.

.scexe files contain a hidden --unpack flag that will unpack the contents to the directory of your choosing.

For example:

# ./SOMEFILE.scexe --unpack=/tmp/test/
SOMEFILE.xml
SOMEFILE-PayLoad-version.version.version-1.zip
something.txt
installer
readme.txt
reference.xml

Did you find this post useful or have questions or comments? Please let me know!

The post HOW TO Extract the contents of a .scexe file first appeared on Brain Goo.

]]>
https://www.popmartian.com/tipsntricks/2014/01/17/how-to-extract-the-contents-of-a-scexe-file/feed/ 5
HOW TO Use Multiple Filter Flags in PHP Filter Functions https://www.popmartian.com/tipsntricks/2014/01/09/how-to-use-multiple-filter-flags-in-php-filter-functions/ https://www.popmartian.com/tipsntricks/2014/01/09/how-to-use-multiple-filter-flags-in-php-filter-functions/#comments Thu, 09 Jan 2014 17:17:49 +0000 http://www.popmartian.com/tipsntricks/?p=301 Using multiple filter flags in PHP is easy, but the documentation does not explain it well. The Filter capabilities in PHP 5.3 and above are very powerful and save a ton of effort, but the passing of flags to various … Continue reading →

The post HOW TO Use Multiple Filter Flags in PHP Filter Functions first appeared on Brain Goo.

]]>
Using multiple filter flags in PHP is easy, but the documentation does not explain it well.

The Filter capabilities in PHP 5.3 and above are very powerful and save a ton of effort, but the passing of flags to various filter functions is described minimally as a “bitwise disjunction of flags”. This means you need to pass a bitwise conjunction of flags.

Here’s the english translation:
Pass a pipe-separated list of flags.

That’s it. You need to use the logical ‘OR’ to create a parameter the parser will understand.

If you want to use filter_var() to sanitize $string with FILTER_SANITIZE_STRING and pass in FILTER_FLAG_STRIP_HIGH and FILTER_FLAG_STRIP_LOW, just call it like this:

$string = filter_var($string, FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES | FILTER_FLAG_STRIP_HIGH | FILTER_FLAG_STRIP_LOW);

That’s it. Nothing magical.

The same goes for passing a flags field in an options array in the case of using callbacks. Here is an extended version of the example from php.net:

$var = filter_var($string, FILTER_SANITIZE_SPECIAL_CHARS,
array('flags' => FILTER_FLAG_STRIP_LOW | FILTER_FLAG_ENCODE_HIGH));

Did you find this post useful or have questions or comments? Please let me know!

The post HOW TO Use Multiple Filter Flags in PHP Filter Functions first appeared on Brain Goo.

]]>
https://www.popmartian.com/tipsntricks/2014/01/09/how-to-use-multiple-filter-flags-in-php-filter-functions/feed/ 2
HOWTO: Create a random alpha-numeric string in PHP https://www.popmartian.com/tipsntricks/2014/01/02/howto-create-a-random-alpha-numeric-string-in-php/ Thu, 02 Jan 2014 16:21:16 +0000 http://www.popmartian.com/tipsntricks/?p=284 Creating an alpha-numeric string in PHP is easy, but having a quick function you can call is better! This is very useful for things like password generators. To see how to do this in Python, check out this post: …howto-create-a-random-alpha-numeric-string-in-python … Continue reading →

The post HOWTO: Create a random alpha-numeric string in PHP first appeared on Brain Goo.

]]>
Creating an alpha-numeric string in PHP is easy, but having a quick function you can call is better!

This is very useful for things like password generators.

To see how to do this in Python, check out this post: …howto-create-a-random-alpha-numeric-string-in-python

To see how to do this in Perl check out this post: …howto-create-a-random-alpha-numeric-string-in-perl


<?php
function makeID($size = 6) {
    global $makeIDpool;
    $makeIDpool = array_merge(range(0,9), range('a','z'), range('A','Z'));
    $append = function ($value){ global $makeIDpool; return $makeIDpool[rand(0,count($makeIDpool) - 1)]; };
    return implode('', array_map($append, range(0,$size - 1)));
}
?>

Example:

This code sample:


print makeID().'<br />';
print makeID(10).'<br />';
print makeID(20).'<br />';
print makeID(1).'<br />';

Will print something like this:

KNHtkn
2z8ksLDSkp
bfn5X5jF5dTZ3itt9HWy
q

Did you find this post useful or have questions or comments? Please let me know!

The post HOWTO: Create a random alpha-numeric string in PHP first appeared on Brain Goo.

]]>
HOWTO: Create a random alpha-numeric string in Perl https://www.popmartian.com/tipsntricks/2013/12/27/howto-create-a-random-alpha-numeric-string-in-perl/ Fri, 27 Dec 2013 17:38:44 +0000 http://www.popmartian.com/tipsntricks/?p=273 Creating an alpha-numeric string in Perl is easy, but having a quick function you can call is better! This is very useful for things like password generators. To see how to do this in Python, check out this post: …howto-create-a-random-alpha-numeric-string-in-python … Continue reading →

The post HOWTO: Create a random alpha-numeric string in Perl first appeared on Brain Goo.

]]>
Creating an alpha-numeric string in Perl is easy, but having a quick function you can call is better!

This is very useful for things like password generators.

To see how to do this in Python, check out this post: …howto-create-a-random-alpha-numeric-string-in-python

To see how to do this in PHP, check out this post: …howto-create-a-random-alpha-numeric-string-in-php


sub makeID {
    my $makeIDchars = ( $#_ >= 0 ? shift @_ : 6);
    my @makeIDpool = ('a'..'z','A'..'Z',0..9);
    return join '', map $makeIDpool[int(rand($#makeIDpool - 1))], 1..$makeIDchars;
}

Example:

This code sample:

print makeID()."\n";
print makeID(10)."\n";
print makeID(20)."\n";
print makeID(1)."\n";

Will print something like this:

QLNbMX
1wO6uBRbER
bjbYBJSMLONKOPU0SiQS
p

Did you find this post useful or have questions or comments? Please let me know!

The post HOWTO: Create a random alpha-numeric string in Perl first appeared on Brain Goo.

]]>