How to Reset and Clear a Form Field or Textarea with Stateless Components in React
Stateless components are nice. They are simple to use and understand but can become tricky when you start thinking about data and how to manage state. In general, the consensus seems to be that if your UI is going to need state, then at least the componen...
Trigrams, Bigrams and Ngrams in Python for Text Analysis
Creating trigrams in Python is very simple
trigrams = lambda a: zip(a, a[1:], a[2:])
trigrams(('a', 'b', 'c', 'd', 'e', 'f'))
# => [('a', 'b', 'c'), ('b', 'c', 'd'), ('c', 'd', 'e'), ('d', 'e', 'f')]
You can generalize this a little bit more
Change the Default Controller Name in Rails Functional Tests
Rails will infer the controller you want to test from the class name of the test case. For example...
class PeopleControllerTest < ActionController::TestCase
will test the app/controllers/people_controller.rb.
To change this is trivial. Us...
Get Child Categories of Parent Category on Single Post in Wordpress
I was hoping to find a function in the Wordpress API, that goes something like this...
// print Burlington, Brattleboro... etc if this post has any child categories of Vermont
But I could not. The result that I did ...