The basic way searching works is that you create an index of all content on a site you want to search, then the search query is checked against that index. On something like a WordPress site, this query is checked against the database, which is a defacto index. Google does its own indexing of your site, so the Google queries are checked against Googleâs index (likely also stored in a database).
Since Jekyll sites are static (meaning that they are only files, no databases included) there is no database to search. That leaves us with two options:
Create an index on your own and make sure your search queries check against that index.
I love Google CSE, but I decided to go with the second route this time. I used Mat Haywardâs Jekyll Search scripts to do the heavy lifting, but I edited them to suit my needs. It is lightning fast!
These scripts:
Generate a JSON file of my site contents when the site is built
Compare the search query to the contents of the JSON file
Return the results based on a template
I modified the way the dates are formatted, how the excerpt gets put into the JSON file, the output styles, and put in a conditional for external link posts.
When moving files between Windows machines via Remote Desktop, you typically go to Local Resources > More and check the box in front of Drives to map your drive on the remote machine. Then you can use xcopy and \\tsclient to move the files.
This isn’t quite the same on the Microsoft Remote Desktop Mac app. I believe this is because Mac OS X can’t accept SMB connections by default, so you have to map a special folder on your machine to accept transfers.
When you add or edit a Remote Desktop connection, click “Redirection” on the top of the window.
Then check “Enable folder redirection” and map a folder on your machine to be mapped to \\tsclient. I like to map a Dropbox folder so I the items are automatically backed up for me.
The folder you map will be available at \\tsclient. You can either use xcopy from the command line or find it under the Network drives area in the file browser.
Let’s say you have two forms: One is a basic contact info form and the other is more in-depth. You have them separated because you want to capture contact information as soon as possible to follow up on leads, but you want some information to be carried over to the second form. You also want the user to be greeted with a message to finish the form when they come back to the site (if they leave).
Here is a sketch of what you’d need to do:
When the first form is filled out and submitted, set a cookie. You could either use vanilla Javascript or a plugin like js-cookie.
The cookies should contain the value of the form fields that were entered. Use something like form.fieldname.value in JavaScript or $("input").val() in jQuery to retrieve them.
Set the cookies for a reasonable amount of time. 2 weeks?
On the landing page, check for cookies. If they are there, change the call to action from “Apply Now” to “Finish your application!”
On the second form page, write a function to check to see if there is are cookies set. If there is, read the cookies and insert their values into the form.
When the form on the second page is submitted, use a function to remove the cookies. They are no longer necessary.
The implementation is left as an exercise for the reader. This outline should get you well on your way!
Medium is a wonderful network and editorial platform that allows anyone to share their stories and their ideas. It allows those who donÃÂâÃÂÃÂÃÂÃÂt want to run a full blog to publish their content easily. If you do want to start a full blog without the overhead of buying hosting or running a WordPress site, it is super easy to power your blog with a custom domainArchived Link through Medium. This means you can buy your own site name (i.e. http://amandagrimmett.com) and the Medium publication will show up there. Here is what you need to do:
Fill out this form with your publicationÃÂâÃÂÃÂÃÂÃÂs URL and what custom domain you want to point to it.
Medium will respond within 12 hours with a list of A records and a CNAME record that youÃÂâÃÂÃÂÃÂÃÂll need to add to your registrar. Here is a cheatsheet for you and MediumÃÂâÃÂÃÂÃÂÃÂs support pageArchived Link. This is a bit of a pain, but thankfully a good registrar like Hover can do this for you. HoverÃÂâÃÂÃÂÃÂÃÂs new Connect service presets the 12 A records for you and steps you through setting a CNAME record.
Within a few hours your domain will point to your Medium publication and your blog will be live!
I just set one up this weekend for my wifeÃÂâÃÂÃÂÃÂÃÂs awesome new blog. I couldnÃÂâÃÂÃÂÃÂÃÂt believe how simple it was. My only frustration was the wait time between submitting the request and getting a response from Medium. It was a weekend though, so I canÃÂâÃÂÃÂÃÂÃÂt complain.
Once it is set up, you log in through Medium and publish to it through the Medium platform. It has the benefit of being tied in to the entire Medium ecosystem, so sharing, commenting, and gaining followers is easy. You are constrained to the limits of their platform, but it does have some customization optionsArchived Link. This is perfect for those of you focusing on your writing.
Did you know that you can pre-fill Google Forms based on a URL? Did you also know that if you have a basic example you can automate it with a database and send personalized forms?
General Instructions
On your form, click the vertical ellipses in the upper right corner to reveal the menu.
Click âGet pre-filled linkâ
This shoots you over to a page where you can fill in the fields you want pre-filled and it will generate a URL for you. Copy this. If you want the link you send out to everyone to have the same pre-filled info, your work is done. Send the link out!
How you might automate it
Here is my example form.Once I went through the above steps to get a pre-filled link, here is what I got:
As you can see, those are the items I filled in on my own. How might one automate this, then? Here are a few suggestions:
Using handlebars or Liquid, fill them in with the appropriate expressions and use the appropriate objects to fill them in: https://docs.google.com/forms/d/1nuxTbnUGkTaZw1uGIXXgqfx3hYRi3ZaPahdwDNEgy3Q/viewform?entry.2005620554={{name}}&entry.1045781291={{email}}&entry.1065046570={{address}}&entry.1166974658={{phone}}&entry.839337160={{comments}}
Using PHP, you might assign variables for these items and fill them in from your database with a select statement: https://docs.google.com/forms/d/1nuxTbnUGkTaZw1uGIXXgqfx3hYRi3ZaPahdwDNEgy3Q/viewform?entry.2005620554=$name&entry.1045781291=$email&entry.1065046570=$address&entry.1166974658=$phone&entry.839337160=$comments
On Mailchimp, youâd have to use Merge Tags: https://docs.google.com/forms/d/1nuxTbnUGkTaZw1uGIXXgqfx3hYRi3ZaPahdwDNEgy3Q/viewform?entry.2005620554=*|name|*&entry.1045781291=*|email|*&entry.1065046570=*|address|*&entry.1166974658=*|phone|*&entry.839337160=*|comments|*
Note: Make sure you are URL encoding things with weird characters and spaces like an address. Example: 308+Negra+Arroyo+Lane,+Albuquerque,+NM+87114 vs 308 Negra Arroyo Lane, Albuquerque, NM 87114
Completion of the code in 1, 2, and 3 is an instruction left to the reader. Iâm assuming that if you want to do something like generate thousands of personalized URLs to a form, you probably already have a database and know how to use it. I hope this guides you in the right direction! Email meArchived Link if you want some help.
The best time to learn how to handle crises is right after you just had one. Analyze what happened, what you did to solve it, and then make a checklist for when it happens next time.
Then, during your next crisis, take a deep breath and start jotting down notes of what is happening and what you are doing. This makes your post-game analysis easier to complete.
We had a mini crisis at work today: Some of our sites weren’t connecting to our MySQL servers and we couldn’t figure out why. The problem was intermittent. Our sysadmin is on vacation, so a few of us had to jump in and try to figure it out. When we were in a holding pattern while waiting for our hosting provider to call us back, I made a checklist of what we need to do the next time this happens. This took into account what we had to figure out on the spot, look up, diagnose, and what we learned. Now we have it for the future.
H/T to Episode 279 of Back to Work with Merlin Mann and Dan Benjamin. I listened to it this morning and their discussion of making checklists while traveling for travel made me think of doing this during the MySQL issues.
Today I learned about jQuery’s greater than selector, :gt().
The :gt() selector selects elements with an index number higher than a specified number. The index numbers start at 0.
I’m using this selector to hide more than 10 recent posts on my TIL page. Each of these posts is inside a list item (li) and a child of the unordered list (ul) with a class called “recent”. I then added a toggle function on a button to show them again by using the same selector.
Example:
$(document).ready(function(){$("ul.recent").find("li:gt(9)").hide();$("ul.recent").has("li:nth-child(10)").after(""showhide button" >Show/Hide all TIL posts");$("a.showhide").click(function(){$("ul.recent").find("li:gt(9)").toggle("slow");$});});
There is also a less than selector in jQuery. It works similarly, except that it selects elements with an index number lower than the specified number. Syntax: :lt()
Note: Since I’m using a Jekyll site and generating that TIL list via Liquid, another solution is to set a counter after which it automatically adds a class directly to the HTML to hide those items that we can then toggle later. I think the jQuery solution is cleaner, though.
There are a lot more domain record terms than this, but these are the ones I most frequently encounter. I’ll add more as I run into them.
Records
Record
Description
Use
A
Address Record
Point a domain to a specific IP address
CNAME
Canonical Name Record
This is an alias of one name to another. Example: A CNAME of www.cagrimmett.com to cagrimmett.com tells the server to look for the WWW version wherever the non-WWW version’s A record resides. CNAME records must always point to another domain name, never directly to an IP address.
MX
Mail Exchange Record
Direct’s a domain’s email to the server hosting the accounts. I most frequently use this for setting up Google Apps.
NS
Name Server Record
Determines which servers will communicate DNS info for a domain. You usually have a primary and secondary. This site uses Cloudflare’s name servers.
Basically a phone book for the web. When you try to go to a domain (e.g. google.com) in your browser, the domain name system tells your browser where to find that domain, usually an IP address.
TTL
Time To Live
How long it will take any change you make now to go into effect
@
Self-referential character
You don’t use the actual domain name in your DNS settings. Instead, you use the @ symbol to indicate the domain name.
fname– I had to make this a snippet instead of putting it in directly because in the filename creation string TextExpander didn’t recognize the date string. If you nest it inside another snippet, it works just fine.
%Y-%m-%d-%filltext:name=title%.md
;tem
--- layout: post title: author: Chuck Grimmett date: %Y-%m-%d category: TIL feature-img: "/img/defaults/%snippet:;random-img%" tags: - excerpt: --- ### Today I learned:
Today I learned about Many-to-Many relationships in relational data models
A many-to-many relationship is a type of cardinality that refers to the relationship between two entities A and B in which A may contain a parent instance for which there are many children in B and vice versa.
For example, a recipe may have many ingredients and a specific ingredient may be used in many recipes.
In SQL, this relationship is handled by an associative table. The primary key for this type of table is composed of two different columns, both of which reference columns in other tables that you are associating together.
It is a good convention to name these associative tables by how they reference each other: Table1_Table2
A SELECT statement on an associative table usually involves JOINing the main table with the associative table.
If you don’t want to run these JOINs every time, create a view first. A view is a virtual table based on the result-set of an SQL statement. You can add SQL functions, WHERE, and JOIN statements to a view and present the data as if the data were coming from one single table.
Trifacta Wrangler is a free program (currently in beta) that helps you clean up data sets and gives you a first cut at basic analysis. It is great for quickly turning messy data into structured, manageable formats.
In the past few days I’ve used it to analyze huge log files and turn messy JSON in structured CSVs that I could import into SQL.
Quick tips:
splitrows always has to come first. The program usually tries to split by \n (new line) first, but that doesn’t always work for JSON. Try splitting by something like },{, or do a quick find and replace ( },{ for }|||{ ) and do the split by ||| if you want to keep the curly brackets for an unnest.
unnest is very powerful for splitting out JSON values out into separate columns titled by their keys.
flatten works better than unnest in cases where the JSON does not have keys. It creates new rows and repeats other values in adjacent columns to keep the relation. This works well if you have an ID column and are going to eventually stuff things into a relational database.
Hazel is a preference pane-based application that helps you automate organization on your Mac.
Within a few hours of using Hazel, I was able to clean out my 1000+ file Downloads folder, tame my unruly Desktop, get rid of all the trash that accumulated in my home folder, and organize my stashes of client files. I also set up rules for the future that will keep these places neat and orderly.
The next step is to turn my gaze on my photo library to create one master repository.
Data scientists notoriously hate word clouds. Besides for figuring out what the top 2-3 words are (because they are the biggest), it is difficult to see how much one word is used relative to another. Unfortunately, clients and non-data people love word clouds and sometimes insist on them. What is a self-respecting data nerd to do?
Pair it a word frequency chart!
The easiest way to do this is by using Python’s counter:
Counter(words).most_common()
Then you can use your favorite charting tool to make a bar chart of the results. I prefer D3.js.
Results
If you see both together, you get a better understanding of the words being used. Of course, a single word doesn’t always capture sentiment. They can be helpful in smaller data sets, but sometimes common phrases are more helpful in larger data sets. For common phrases, use n-gram analysis.
Ember.js is an open-source Javascript framework with the Model–view–viewmodel pattern.
Ember is an opinionated framework. This means that most architectural design decisions have been made for you by the developers of the framework. The advantage of this is that anyone who knows Ember can load your code and understand within a few minutes what is going on.
Core Concepts
Ember router maps a URL to a route handler
Route handler renders a template, then a model that is available to the template. Templates use Handlebars syntax.
Models save data in a “persistent state”, which is fancy language for putting it in a database or data store of some kind.
Components control how the UI behaves. They have two parts: A handlebars template and a javascript source file that defines the behavior.
Installing and running a project
Install:
$ npm install-g ember-cli@2.6
Creating a new app:
$ ember new
Starting the development server. You must be in the project folder (cd to it). It will serve on http://localhost:4200/
How to make link posts (or external post links) with Jekyll
I’m an avid reader of Marco.org and Daring Fireball. They both have these nifty posts that link directly to external pages. Now that I have two blogs, a podcast, and occasionally have work published elsewhere, I want to keep a record of these things on my cagrimmett.com blog. Link posts are an excellent way to do that.
Jekyll doesn’t have this capability out of the box, but with a little Liquid magic you can make it happen. I followed Christian-Frederik Voigt’s method. This takes advantage of the ability to create items in each post’s YAML front-matter and use them in template files:
First, create a variable called link: in your YAML front-matter for the post you want to link elsewhere. Fill it in with the link you want to post to link to:
Then anywhere in the template files that generates post headlines, you’ll need to write a conditional to check if the new link: variable is present. If it is, you’ll want to write the headline’s link there (post.link) instead of the post.url. I also added an arrow inside another conditional to specify that this is an outgoing link:
This method works great if you want to have direct links to other places and don’t want a permalink page on your own site that you can reference. I don’t care about that, so I didn’t make this for my site. If you want that, you’ll need to refer to Christian-Frederik Voigt’s method. The short story is that you’ll also need to modify the post and page templates.
Jekyll has a built-in filter called jsonify to turn data into JSON and Liquid has a filter called json. These is pretty useful for turning standard Jekyll output arrays into JSON, but if you need something more customized, you’ll need to build it yourself because Liquid’s ability to create arrays is limited. (Not a criticism, just an observation. It is primarily a templating language.)
For example, I wanted to store the dates I have blog posts for and the number of posts on each of those dates in order to pass it to a heatmap calendar. I couldn’t figure out a way to build that into a single array with Liquid (and I didn’t want to drop down into Ruby), so I figured out a way build JSON manually.
This outputs my blog’s post dates in the Unix timestamp format and displays the number of posts on a given day and leaves the trailing comma off to comply with the JSON standard:
The key to getting the counts right was advancing the counter by 1, comparing the date of the current post to the previous post, outputting the date and the count if they did not match, and if they did match advancing the counter by 1 and comparing again. After the date and count are output, the counter is reset to 0.
Thanks to Eric Davis for advice on using less code and pointing out how I can make the trailing comma if statement more efficient: %if forloop.last == false% , %endif%
He said:
If there’s one bit of “programming advice” I would give to anybody mucking around with this stuff, it’s this: Write as little code as humanly possible. The most bug-free line of code is the line not written.
What I need to ask myself: If something is being repeated, why?
I started a simple Python http server as a background process at the end of a Python script. That was a mistake. Since it isn’t running in an open Terminal window, it is easy to forget about and it will run until you kill the process or reboot your machine. I don’t like that.
Here is how to identify and kill background Python processes in Terminal.app: