Been writing more PHP code lately, coming from a Java background, I like having getters/setters despite PHP typically just using public variables. A while back, I found this site that helps to generate code, but it was lacking in some features; especially when I preferred the pascal/camel case on my functions when the variables were named in snakecase.

Quick background:
snakecase – words in a variable are separated by _ (e.g. my_variable)
camelcase – words are alternated by capitalized letters (e.g. myVariable)
pascalcase – similar to camel, but the first letter is capitalized also (e.g. MyVariable)
kebabcase – words are separated by – (e.g. my-variable)

The drawbacks of the previous solution: Michael Angstadt, would take private/protected variables, regardless of what type of naming convention and use a simple implementation that would just add the get/set in front of that variable to create the function.

What I wanted was to be able to transform snakecase (this is typically used in python, some api’s also seem to prefer it) to pascal case on the function names so that I wouldnt have to manually go in and change it. Also many times, I like having a constructor, which is tedious depending on how many variables are in the model. Also when outputting to excel, it’s nice to have a toArray function.

Unfortunately, it’s not a 100% code generation because PHP doesn’t really do type hinting, there is no way to really know if the variable is supposed to be a string or number or array – but most of the time, strings are good enough, so this generator outputs assuming that the variable is a string, which still requires some manual modifications, but it will handle 80% of the work.

Perhaps later in the future, I could build something to account for the different types. Other possible additions might be to generate a function to translate json into the model class.

Check it out here!
https://php.gregtam.com/

Lately I’ve been noticing that my WordPress has been getting hacked constantly (this site is run on WP). Even if I update it, there seems to be some backdoor that gets executed every month.

So recently I took a few extra moments to take a look at these attacks. On the surface these attacks are not sophisticated, they mostly target un-updated WP installations and install malicious payloads that has a signature similar to:
eval(base64decode(123413j234lk1j23adfa ...

Originally i started to write some scripts to remove signatures like this, but it seemed easier to re-use other’s code. I recently stumbled upon this:
Exploit Scanner
basically what this plugin does is it matches the current install with the vanilla version of WordPress and tells you if there are any differences – a very good way to detect modification of php code.

the hashes exist here:
Hashes

The other thing i do is that I track all my wordpress installs with git
everytime I install a plugin / update WordPress – i update my git with a commit, so if any of the WordPress installs get attacked, I can run:
git reset --hard HEAD to revert any changes made to the files and at the very least put me on a good baseline for cleanup

1&1 actually does some nice security scanning now. They detect attacks and then automatically lock the file so that it cant be executed on the web. In order to fix this – i usually do a:
chmod -R 777 * on the WordPress directory so git will have the right permissions to remove/delete files

Gatekeeper

there are times when your organization/company locks down your computer and you have to install software. Here is how to gain access to install software.

Obviously you will need to have root access. Most of the time, if you are configured as an administrator on the Mac, you will be able to gain root.

1. Open up Terminal
2. Run this command $ sudo spctl –master-disable

spctl is the Mac’s SecAssessment System Policy Security.

What we are doing is Disabling the assessment subsystem altogether. Operations that would be denied by system policy will be allowed to proceed; assessment APIs always report success. Requires root access.

see:

Lately I’ve been trying to run some load scripts that basically take data from mySQL and convert them to a Redis Luke Protocol. Part of the reason why I wrote it in Java was because the cached object needed to be Java serialized.

I ran into some issues while running some tests. It seems that my Eclipse memory heap was not big enough. Here are steps to increasing it.

1. Open Eclipse
2. Eclipse > Preferences > Java > Installed JREs

installedJre

3. Select the current JRE
4. Select “Edit”
5. Modify the default JVM properties to something like:
-Xms512M -Xmx1024M

editJre

When attempting to use php micro frameworks on 1and1, the key is having the correct .htaccess file

if should look like this:
Options +FollowSymLinks -MultiViews

AddType x-mapp-php6 .php
AddHandler x-mapp-php6 .php

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]