Skip to content

Instantly share code, notes, and snippets.

View jwietelmann's full-sized avatar

Joel Wietelmann jwietelmann

View GitHub Profile
var sys = require('child_process');
function commandExists(cmd) {
var exists = false;
sys.exec(cmd, function(err) {
if(err === null) // of maybe: if(!err instanceof Error)
exists = true;
});
@jwietelmann
jwietelmann / barcamp_overlay.html
Last active August 29, 2015 14:01
RAWRRR BARCAMP OVERLAY PROOF OF CONCEPT
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
html {
background-image: url(http://www.barcampnola.com/images/splash.jpg);
background-size: cover;
}
body {
padding: 0;
layout author title
post
edward
Getting Good at Vim

I have used Vim to write code for about a year, and I can confidently say that Vim does two things for me well. The most obvious thing is that it cuts down on my text editing time. If you consider the amount of time you spend highlighting with the mouse and then returning back to the keyboard to edit text, daily, over the course of a year that time begins to adds up.
@jwietelmann
jwietelmann / every_controller_spec.rb
Created January 12, 2016 17:37
An RSpec sanity check to run against every Rails controller.
# What the heck is this spec about?
#
# It's a gut-check that runs against every controller in the application.
# It is NOT a replacement for writing controller specs for each controller.
#
# What this does is things like check to make sure you didn't forget to lock
# down the index action of a controller to authorized users, checks to see if
# common routes are throwing silly errors, etc.
#
# Your controller passing these tests does not guarantee that it is healthy.
@jwietelmann
jwietelmann / wordpress_controller.rb
Created January 12, 2016 17:39
A hacky way to consume WP-API content and provide it to Rails views.
require 'faraday'
class WordpressController < ApplicationController
@@wp_client = Faraday.new(url: "http://#{ENV['WP_DOMAIN']}") do |builder|
builder.adapter Faraday.default_adapter
builder.headers = {'Content-Type' => 'application/json'}
builder.request :url_encoded
end
@jwietelmann
jwietelmann / rack_reverse_proxy_by_adam.rb
Created January 14, 2016 22:46
"keep in mind that there are a few things here that don't work super well: Jekyll dies if you're missing a trailing slash. it appears to handle that internally by always redirecting to a url with a trailing slash. presumably there's some regular expression or something that we could use to handle the cases, but I didn't have time to solve that p…
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module MyProject
class Application < Rails::Application
// Stupid JavaScript and console tricks.
// Trap and record console things and errors.
function MosquitoNet() {}
MosquitoNet.history = [];
MosquitoNet.writeHistory = function(type, args) {
MosquitoNet.history.push({ type: type, args: args });
}
MosquitoNet.shadowConsoleFunction = function(name) {
var oldFn = console[name];
@jwietelmann
jwietelmann / webpackProgrammaticConfig.js
Last active November 23, 2019 17:35
File that exports separate webpack configs for frontend and backend
var webpack = require('webpack');
var path = require('path');
var fs = require('fs');
var deepMerge = require('deep-merge');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
// BEGIN CONFIG TOOLS
// Set up config merging function.
var merge = deepMerge(function(target, source, key) {
@jwietelmann
jwietelmann / router.ex
Created August 31, 2016 17:00
A rough sketch of a Phoenix router that uses an independent rendering service to create HTML from JSON views.
# This plug takes HTML requests, forwards them to our controllers as JSON
# requests, takes the resulting JSON and POSTs it to a rendering service,
# then transforms the response back into HTML using the output from the
# rendering service.
#
# Which means we can write our probably-JavaScript/React view layer
# independently of Phoenix tooling.
defmodule ServiceRenderer do
# Base URL of render service goes here.
def init(url) do
@jwietelmann
jwietelmann / walkReactComponentFiles.js
Created September 1, 2016 03:05
A hack to use `react-docgen` to iterate over all React component files in a directory tree.
'use strict'
const reactDocs = require('react-docgen')
const dir = require('node-dir')
export default function walkReactComponentFiles(path, pattern, handleFilename, done) {
const iterator = function(error, content, filename, next) {
if(error) {
throw error
}