Skip to content

Instantly share code, notes, and snippets.

View Stenerson's full-sized avatar

Matt Stenerson Stenerson

  • eMenuCHOICE
  • Minneapolis
View GitHub Profile
@Stenerson
Stenerson / html.json
Created October 17, 2023 14:49
PHP Short Tag Snippets for VS Code
{
"<?php If ... endif": {
"prefix": "pif",
"body": [
"<?php if (${1:condition}): ?>",
"\t${0:<!-- code here -->}",
"<?php endif; ?>"
],
"description": "If endif block inside HTML"
},
@Stenerson
Stenerson / call-ssl-deploy-hook
Created November 5, 2019 18:57
Certbot post deploy hook to safely copy certificates into web application directory
#!/bin/bash
bash /path/to/ssl-deploy-hook -d example.com -p "NEW-PASSPHRASE-FOR-CERTIFICATE-PRIVATE-KEY"
# Example Crontab
# 36 2,14 * * * root /opt/certbot-auto -q renew --deploy-hook /path/to/call-ssl-deploy-hook # this script
@Stenerson
Stenerson / ASimpleHowlerButton.js
Last active November 9, 2018 22:45
A basic button that will control a ReactHowler instance
<HowlerButton
className="btn btn-inverse"
src={`assets/audio/${fileName}`}
/>
@Stenerson
Stenerson / ReceiptPrint.php
Created October 13, 2016 17:50
Using escpos-php with Code Igniter (2x)
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
// IMPORTANT - Replace the following line with your path to the escpos-php autoload script
require_once __DIR__ . '\..\..\autoload.php';
use Mike42\Escpos\PrintConnectors\NetworkPrintConnector;
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
use Mike42\Escpos\Printer;
class ReceiptPrint {
@Stenerson
Stenerson / gist:8a92463ec2813d258f52
Last active August 29, 2015 14:23 — forked from thijsc/gist:1391107
Select item from chosen js select with Capybara 2+ and Selenium
def select_from_chosen(item_text, options)
field = find_field(options[:from], visible: false)
option_value = page.evaluate_script("$(\"##{field[:id]} option:contains('#{item_text}')\").val()")
page.execute_script("value = ['#{option_value}']\; if ($('##{field[:id]}').val()) {$.merge(value, $('##{field[:id]}').val())}")
option_value = page.evaluate_script("value")
page.execute_script("$('##{field[:id]}').val(#{option_value})")
page.execute_script("$('##{field[:id]}').trigger('liszt:updated').trigger('change')")
end
def select_from_chosen(item_text, options)
field = find_field(options[:from])
option_value = page.evaluate_script("$(\"##{field[:id]} option:contains('#{item_text}')\").val()")
page.execute_script("$('##{field[:id]}').val('#{option_value}')")
end
@Stenerson
Stenerson / Class_Utility.php
Created April 7, 2015 16:17
PHP Public Methods
<?php
class Class_Utility {
// Echoes headings for each class with an unordered list of public methods
public static function echo_subclasses_and_methods($parent, $exclude_classes = null, $exclude_methods = null)
{
// Loop through results to echo "pretty" output
foreach (static::get_subclasses_and_methods($parent, $exclude_classes, $exclude_methods) as $class) {
echo "<h2>".$class['name']."</h2>";
@Stenerson
Stenerson / seeds.rb
Last active August 29, 2015 13:55
How I do seeds (circa 2013)
# Running Seeds
# From console (for development/production environmnts)
# $ rake db:seed
# Seeding tests (rspec)
# Create helper method
def load_seed_data
load "#{Rails.root}/db/seeds.rb"
end
@Stenerson
Stenerson / gist:8726239
Created January 31, 2014 03:36
My most proud ruby method so far. A method to find the candidates that a user needs to take action on. Probably makes no sense without context - too bad.
def candidate_queue
self.campaigns.collect do |x|
x.candidates.select {|y| y.owners.compact.include?(self) }
end.flatten.sort! {|a,b| a.updated_at <=> b.updated_at }
end
@Stenerson
Stenerson / gist:7969619
Created December 15, 2013 06:19
I'm storing user roles as integers but I don't have a table yet stating what a role means. For now it's just being kept in the user model. I needed a (non localized) string saying what the user's role was. I thought the case method was too ugly so I went this direction instead.
# u = User.first
# u.role_id # => 1
# Desired output
# u.role # => "Administrator"
# Obvious implementation
def role
case self.role_id
when 1