programming

Importing Images in Electron React Boilerplate

  • Posted on: 11 February 2017
  • By: davis

You'll need to do a few things to properly import images in electron-react-boilerplate

First, create a directory under app/ to store your image files (e.g. app/img). Then drop your images in the folder.

Here's the correct (and only!) way to import images correctly in electron-react-boilerplate:

Building an LED Hula Hoop From Scratch

  • Posted on: 26 November 2016
  • By: davis

I'll save you a read if you don't care about details. Long story short - buy yourself a quality hoop from Hyperion. Save yourself the trouble of doing this, because frankly, the results we obtained were not that impressive. We spent around $800 in materials by the end of this project and ended up with a heavy, bulky, large, cumbersome hoop that broke after 10 minutes. Seriously - just get a good hoop from a pro.

Our final result, starring my girlfriend Amanda:

 

Fixing missing libssl library when using Django/Anaconda

  • Posted on: 16 November 2016
  • By: davis

Here's the fix for this error message on OSX: 

raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: dlopen(/Users/anaconda/lib/python2.7/site-packages/psycopg2/_psycopg.so, 2): Library not loaded: libssl.1.0.0.dylib

 

Python: Capitalize First Letter of Each Word in a String (including after punctuation)

  • Posted on: 14 November 2016
  • By: davis

Python's str.title()  and string.capwords(str) methods have some flaws. Namely:

str = "my dog's bone/toy"
assert str.title() == "My Dog'S Bone/Toy"
assert string.capwords(str) == "My Dog's Bone/toy"

As you can see, str.title() doesn't quite format the string "Dog's" correctly - it instead opts to convert the "'s" to uppercase. This results in somewhat nonsensical strings.

string.capwords(str) is better about honoring the possessive case, but it has its own flaws. Firstly - it doesn't recognize words that occur after common punctuation like /, ( ), -, _, etc. This means that "bone/toy" will only be converted to "Bone/toy"

I've written my own answer to this problem, hopefully it helps anyone else who needs to capitalize the first letter of each word after punctuation without using title() or simply relying on capwords().

My solution first takes advantage of title() to solve most of the capitalization. It then uses a Regular Expression to look for an upper-cased letter preceded by a single quote mark that is in turn preceded by a lower-cased letter(this solves the issue of retaining contractions while matching single quotes within strings.)

 

Primitive Pics: A Really Cool Go Project

  • Posted on: 20 September 2016
  • By: davis

https://github.com/fogleman/primitive

This is a really neat project that allows you to create cool photographs from your input.

A target image is provided as input. The algorithm tries to find the most optimal shape that can be drawn to minimize the error between the target image and the drawn image. It repeats this process, adding one shape at a time. Around 50 to 200 shapes are needed to reach a result that is recognizable yet artistic and abstract.

TypeError: Cannot read property 'timeout' of undefined with Mocha and Fat Arrow Syntax

  • Posted on: 12 July 2016
  • By: davis

Don't do this: 

describe('Do Something', () => {
  it(`Should do stuff successfully`, (done) => {
    this.timeout(20000);
    // *this* binding refers to parent function scope in fat arrow functions
    // this will fail, no pun intended

    // do stuff here and include done() in the callback

Replace it with a normal function - fat arrow syntax will assign the "wrong" scope to timeout(), and you'll get an error like TypeError: Cannot read property 'timeout' of undefined

How I got the Shittalk Generator to 80kb pagesize

  • Posted on: 30 March 2016
  • By: davis

Lesson #1: Probably shouldn't have named it Shittalk Generator. It's hard to tell your family what it is. "Well... it's a script to shittalk people". Maybe I would have named it the Trash Talk Generator, in restrospect

You can track the actual commits I made on Github, you'll see the progression in pagesize.

Here are some notes:

Minify HTML (http://www.willpeavy.com/minifier/)

[RELEASE] Bootstrap CRUD Generator

  • Posted on: 30 March 2016
  • By: davis

Go to the CRUD Generator

I'm pleased to announce that I've developed a Bootstrap CRUD application generator. Tired of manually building forms for basic SQL events? Use my tool to generate CRUD pages for your tables.

A painless way to create PHP/MySQL/Bootstrap CRUD apps

Generate a basic Bootstrap-themed CRUD (Create, Read, Update, Delete) application based on your MySQL SELECT, UPDATE, or CREATE query.

Bash - Get Name of Parent Directory

  • Posted on: 2 March 2016
  • By: davis

For the path /foo/bar/, if the current directory is bar, and we want to get the name of the parent directory (i.e. foo)

path="$( cd "$( dirname $0 )" && cd -P "$( dirname "$SOURCE" )" && pwd )"
parentName=$(basename -- "$(dirname -- "$path")")
echo $parentName # will return parent directory's name

This resolves symbolic links (sidestepping the error where it returns "." for the parent dir). Give it a try.

Pages