Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
# Add Vagrant's NFS setup commands to sudoers, for `vagrant up` without a password
# Updated to work with Vagrant 1.3.x
# Stage updated sudoers in a temporary file for syntax checking
TMP=$(mktemp -t vagrant_sudoers)
cat /etc/sudoers > $TMP
cat >> $TMP <<EOF
# Allow passwordless startup of Vagrant when using NFS.

Zero to Database with Laravel

Part 1: Seeding and Viewing

[Laravel][] is a PHP framework that's really a joy to work with -- though I did find the initial learning curve a bit steep.

This tutorial describes a minimum set of steps necessary to pull content from a database and dump it to a url using Laravel's Eloquent ORM. For me, that was the breakthrough moment.

Assuming you've got [Laravel installed][install] and the [database configured][configure], here are the steps needed to get your data from the database into a web browser:

  1. Create a migration
@joemaller
joemaller / Vagrantfile
Last active December 30, 2015 22:18
Troubleshooting Vagrant 1.4 NFS problems. Testing on a Mac with VirtualBox 4.3.4. VMs work correclty on first `up`, then fail on reload with this error: "No guest IP was given to the Vagrant core NFS helper. This is an internal error that should be reported as a bug." Precise32 box fails on first reload (precise64 also fails on reload). Lucid32 …
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "precise32"
config.vm.box_url = "http://files.vagrantup.com/precise32.box"
@joemaller
joemaller / re-thinking-angularjs.markdown
Last active August 29, 2015 13:57
Thoughts on the future of AngularJS

Re-thinking AngularJS

The [Angular 2.0 preview roadmap][ng-2] was recently posted to [HN][ng-hn] and after reading it, I'm starting to think adopting Angular might have been a mistake.

Having built a few small projects with [AngularJS][ng], I've found the framework a pleasure to work with. Once past the initial learning curve, features started flying together. Most of my trouble-shooting time was spent getting backend data delivered correctly, Angular just worked. Based on this positive experience, I've been moving towards adopting Angular as the standard frontend of my web toolkit.

Choosing Angular wasn't without doubts. Introducing this many new conventions, syntaxes and practices doesn't come without a cost. The problem with re-invention is longevity: Either these new ideas succeed and become the norm, or they're left for dead on the side of the road as technology marches on.

Parts of the 2.0 roadmap sound great. But it also sounds as if this future Angular will be very different from the Angular w

gulp.task('gulpify', function() {
gulp.src("./src/js/**")
.pipe($.plumber())
//using vinyl-transform lets us use any transforms available to browserify
.pipe(transform(reactify))
.on('error', $.util.log)
.pipe($.ext.replace('.js'))
// converting .jsx/coffee/etc. into a temp folder prior to 'bundling' reduces additional boilerplate later-on
.pipe(gulp.dest('./temp'))
.pipe($.filter('init.js'))
@joemaller
joemaller / one-line-sourcemap.css
Created July 12, 2014 02:33
This is the CSS file that's failing to be picked up by convert-source-map. Mentioned here: https://github.com/thlorenz/convert-source-map/pull/6#issuecomment-48799449
body p{color:red;}body h1{color:orange;}body h1 p{color:green;}/*# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiIiwic291cmNlcyI6WyJhcHAvc2Nzcy90ZXN0LnNjc3MiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsS0FBSyxFQUVHLE1BQU8sS0FDZixLQUFLLEdBRUcsTUFBTyxRQUFmLEtBQUssR0FBRyxFQUVJLE1BQU8iLCJzb3VyY2VzQ29udGVudCI6WyJib2R5IHtcbiAgICBwIHtcbiAgICAgICAgY29sb3I6IHJlZDtcbiAgICB9XG4gICAgaDEge1xuICAgICAgICBjb2xvcjogb3JhbmdlO1xuICAgICAgICBwIHtcbiAgICAgICAgICAgIGNvbG9yOiBncmVlbjtcbiAgICAgICAgfVxuICAgIH1cbn0iXX0=*/
@joemaller
joemaller / Readme.md
Last active February 10, 2019 23:21
A simple gulpfile example

Build-tools and Live Reload

As creating for the web has gotten more complex, build tools have become an essential part of my workflow. These tools are usually used to automate repetitive tasks such as pre-processing CSS stylesheets from Sass or Less, or compiling JavaScript from many smaller files. They can also reload browsers when files change -- not having to constantly mash reload is a significant productivity boost. Working without auto-refresh now feels like trying to type in mittens.

[Gulp][] and [Grunt][] run from the Terminal, [CodeKit][] and [LiveReload][] are standalone Mac apps. Gulp is relatively new, is very fast and its task definition files are written in JavaScript. Grunt is more established, works well and has a ton of people using it, but can be slower and requires a lot more configuration using verbose JSON files. CodeKit and LiveReload help with common workflows, Gulp and Grunt can do just about anything imaginable.

I’d been happily using Grunt for a while, but increasing buzz a

@joemaller
joemaller / webhook_validate.php
Last active November 20, 2021 12:29
Validate Github webhook signatures with PHP
<?php
$sig_check = 'sha1=' . hash_hmac('sha1', Request::getContent(), $_ENV['github_webhook_secret']);
if ($sig_check === Request::header('x-hub-signature')) { // php >=5.6 and above should use hash_equals() for comparison
// sigs match, do stuff
}
@joemaller
joemaller / gist:33fea86a9b313d2359cd
Last active February 5, 2016 16:05
IPTables command to block attempted logins to our office server, mostly out of China. These commands don't attempt to isolate single IPs, they just ban the entire subnet.
iptables -I FORWARD -s 89.248.167.139 -j DROP
iptables -I FORWARD -s 112.33.0.0/16 -j DROP
iptables -I FORWARD -s 113.194.0.0/16 -j DROP
iptables -I FORWARD -s 113.195.0.0/16 -j DROP
iptables -I FORWARD -s 115.230.0.0/16 -j DROP
iptables -I FORWARD -s 115.231.0.0/16 -j DROP
iptables -I FORWARD -s 115.239.0.0/16 -j DROP
iptables -I FORWARD -s 117.21.0.0/16 -j DROP
iptables -I FORWARD -s 117.25.0.0/16 -j DROP
iptables -I FORWARD -s 218.25.0.0/16 -j DROP
@joemaller
joemaller / gist:c05ca826971f9b563ce8
Created January 16, 2015 02:14
View a uniq list of connections from /var/log/vsftpd.log
sudo grep CONNECT /var/log/vsftpd.log | cut -d ']' -f2 | uniq