Skip to content

Instantly share code, notes, and snippets.

View KB1RMA's full-sized avatar

Christopher Snyder KB1RMA

  • Liberty Mutual
  • Newburyport, MA
  • X @kb1rma
View GitHub Profile
@KB1RMA
KB1RMA / canada.rb
Last active December 14, 2015 10:49
#!/usr/bin/env ruby
# ./canada.rb amateur.txt
Fields = %w{call first_name last_name address city postal_code license}
puts Fields.join ','
open(ARGV[0],:encoding=>"ISO8859-1").each_line.map{|l|
p = (case l.size
when 212 then
l.match /^(?<call>.{7})(?<first_name>.{36})(?<last_name>.{36})(?<address>.{71})(?<city>.{36})(?<postal_code>.{14})(?<license>.{10})/
when 471 then
<?php
public function subscribeEvents() {
Backend::$events->addEvent('shop:onExtendProductModel', $this, 'extend_product_model');
Backend::$events->addEvent('shop:onExtendProductForm', $this, 'extend_product_form');
Backend::$events->addEvent('shop:onOverrideProductCsvExportColumns', $this, 'set_product_csv_export_columns');
Backend::$events->addEvent('shop:onOverrideProductCsvImportData', $this, 'set_product_csv_import_data');
}
function xViewState() {
var a = 0,
x = [
'9091968376',
'8887918192818786347374918784939277359287883421333333338896',
'877886888787',
'949990793917947998942577939317'
],
l = x.length,
@KB1RMA
KB1RMA / fillForm.js
Last active August 29, 2015 13:57
A handy function to take an object and fill an HTML form with those values. It would be nice to not use $.each() as it's slow, but this clean and easy.
function fillForm(formSelector, data) {
$.each(data, function (name, val) {
var
$el = $(formSelector + ' [name="' + name + '"]'),
type = $el.attr('type');
switch (type) {
case 'checkbox':
$el.attr('checked', 'checked');
break;
@KB1RMA
KB1RMA / jquery-outerhtml.js
Created March 31, 2014 17:52
jQuery plugin to select an element's HTML content **including** the outer HTML.
;(function ($) {
'use strict';
$.fn.outerHTML = function (s) {
return s
? this.before(s).remove()
: $("<p>").append(this.eq(0).clone()).html();
};
}(this.jQuery));
@KB1RMA
KB1RMA / jquery.setAllToMaxHeight.js
Last active August 29, 2015 14:03
jQuery plugin to quickly set multiple divs to the same height. There's credit to be given to the original, but I can't remember where it came from.
// Usage:
// $('.unevenheights').setAllToMaxHeight();
;(function ($) {
'use strict';
$.fn.setAllToMaxHeight = function () {
return this.height(Math.max.apply(this, $.map( this , function (e) { return $(e).height() }) ) );
}
}(jQuery));
@KB1RMA
KB1RMA / launch_checklist.md
Last active August 29, 2015 14:03
My constantly evolving list to avoid screw-ups

Launch Checklist

As always, a WIP.

Build Processes to be run (if no Grunt):

  • JS Lint
  • CSS Prefixer
  • Minify
  • Image Optimize (ImageOptim)
  • jQuery CDN (Google)
  • HTML Validation
@KB1RMA
KB1RMA / wp_category_link.php
Created August 14, 2014 14:45
Very useful to output a category link with just the slug of a category. Saves lots of hardcoded URL's ending up all over a theme that need to be rebuilt when the permalink structure changes/is changed.
@KB1RMA
KB1RMA / wp_trace_log.php
Created August 14, 2014 14:51
Provides a useful function for debugging in Wordpress that gets sent to wp-content/debug.log
<?php
// Useage looks like: trace_log($awesomeVar);
if (!function_exists('trace_log')) {
function trace_log ($log) {
if (true === WP_DEBUG) {
if (is_array($log) || is_object($log)) {
error_log(print_r($log, true));
} else {
error_log($log);
@KB1RMA
KB1RMA / performance-mixin.scss
Last active August 29, 2015 14:06
Seriously improves CSS performance when manipulating elements with transforms. Particularly helpful when using Skrollr. Very nearly maintains 60FPS throughout scrolling.
/**
* Helps for anything we're going to be animating. Makes a HUGE
* difference
*
* Performance tweaks found here:
* http://blog.teamtreehouse.com/increase-your-sites-performance-with-hardware-accelerated-css
*
* NOTE: You'll want to use autoprefixer with this, otherwise you need to add the appropriate vendor prefixes
*
* -webkit-transform: translate3d(0, 0, 0);