The Dev Pages

A knowledge base for simple (and beyond) web applications development

Archive for the ‘General Dev’ Category

how and why software development


Posted on March - 21 - 2017



I was thinking I should create some re-usable language. Like a good software engineer. The topic of software development comes up somewhat frequently with people. This happens naturally as a consequence of explaining what I’m up to at any given time, but also because people wonder how the hell I’ve managed to continually find a job when I’ve been forced to work for money. (ha)

As I’ve hinted at, it has been a love-hate relationship. In a nutshell I love the flexibility it has given me and the constant intellectual challenge and the opportunity for creativity and self-autonomy. But I often struggle with the challenge of being at a screen so long without human interaction. But good projects and associates are collaborative and I have learned a ton from some amazing people. All in all I’d consider my career path lucky. I hope it continues to be that way as I go in different directions.

My ultimate advice is that anyone should try coding. If you like it for the sake of coding, stick with it. It’s like a switch within. It’s a crossroads that comes about relatively quickly. If it’s a legitimately miserable experience and you can avoid being a technical prostitute, then move on to something less soul-sucking. There are many redeeming  jobs and characteristics that may be a direct result of someone not being a good coder.

How to to figure out if the switch will click is harder to say. I’m not sure exactly how or when it happened for me. Here’s my best guess: find something legitimate to figure out. After getting something like that successfully setup, evaluate the suffering you’ve experienced. Did you enjoy that suffering? If it was like a good workout or a painful massage or a worthwhile hard read, something somewhat masochistic but ultimately enjoyable, then you may be ok. If it was like watching CNN or reading a lot of opinion-based facebook posts or calling a cable/satellite provider or waiting to take photographs, something harrowing, then move on.

It’s really not about understanding the weird syntax of code. But you do need to be figuring out what some of that language and structure is achieving at some early point. Getting something working is the first step and then caring enough about understanding HOW it’s done so you can effectively re-create something similar is also very important. So maybe one needs to try something out, and then do a variation on it while forcing yourself to understand how to accomplish that variation from the principles you learned in the first task.

I would say a good place to start is to figure out how to buy a domain, setup web hosting, and get an html page loaded with some decent styling and an image carousel loaded using a javascript library like jQuery. Setting up a blog doesn’t count.

Another one might be getting a web page to show some ugly-ass text but to generate the text from a database. Or from your favorite playlist from your spotify or last.fm account using an API data source.

Another one might be getting a native mobile app setup and on a test environment on your actual phone and have it have a menu with legitimate options that loads a placeholder view.

If you like the problem solving aspect or if you like to work on your own on technical things you may be suited. The best and the brightest are also good collaborators, but there’s a personality aspect to it.

You will be using w3schools.com, stackoverflow.com, and google.com a ton to get started. And once you figure some stuff out, look into finding a project at work where you can apply code if at all possible. Or save up money or get someone who really loves you to fund code academy classes or a start or return to a university. I’m skeptical about most for-profit institutions.

Here’s a tale of two friends. Both tried coding. One took a class in college and the other came back to it after school and did a code academy. The one who took the college class never got to enjoy it and the switch never clicked. I’ve met plenty of people who tried code academies to the same end. The difference for the other friend was that they just somehow enjoyed it and desired it and got to the point where stuff started clicking. It’s always been the same way with so many people I’ve met. Either they’ve naturally had a fierce desire and possibly a natural aptitude, or they’ve taken a crack and never really had anything click. There’s just some fierce dichotomy that exists out there. I’m still trying to figure it out. Maybe it’s something as simple as being willing to google and pound your head against the wall to get a semi-colon in the right place and finally understand how something works to great satisfaction. Who knows? But figuring out if you can flip the coding switch is something I would recommend to anyone who is at all curious.

