What’s with Redux, ReduxSauce, Thunk, and Sagas?

What is Redux?

A library to create and manage data objects (aka state objects) based on the flux pattern.

Actions

Are requests to a store to take an action.

Example:
{ type: ADD_TODO, text: ‘Build my first Redux app’}

Action Types

An enum of allowable action types.

Reducers

Are handler functions for actions that apply the action payload.

myReducer = (state, action) => nextState

ReduxSauce

Is a library to make Redux more DRY. In doing so though, it makes the code less readable imo.

Thunk and Sagas

Calls to actions are synchronous. This means that action handlers cannot fetch data or have side effects. Thunk and Sagas solve this desire.

Reasons for: More powerful Redux can handle most of your biz logic
Reasons against: If not done carefully, you will end up with Redux spaghetti

Thunk

Thunk is an extended reducer which can (1) return a promise, and (2) actions are allowed to be called from within the promise (aka side-effects). For example, you can have an action which first sets a loading field = true in the store, fetches data, then updates the store when done.

Sagas

Sagas is like Thunk, but allows for action handling to be interrupted using generators

Further Reading

  • https://engineering.universe.com/what-is-redux-saga-c1252fc2f4d1

How to access object attributes based on a variable in Typescript

Typescript is obscurely particular with accessing attribute keys on objects that lack a generic signature. Adding generic signatures reduces type-safety though.

Here’s a Typescript-friendly way to verify an attribute exists in an object, and then access that attribute.

This post originally posted at https://blog.smartlogic.io/accessing-object-attributes-based-on-a-variable-in-typescript/

Have FTP but no ssh? Web Shell to the rescue!

There are many times a web shell can come in handy, such as  running a non-shell OS or if you have FTP but non SSH.  Web shell to the rescue!  The top three I could find are b374k-shell, ajaxshell, and shellinabox.  b374k-shell is my favorite, because it is all-around better than ajaxshell, and it doesn’t require compilation like shellinabox.  So enter b374k-shell a php web app that emulates some core capabilities of a shell.  Here is my review.

Features:

  1. A web-app that is a self-contained php file
  2. Password protected – stores a hash of your password within the php file
  3. Secure if you have https configured
  4. basic shell
  5. file browser, with options to
    • upload
    • edit
    • download
    • create
    • delete
    • rename
    • hex view
    • compress
    • decompress
    • copy
    • paste
    • chmod
    • limited bulk operations
  6. process manager
  7. system info browser
  8. php/python/ruby/perl/gcc evaluator
  9. db shells

 

Limitations:

  1. Can’t sshfs
  2. Bulk upload/download
  3. Basic editor with no syntax highlighting
  4. Works on mobile, but isn’t optimized for mobile

 

Conclusion:  It isn’t as good as ssh, but it’s super cool and can do everything you need it to for web development.

jQ.Mobi 1.0 vs. jQuery Mobile

A common complaint about jQuery Mobile is the size and speed. By giving up support of legacy browsers, frameworks like jQ.Mobi (aka jqmobi) and Zepto claim smaller footprints and superior performance.  According to most benchmarks I’ve seen like this one, jQ.Mobi delivers while Zepto falls short of it’s performance claims.  Also, jQ.Mobi claims support for IE9 and IE10.  For these reasons, I decided to give jQ.Mobi a shot.

To create a fair comparison, I recreated last post‘s jQuery Mobile demo using the jQ.Mobi+jQ.Ui framework.  Getting started with jQ.Ui is harder than it should be, especially since being acquired by Intel.  On the bright side though, it’s still open source and the developer is very friendly on GitHub.  The best way to start with jQ.Ui is to pull down the jQ.Mobi git repo and point your browser to the jQ.Ui kitchen sink.  From there, you can explore most of the features jQ.Ui has to offer.  I started this demo with the example project.

