A Toy for My Nephew

My nephew really likes light switches, so I made him this toy out of junk that I found in my house. He does know the word “hot”, so I think he’ll understand not to touch the bulbs. If he doesn’t, I may have to cover them with something or use a different bulb. He’s a smart kid, so I’m not too worried about it.

My First Sinatra Project

I have a wufoo form that I’m using and I want to automatically see the results on a webpage. One of the hangups of this process is that I can’t put any script on the webserver. But what I can do is embed an iframe. So I could download the information that I wanted from my form to another server and then display that page in the iframe. My question was what to run on my second server, which I’m going to call my results server. All it really needed to do was get the results and then show them. So using a ruby on rails app for this seemed to be overkill. After reading about it, sinatra seemed to be the perfect fit. I could still use ruby and just show the results I wanted. This seemed to be the perfect project to test out sinatra.

The only gems that I needed were sinatra and wuparty. Wuparty is a gem specifically written for wufoo. I installed it with gem install and found that it didn’t install correctly. I looked at the source code on git and saw that everything except the /lib/wuparty/* files got installed. If I knew how to use git better, I’d submit a ticket. But it was easy for me to just fix manually.

Anyway, ignoring all the files I need to deploy or set things up, here’s what I needed.

Gemfile

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '>= 2.5.0'

gem 'wuparty' # For using wufoo API
gem 'capistrano' # For deployment
gem 'rake', '12.3.2'
gem 'rack', '2.0.7'
gem 'sinatra', '2.0.5'

config.ru

require 'rubygems'
require 'sinatra'
require File.expand_path '../display_results.rb', __FILE__

run Sinatra::Application

entry.rb (this is where I define which fields are for what)

Entry = Struct.new(:firstname, :lastname, :institution, :attending, :guestfirstname, :guestlastname, :guestattending)

module Entries

end

if __FILE__ == $0
x = Entry.new('George', "Washington", "White House", "Dinner and Talks", "Martha", "Washington", "Dinner").to_h
puts x[:firstname]
end

display_results.rb

require 'rubygems'
require 'sinatra'
require 'wuparty'
require_relative 'entry'

config = YAML.load_file("config/wufoo.yml")
account = config["ACCOUNT"]
api_key = config["API_KEY"]

get '/results.html' do
erb `cat public/results.html`, layout: false
end

post '/results' do
@entries = []
wufoo = WuParty.new(account, api_key)
form = wufoo.form('FormName')
count = form.count.to_i
pageSize = 100
times = (count / pageSize).to_i
(0..times).each do |l|
form.entries(limit: pageSize, pageSize: pageSize, pageStart: (pageSize * l)).each do |e|
@entries << Entry.new(e["Field1"], e["Field2"], e["Field4"], e["Field6"], e["Field215"], e["Field216"], e["Field218"]).to_h
end
end
output = erb :'results.html'
File.open("public/results.html", "w") do |f|
f.puts(output)
end
end

That’s basically it. It’s really simple, but does exactly what I want it to do. And wufoo has webhooks that you can set up. I use those to send a post request each time someone signs up. This post request generates a new results.html file for me. And that’s the file that I put in an iframe on the website where I’m very limited in what I can do. I store a few things in a config file that I don’t want to store in my repo.

This is pretty simple, that I’m pretty sure it would be easy for me to add another get/post combo for another wufoo form when I add it.

This was a fun project and I like being able to set up sinatra to handle simple things like this. Rails would have been overkill here.

Quick Baby Quilt

After the success of my Dr. Seuss quilt, I was in the mood to make another quilt. So I used only leftovers from my previous quilts to make a baby quilt for a cousin who is having a baby. My original idea was to make it in 30 days, but I think I took longer than that. I’d have to check my journal to find out exactly when I started it, but I finished it on July 31st. And the baby is due the first week of August, so I’m happy with that. I’m not happy that I haven’t yet mailed it to them, but I’ll try to do that soon.

The other thing I really like about the quilt is that I think I’m finally getting the hang of correctly mitering the corners. Look at how good this corner looks. I actually stopped sewing to take a picture of it because I was so pleased. I’d like to say the other corners all looked like this, but they weren’t as good.

My best corner ever

And here are some pictures of the final quilt. I’m quite pleased with how it turned out.

cmake

I haven’t been doing much with writing/compiling c programs of late. So I didn’t really notice the move from using make to using cmake for the build environment. We’ve been having some issues at work with this, so I’ve spent a few days trying to learn it. I’m not at expert at this at all, but I have picked up a few things. So I want to document them here.

Here’s a simple hello.c program.

#include <stdio.h>

int main() {
printf("Hello world!\n");
return 0;
}

It can be compiled with:

yo:hello $ gcc hello.c -o hello
yo:hello $ ./hello
Hello world!

How would I do this using cmake?

yo:hello $ mkdir build
yo:hello $ touch CMakeLists.txt
yo:hello $ ll
total 32
-rw-r--r--  1 maryh  staff     0 Apr 24 10:23 CMakeLists.txt
drwxr-xr-x  2 maryh  staff    68 Apr 24 10:23 build
-rwxr-xr-x  1 maryh  staff  8432 Apr 24 10:09 hello
-rw-r--r--  1 maryh  staff    73 Apr 24 10:06 hello.c

The file that cmake looks for is called CMakeLists.txt. Edit this file so it looks like this:

cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(hello)
add_executable(hello hello.c)

All this does is check that we’re using at least version 3 of cmake. Not necessary for this, but for some other work programs, I needed that. The project line sets up the project and stores the name in the variable PROJECT_NAME. And if it’s the top-level CMakeLists.txt file, it also stores it in CMAKE_PROJECT_NAME. And the add_executable line adds an executable target (for us called hello) that’s built from the source file(s) (for us we only have hello.c).

That’s all that is needed. It’s nice to make the build directory and run the cmake program there because it makes things much easier to delete all the files if you’re doing various iterations on things.

To compile then, go to the build directory and run:

yo:hello $ cd build
yo:build $ cmake ../
-- The C compiler identification is AppleClang 9.1.0.9020039
-- The CXX compiler identification is AppleClang 9.1.0.9020039
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/maryh/Documents/C/hello/build

Now use make to compile the program.

yo:build $ make
Scanning dependencies of target hello
[ 50%] Building C object CMakeFiles/hello.dir/hello.c.o
[100%] Linking C executable hello
[100%] Built target hello
yo:build $ ll
total 80
-rw-r--r--   1 maryh  staff  13521 Apr 24 10:33 CMakeCache.txt
drwxr-xr-x  15 maryh  staff    510 Apr 24 10:34 CMakeFiles
-rw-r--r--   1 maryh  staff   4751 Apr 24 10:33 Makefile
-rw-r--r--   1 maryh  staff   1373 Apr 24 10:33 cmake_install.cmake
-rwxr-xr-x   1 maryh  staff   8432 Apr 24 10:34 hello
yo:build $ ./hello
Hello world!

This is definitely overkill for such a simple program, but those are the basic steps for more elaborate programs. And the key file to edit is basically CMakeLists.txt.

Ideas

It’s weird. I’ve just spent the past two hours making myself a calendar. I was wondering how to design it and it just popped into my head that I have pictures from the early 2000s to now. Why don’t I use some of my own pictures on my calendar? And then find some quotes I like and put them over the picture. It’s a really simple idea, but I love it. I’m going to get a calendar that has motivational or inspirational quotes and I can look at pictures of things I’ve done which brings back those memories. Totally going to make me happy.

I had wanted to read a book tonight, but I finally got my bluetooth speaker working with my laptop. So I felt that I had to listen to music. I can’t really read when there’s music playing that I can sing along to, so I gave up reading pretty quickly. Then I was thinking that I need to start tracking that I’m eating vegetables, so I need a calendar. And making calendar on the computer is something I can easily do while listening to music. I don’t know why, but now that I don’t have a tv, I feel like I’m getting more and more good ideas for projects. Or maybe it’s just that I have the time to do them, since I’m not sitting in front of a tv. All I know is that I’m loving getting more and more ideas, so I hope they keep coming.

UPDATE: Just printed the calendar. I have a cheap printer and it says it prints on 13×19 paper, which technically it does. But on a few pages, everything was a little skewed. So I think it has a hard time handling paper that big. But it’s printed and hanging on my wall and I love it!

Happy 2019!

Got a decent amount of sleep last night, so I’m starting the year off right. Just went for a short walk to the mailbox to pay some bills and now I want to think about things for the coming year…and beyond.

I think it was Bill Gates who said “People overestimate what they can do in one year and underestimate what they can do in ten years.” I completely agree with that. In fact, I learned that around my 40th birthday when I decided to learn ruby on rails. I had very little programming experience and I recall that it took about four years for me to produce something usable. Now I’m still not a programmer, but in a pinch, I can put together something that can solve a problem for me. And that’s all come from my few years investment in learning a decade ago. So while what I’m going to list here are my resolutions for this year. I’m also hopefully laying the groundwork for some longer term things that I want to do.

I’m old enough to know that if you set up good habits, it’s much easier to “trust the process” and get to your final goal without being miserable. Most of the difficulties in life that I have are due to bad habits that are very difficult to break. Just look at all the people who fail at quitting smoking. I’m fortunate that I didn’t take up smoking. But my bad habits tend to gather around eating. I don’t plan meals that much, I snack a lot and I eat far too many sweets. It doesn’t take a genius to know why I’m overweight. So my first resolution is the same as last year. Basically, it’s eat more vegetables. (Quite frankly, this is a resolution for life.) But in order to track things, the exact goal is to eat at least on vegetable per day. I just read a book on eating and the ideal is to make 50% of each meal to be fruits and vegetables. I’m actually ok with eating fruits. I have fruit every morning with breakfast. I know me and it’s the vegetables that I have an issue with. So I’m going to try a bunch of different kinds of things and cooking them in different ways. Hopefully, I’ll find something that can be a go-to meal with vegetables.

My second resolution is probably quite funny, considering that this is being read on a blog. And that’s to get away from screens of all types. I’m far too distracted when I work on my laptop. I always have mail open and immediately check any new messages that come in. When I’m at work, that’s fine…it’s my job. But when I’m at home, I need to start shutting that off. I sort of started this last year when I switched to using an android phone from my iphone. It’s not as nice to use, so I didn’t want to use it as much. I also deleted all (except instagram) of my social media accounts. And took all the apps off my phone. I can still check instagram, but I have to log into it on my computer. That’s painful enough that I know I won’t do it very often. My overall goal here is to be more present. When I’m visiting or talking to people, I want it to be about that connection and not have some electronic devices in the way. I’m not getting rid of all my electronic devices. I work in IT and knowing how to take care of them is my job. And I’m still happy to help people who are having trouble. But the random pull my phone out because I’m bored or am not enjoying the conversation needs to stop. If I’m that bored someplace, I should just leave and go and do something more productive.

Related to the previous goal is to do more with physical objects. Again, I started this last year with doing more DIY projects and I’m all for continuing with that. But this also includes, writing more in my journal and seeing friends face-to-face instead of talking through text messages. The journal writing has been wonderful. I’ve been going to the coffeeshop on weekends for the past few months and just thinking and writing down ideas. I usually just take my journal, pens and a book to read. Is it an expensive habit? Yep, I probably shouldn’t be spending $10 on lattes every weekend. But I think it’s very worth the benefits I get from sitting and thinking for an hour or two every weekend.

I pretty much do this a lot already, but I’m putting it down because it’s very important to me. Bike more. I am almost always happy when I’m riding a bike. It’s good for me, the environment, saves money…the list of benefits seems endless.

Fail more. This may seem kind of odd, but I think I’ve gotten too comfortable with life. In general, I’m not a risk-taker, but I think I’ve flipped to the too risk-averse. I need to try some big public things where I can look like a complete fool when they don’t work out as planned. And yes, people will make fun of me for them for the rest of my life. That’s fine. It won’t kill me and perhaps I’ll actually achieve a crazy goal.

The items above are my actual resolutions for the year and my life essentially. But there are some other things that I’d like to do or try, but I may not really commit to them this year. I’m putting them down just to note them.

  • meditation–though my coffeeshop writing is already a sort of meditation
  • yoga, tai chi or some other practice that will help with flexibility and focus
  • drawing or calligraphy class
  • try making a bullet journal for my garden and maybe some other projects
  • find people who are interested in the same things as me, maybe start going to meetups about stuff I’m interested in
  • do a 5k
  • look into shorter-term volunteer opportunities
  • do a metric-century (62 miles) bike ride
  • learn about being a landlord
  • learn electronics
  • get the garage set up for welding
  • try more difficult sewing projects
  • do more repair…look for a repair cafe to join
  • host people in my house more
  • read more books

I think that’s enough. It’s funny, when my mind is calm and I can focus, the ideas just seem to pour in. Yet another reason that I should always carry a little notebook and pen. Sometimes I need to write things down quickly.

Happy New Year!