Here’s my roots:

  1. At the age of 10 I hammered on a old-school IBM until I figured out how to draw lines in a DOS operating system based program called Harvard Graphics.
  2. At the age of 12 I learned how to boot into the DOS operating system so I could load a computer game from a floppy disk, Joust VGA, of a disk and play it on my own
  3. At the age of 14 I learned how to use text commands to navigate BBS (Bulletin Board Service) portals, which were like a dial-up text based website you could navigate from the command line or a command-line like tool for BBS-ing. I wanted to download music. I still remember illegally downloading my first song, Cream’s White Room. (1)
  4. At the age of 17 I took a C++ class in high school and had fun with it.
  5. When I was 18 in college my Object-Oriented Computer Science class in Java seemed like cake after learning some C++. I think this was when I realized the switch had clicked.
  6. When I was 22 I learned to build html documents and use javascript.
  7. When I was 23 I convinced one of the world’s greatest bosses to let me learn Coldfusion, a server side language like php or python (well, a little bit weirder). I stayed up for a couple nights late, and I came back for a second interview proving I could query data from a database using the stuff and since then I’ve always had jobs in development, learning things as I went from my Information Systems program to some extent, but largely from the jobs I’ve had and opportunities to learn new technologies.

I don’t know what any of that proves. I think a common theme is giving a shit about mysterious details and figuring them out to achieve something interesting. As I’ve gotten older and money became involved I didn’t necessarily need the gratification of a childish drawing (though that is the end product of some recent projects) or a video game or a song. But I still really enjoy knowing how technical stuff works, to the point of knowing some stuff about fixing my car and creating music with an instrument and understanding how areas of finance and law and other dense subjects work. So maybe a part of it is being a hedonistic control freak. I think those character traits can be very rewarding.

Footnotes
1 – TODO:NW middle school aol password phishers and sketchy affiliates and the woes of not figuring out internet browser temporary file storage fast enough.
2 – My crazy career path at linked in: https://www.linkedin.com/in/nate-williams-aaba3735/

… The job stuff (TODO:NW move to another post)

Finally, there’s a point where you actually have to get started with a money-making gig. Once you get your first one, you may very well be set forever.

<from a recent email, probably not entirely useful>

1 – Go to ‘meet ups’, I know in other cities they are huge. SLC has a smaller scene, but people seem to think they are useful. I’ve almost gone to a couple and have been meaning to go. My server side language, php, isn’t as big, but the javascript I do (angular 2 and react), some mobile stuff, and server admin/dev ops have some interesting groups. Some guys I worked with last summer were into them, and said recruiters and people hiring will stick around after to look for people and often sponsor the meet ups. There are some javascript, angular 2, and react groups that could be good.
2 – Go nuts with responding to craigslist, ksl, indeed.com and other job boards. While I lived in Austin last spring, I found a job post on a U of U job posting board for ‘data research’. It turned into me doing scripting (great for learning python) and doing a ton of work on an angular JS app when I got back to Utah. It was such a fun project. We worked for the Weinholtz campaign, and visualized voting data for Utah.
With hitting up postings it never hurts to have people look over your resume and form cover letters. To a certain degree, getting that first job will include having a resume where nothing is all that impressive for the industry. But wording and layout and how you paint past experience counts for something. With coding in particular, being a fast learner is huge.
3 – Take a job in something else, and as part of the deal offer to work for free/get training on a dev project. I had a campus job where we hired QA and copy writer people and let them do html and JS and get the experience and title for their resume and go other places. Unfortunately this is somewhat rare involves finding a good employer.

 

Using php with Angular 2 and Laravel


Posted on August - 11 - 2016



I’ve been using Angular 1.0 for the last few projects, but I wanted to get familiar with Angular 2. I found the process of getting up and running with php a bit annoying.

SUMMARY: With php, you can use the ‘5 Minute Quickstart’ tutorial google offers with some adjustments to asset locations, config paths, node packages, and automated tasks (most notably the typescript transpilation process) to get setup with Laravel and Angular 2. Google uses a node app, and a lite node server. I wanted to avoid this and use php and laravel to deploy assets, etc. and use Angular 2. Conceptually:

  1. Make sure you understand which packages you will need. The best would be just to copy the ones from the Angular 2 google tutorial, though not quite all of them will be used (we will let Laravel handle the typescript transpilation).
  2. Make sure you understand where the hell all the files should go. You need to change google’s root level file structure of the example node app to a php laravel app where public assets reside in the nested ‘public’ folder within the root app. Paths in the files need to be adjusted accordingly.
  3. Make sure you understand how to adjust the automated tasks in the gulp file, and in the laravel-elixir-typescript node package. This is mainly about how to get your typescript files to end up in the right place when they are compiled to javascript.