My overall impression with jQ.Ui is good and bad.  I confirmed every claim of performance and size.  My demo is footprint is tiny, very noticeably faster on both newer and older devices, and compatibility with mobile phones is superb.  I’d go so far to say that compatibility on phones is even better than jQuery Mobile.  On the other hand, jQuery Mobile is a lot easier to develop on because 1) The documentation is awesome, 2) the library of built in gadgets is much bigger, 3) customizing and theming is much more intuitive, 4) RIB will get you up and running wicked fast.

So for the time being, I’ll prototype with jQuery Mobile and move to jQ.Mobi if the extra work is warranted later.  Check out my jQ.Mobi demo here!

Initial thoughts with the jQuery Mobile Framework

I’ve been meaning to try the jQuery Mobile Framework for a while now, and after discussing with District Karaoke’s Jesse Rauch I felt inspired.

So far, I’m optimistic. The baked in look and feel make for a what appears to be a nice experience. However, JQM animations are a little ahead of the mobile support. The animations will not be smooth on most phones, and will sometimes not come from the correct direction. It seems entirely a performance and browser issue, and I think JQM will look much better in future phones.

So for now, JQM may not be the best choice for lower end phones. Stay tuned, because soon I’m going to report on how JQM compares to alternatives.  In the mean time, check out my demo and offer me your thoughts!

Quick tip: I found the easiest way to get up and running with jQuery Mobile is to use the awesome RIB tool.

Migrating WordPress the easy way

UPDATE
I now advise using interconnectit’s php script method instead of the method below, because it’s more reliable.

If you search on Google, there are tons of tutorials on migrating WP.  I found all of them hard to follow and overly complicated.  Follow these simple steps to easily move a WordPress (WP) website:

1) Copy the WP root folder to the new location

2) If also migrating the db, use phpMyAdmin to export the WP tables from the old db and import them into the new

3) Point a browser to the new WP location.  It should work, but all of the db is still pointing to the old WP location so we have to fix that

4) Run these sql commands in phpMyAdmin:

5) Last, make sure you setup mod_rewrite on your new web server if you are using mod_rewrite on your old one.

Setting phpMyAdmin to point to an Amazon RDS instance

Isn’t it annoying how you can’t ssh in to Amazon RDS instances?  Don’t you wish there was a way you could use trusty old phpMyAdmin to manage your db?  Here is the easy way to do it:

  1. Find the endpoint link to your RDS server.  It’s found in the instance information section.  It usually looks something like this: xxx.amazonaws.com
  2. Install phpMyAdmin somewhere.  I recommend on a webserver so you can access anywhere.
  3. cd phpMyAdmin
  4. sudo cp -p config.sample.inc.php config.inc.php
  5. Change this line in config.inc.php:

to

 

That’s it!

CloudFormation templates: Old vs. New

I’ve been using Amazon Web Services (AWS) for a while now, and have recently started using their new product called CloudFormation.  CloudFormation is a must-have solution if you find yourself setting up the same web stack frequently.  First you setup a template for your stack, then you let CloudFormation setup your stack for you.  I’ve now used it several times for WordPress + RDS stacks, and it has saved me a tremendous amount of time!

That said, I don’t like the new example template for WordPress + RDS stack.  I find overly-complicated, because it askes for many parameters which are unnecesary and not straight forward.  If you are having trouble with the new template, I highly recommend trying the old one here.

Tip:  The example WordPress+RDS templates disallow micro RDS instances.  This sucks because it bumps you out of the free usage tier.  If you want to stay in the free, just add db.t1.micro to the allowed values of DBclass in the template.  I already did this for my template I posted above.  For small websites, the db.t1.micro works just fine!

Namescheap and DNS settings

I started using Namescheap lately as an alternative to GoDaddy.  Namescheap is awesome for how clean and straight forward it is.  I do pose a warning though:  their documentation for the DNS settings is somewhat misleading and confusing, and their default settings are probably not what you want.

The Options:
URL Redirect (default) – URL Frame Forwarding – A-address –  URL Redirect – 301

My advice:  If you want this domain to have the browser redirect to another domain, use URL Redirect.  You will notice in the address bar that the original domain you entered will change to the redirected domain.  If you are using the domain name as your primary, then use the A – address option.