See https://angular.io/docs/ts/latest/quickstart.html

I’ve tried to explain my experience in a way that will make things easier for someone trying to setup any general php app with angular 2 at any point in the near future. The packages, versions, and syntax of the code may vary in the future, but if you understand what changes you need to make conceptually, it will hopefully be easy to use Google’s tutorials and documentation for the next while. My experience was based on the somewhat murky guide at https://www.codetutorial.io/laravel-5-and-angular-2-beta-setup. The video is at https://www.youtube.com/watch?v=dohhsLSbkYA. I found I needed some clarifications on paths, etc. and that the packages used and versions were outdated or unexplained. I tweaked the tutorial found at https://angular.io/docs/ts/latest/quickstart.html. I was using Laravel 5.2.43. I’ve tried to follow the steps in the google tutorial.

Step 1: Create and configure the Laravel and Angular 2 project

I took a laravel project and figured out where to put all the files from the google Angular 2 tutorial. Some files from the tutorial could just go in the root of the app. The following things need to be adjusted:

a) Create a laravel project, and change into that directory. Mine is called laravel_angular2.

laravel new laravel_angular2
cd laravel_angular2

I’ve gotten used to setting up a virtual host and getting the app and and running with php and apache. Hopefully you’ve already made it to this point.

b) Package definition and config files. Copy the typings.json file into the root of your project. Ignore the tsconfig.json file, as we will use laravel an gulp to handle typescript transpiling and serving the app. Put the systemjs.config.js file in the /public folder of laravel. UPDATE THE PATHS in this file to point to / instead of /node_modules, your public folder. The package.json file needs to be merged with existing laravel one. You can essentially copy the dependencies and devDependencies portions of the tutorial package.json file into the package.json file in the root of your laravel app. You can tweak the packages, perhaps remove the lite server and typescript stuff that google includes. As for me, I just left all the packages google indicated in there. I have yet to figure out a good way to determine, when cloning projects, how the hell to figure out which packages are unnecessary, and how to tell which should just go in the devDependencies section when the list gets real long and full of unfamiliar packages. The scripts and other sections of the tutorial package.json can be ignored since, again, we will use laravel an gulp to handle typescript transpiling and serving the app.

c) Install packages. npm install should work fine. Somehow I always screw the packages up and get error messages, but nothing helpful on how to avoid this comes to mind. Hopefully you only get some warnings. I could not get npm run typings install to work, as per the tutorial. I don’t know if this is because we removed it from the scripts section of the package.json file. You can try adding this section and run the command. I suspect it had more to do with the fact that the console wanted a cli package for typings. Do npm install typings --global to get the global cli package, then typings install. We need to deal with the typings folder and move it into public. I didn’t get errors in my quickstart app without moving the typings folder, but it should be moved to the public folder. So, move the ‘typings’ folder into /public. You could probably use a gulp task command to do this. You could also figure out how the hell to adjust google’s code to put this typings folder in public automatically. I never got to that point. The typings.json config file made no sense to me and I don’t know any of the conventions on using that package. I actually don’t even know what the typings folder is used for, but figured it should go in the public folder.

Ignore the ‘Helpful scripts’ section, as we will use laravel and gulp to run the typescript transpiling and the server.

Steps 2-4: Our first Angular 2 component, etc.

Instead of creating an ‘app’ root folder, make a folder ‘/resources/assets/typescript/app’ to house your typescript files. They will be transpiled to the /public/app folder later. Put all the files mentioned in the tutorial in steps 2-4 there.

Step 5.0: Making sure our Angular 2 typescript transpiles using Laravel and Gulp

I couldn’t get google’s typescript transpiler to work easily, and I wanted to use the one included in the laravel packages. The tricky part about this is to avoid jamming on the javascript into a single app.js file. There are 2 ways I’ve done this. The second way is demonstrated in the tutorial on codetutorial.io (and the youtube video), but it involves modifying a node package in the node_modules folder, which is fragile. In my opinion.

  1. Use the gulp typescript library and make a task for transpiling the javascript from typescript.

    • This is the weird custom step I found useful. It deals with getting the transpiling to work using the npm package elixir-typescript. This involves tweaking the package code, and will not be committed to the git app as it involves editing the node_modules folder. I don’t know if there is a better way to do this, but this idea comes from the aforementioned tutorial. Add the elixir-transcript package. Version 1.1.2: npm install elixir-typescript@1.1.2 I haven’t added this to the package.json file, as we are editing the package manually, but you could add it. Be aware that on certain npm actions, the required update that makes our transpiling work may be overwritten and break.
    • In the file /node_modules/elixir-typescript/index.js, comment out the concat line. //.pipe(concat(outputFileName)). This was on line 28 for me. This is so that when the typescript files are transpiled, they don’t all get mashed into one app.js file. Angular 2 would not like this. Every time you do npm install, you may have to redo this!
    • add the following to your gulp file. The first line was already there for me:


      Run gulp typescript to make sure it works. There should now be javascript files in /public/app. The paths here are weird and took me some tinkering to figure out. More on this later. These 3 steps were definitely the trickiest part of the whole process. It’s more about if you’re keen on learning how to use typescript with your php projects, as similar steps would probably need to be used in any tool that uses typescript on the frontend.

Step 5

Setup the welcome/index/homepage of your Laravel app to load the Angular 2 app. Instead of making an index.html as per the tutorial, update your home view, or whatever you want to run the angular 2 app, to use the html that is in the tutorial. We will need to modify the url paths since the packages used by Angular 2 reside in node_modules folder, which is not in /public. We also need to copy the used packages into the /public folder so we can reference them from the script tags. We will accomplish this by:

  1. Input the html, etc. from the tutorial. In my /resources/views/welcome.blade.php file I added Loading... in the content div. Copy the script tags from the tutorial into the head section.
  2. Add the following commands to the Laravel gulp file in the elixir function:


    The following 3 files are also necessary for the framework.
  3. Remove references to node_modules from the script includes in your view file. For example, ‘node_modules/core-js’ should just be ‘core-js’. I edited my /resources/views/welcome.blade.php and removed all the ‘node_modules’ from the script tags. The systemjs.config.js file should already be in the public folder from Step 1. Again, note that you should remove reference to the ‘node_modules’ path in this systemjs.config.js.And with that, run gulp, hit your Laravel app’s url,and the quickstart app should load! You’ll probably want to add a gulp task to monitor changes to your typescript. And this is usually the point in a web post where I’m like ‘What the hell, this isn’t working and you seem to be missing some explanations.’ As I think of them, I’ll try and stay current and add in more explanations and pitfalls to avoid this.



Summary: What you want is to set up a null client. http://www.postfix.org/faq.html#null_client See my notes below for what constitutes an ’smtp server entry’.

So for my local dev environments I’ve been in the habit of setting up php’s mail function to work by doing a ’sudo apt-get install sendmail’ and editing the php.ini to point the sendmail_path to /usr/sbin/sendmail. (I’d recommend this procedure only if you’re working locally and don’t plan on opening port 25 to anything public, won’t want to mess with domain names, and won’t be dealing with mx records, etc.).

Well when I actually had to setup a server with a public domain, and needed emails to work efficiently from php with a qualified domain while worrying about port 25 being secure, I was in for some fun. For starters I’d recommend postfix over sendmail. Much easier to configure. Sendmail has many more config files, and you have to re-compile some of them after edits, etc. So once you have postfix installed, if you just want to send outgoing emails, then you can increase security and reduce overhead by making postfix not listen on the SMTP port. I wanted postfix as an smtp client only. With sendmail you can do this, and even kill all the daemons. With postfix you still need the daemon going, but when we’re done, nothing will be listening on port 25, smtp.

So what we are setting up is called a ‘null client’. You just have to modify /etc/postfix/main.cf and master/cf according to the instructions at http://www.postfix.org/faq.html#null_client.

The main thing that was unclear to me is what line(s) constitute a ‘SMTP server entry’ in master.cf. After commenting out the line close to the top with ’service’ as ’smtp’ and ‘type’ as ‘inet’, I figured this was enough, as ’sudo lsof -i’ indicated nothing was listening on port 25, or as smtp. I would leave the other smtp service entries alone, the ones with ‘type’ as ‘unix’.

Then do ’sudo postfix reload’ and for good measure we may as well do ’sudo /etc/init.d/postfix restart’, or the equivalent on your linux distro.

PHP and MySQL setup on Mac OS X 10.5 Leopard


Posted on September - 10 - 2009



Full fledged open-source MAMP development environment with php, mysql, and apache on Mac OS X 10.5 Leopard

Goal: A complete php development environment using Mac OS X 10.5 Leopard’s out of the box apache2/php install, and an install of the latest mysql and eclipse software with all the necessary plugins for php debugging. ALL 64-BIT!

Admittedly, it was a challenge to get a fully functioning php dev environment up based on Mac OS X 10.5 Leopard’s configuration. But I succeeded in not installing a separate apache/php 32-bit install, or bailing out to use a linux Virtual Box.

Enabling PHP

PHP5

This one was pretty easy. Just uncomment out the line

#LoadModule php5_module        libexec/apache2/libphp5.so

in the httpd.conf apache config (/etc/apache2/httpd.conf) so it includes the php5 module that comes with the OS.

Make sure your extension_dir in php.ini points to /usr/lib/php5/extensions/no-debug-non-zts-20060613/ or go nuts and do your own extension directory.

Debugging 64-bit

This was one of the trickier things. You need to get an X-Debug extension setup. Hopefully you can just use my 64-bit extension file, and put that in your extensions directory (/usr/lib/php5/extensions/no-debug-non-zts-20060613/). Then add the zend_extension directive to the php.ini, along with the X-Debug settings, pointing to your (local or remote) host. In your php.ini:

xbedug.so (specific to 64-bit Mac OS X)

If that short version doesn’t work, you need to compile a 64-bit extension from the xdebug source, which was sort of tricky. You’ll need to get a compiler installed on your Mac OS if you haven’t got the right developer tools installed (XCode from the install disk or mac;s website), and then follow the instructions in this article.

http://www.vividreflection.com/blog/installing-xdebug-on-macosx/
http://www.designified.com/blog/article/60/compiling-installing-xdebug-for-php-525-entropych-build-on-os-x-105

Installing MySQL

Use the installer from MySQL’s site, and it goes pretty seamlessly. You may have to edit the php.ini to use the mysql server.

The tricky part of this is if you use a framework, or your code uses the pdo database interface. Again, you can try my 64-bit version, or compile your own pdo_mysql extension. Enable the extension in the php.ini by addin gthe line extension=pdo_mysql.so

pdo_mysql.so (specific to 64-bit Mac OS X)

http://www.hoboes.com/Mimsy/hacks/adding-pdo-mysql-mac-os-x-leopard-server/
http://www.spiration.co.uk/post/1332/install%20PDO_MYSQL%20-%20mysql_config%20and%20header%20files%20problem

Eclipse

So there is a Cacao version that is 64-bit. I guess the difference here, as I’ve read online, is that the Carbon version is more stable, but also legacy and in the future will be deprecated soon.

I love using the update site to get plugins. That seemed to work best for PDT php, aptana, SVN (subclipse), and various editors, etc.

Flex

I sort of copped-out here when I learned the 64-bit version of eclipse doesn’t work well with Flex-Builder as an Eclipse plugin. I’m planning on installing the stand-alone version of flex builder, and using that separately (a little but resource wasteful, but far more convenient).




I absolutely hate the new project dialog in eclipse. It seems like each plugin (PHP, Flex, Aptana, SVN, etc.) has its own way of doing a new project.

Here’s one reason I hate these dialogs – If I want to add a new project into my workspace, I can’t put the files there first and then make it a project. Why would I want to do this? 1)I want to clone a git project from a remote repository into my workspace. Right now there is no way to do this with an add project dialog. So the files get to my workspace, but they don’t show up as a project. Same goes for SVN stuff where I want to re-add the files as a new project without having to check the whole stinking repository out again. Plus, it would be nice if I wanted to add files first, then make projects. Is that so hard? I understand eclipse doesn’t want to muck around in a folder with no project data to make a new project, but really, is it so hard to make a non-project folder a project folder? And if eclipse isn’t meant to do this, GET RID OF THE ‘Create project from existing source’ option because it doesn’t work with many project types.

So here is a way I found that works swimmingly. I wonder if this came as an option with a plugin. If so, I am using PDT php, Aptana, Subclipse, and I think those are the main ones. If you don’t get this option in your menu, than who knows what plugin you may need. I’m just glad I got it to work for me.

SOLUTION: Screw the new project dialog. Do File->import then select the folder ‘Other’->Existing Folder as New Project. This works great for my goal of 1)having files in my workspace that are not a project in eclipse and then making that folder and all its files a new project.




When doing a push to master I was getting

bash: git-upload-pack: command not found
bash: git-receive-pack: command not found

For me my server was not recognizing the git command. I had to add the server paths to my local git config

receivepack = /home3/<myusername>/local/git-1.6.4/git-receive-pack
uploadpack = /home3/<myusername>/local/git-1.6.4/git-upload-pack

where the config file is in the .git directory of my project on local. This line is under the entry for the remote I had set up called ‘origin’ (use the path on the server where the git install is located and make sure git-receive-pack is in there on the server).

BUT,I think the following is be the better solution. Editing the .bashrc worked like a charm. I added the following line to my .bashrc file (look in /etc or you home/ directory if on a shared server) and things worked swimmingly.

export PATH=”$PATH:/home3/<myusername>/local/git-1.6.4″

replace /home3/… with whatever the path to your git install may be.

I’m still not clear on why the path would be different for a bash ssh command, and a client sending a request over ssh to the server. It seems as if even though my server environment variable $PATH includes the path to the git install, the $PATH variables does not include that path if the git commands are invoked over a remote ssh request (like my eclipse working with git). But if I was logged in on a bash shell, the git commands worked great, with no ‘command not found’ errors. Make sure when you install git, that you understand how to make your server recognize the git executable commands, both from the bash and also from remote requests. I’m still unclear on the difference between 1) editing the $PATH environment variable to include your git directory 2) Editing the .bashrc with the export $PATH setting. 3) Making symbolic links from the bin folder to your git install.

See http://stackoverflow.com/questions/225291/git-upload-pack-command-not-found-how-to-fix-this-correctly

make[2]: execvp: Permission denied


Posted on August - 30 - 2009



make[2]: execvp: true: Permission denied

You need to do chmod 755 true on the true script on your bin, For me I had followed the instructions at:

http://blogs.koolwal.net/2009/07/20/howto-installing-git-on-bluehost-domain-hosted-websites/

for installing git on bluehost. I had to make a script called ‘true’, and put it in my local bin to get git to compile.

make[2]: execvp: <YOUR FILE HERE>: Permission denied

These errors mean that your script does not have execute rights. You can ‘chmod 755 <YOUR FILE>’ and it should work.




Getting an HTTP_Request class was pissing me off. So it seems like you can’t install PECL classes on your php install because of rights issues on a shared hosting environment.

BUT, you can get PEAR classes installed through the cPanel, using the PHP PEAR Packages link. I was adding the HTTP_Request package (HTTP_Request2 won’t install because there is no stable release as of yet).

But even after the install, the classes could not be found. Like when I did require_once(‘HTTP/Request.php’) I was getting the classic not found warning and error:

Warning: include(HTTP/Request.php) [function.include]: failed to open stream: No such file or directory
Warning: include() [function.include]: Failed opening ‘HTTP/Request.php’ for inclusion
Fatal error: Class ‘HTTP_Request’ not found

You have to edit the php.ini (or ini_set the include_path ) to include :/home/yourusername/php, or in my case the home directory is now home3 for some reason, with some weird aliasing allowing for home I think. The PEAR packages install to /home/yourusername/php, so this needs to be added to the include path.

If you still get:
PHP Fatal error:  main(): Failed opening required ‘PEAR.php’
Then your include_path may be missing :/usr/lib/php, this is the main (not your local user) php lib folder that, I think, has the main PEAR files (The ones that your local PEAR package installs like HTTP_Request will be calling). So when you install a PEAR package via the cPanel, it puts them in /home/yourusername/php, and those files will need to know about the main PEAR install in /usr/lib/php by having /usr/lib/php in the include path.




private function XMLtoHTMLEntities($string){
//get rid of any XML entity encoding that may have been applied (like in an RSS feed)
$unXMLEntify = str_replace ( array ( '&' , '"', ''' , '<' , '>'), ->
array ( '&', '"', "'", '<', '>') , $string );
return htmlentities($unXMLEntify);
}