Skip to content

Instantly share code, notes, and snippets.

View ksouthworth's full-sized avatar

Kevin Southworth ksouthworth

  • Web Ascender
  • Michigan, USA
View GitHub Profile
@ksouthworth
ksouthworth / ruby-vips-text-overlay.rb
Last active November 2, 2021 19:59
Ruby VIPS text overlay example
#!/usr/bin/ruby
require 'vips'
# $ ruby vips-overlay.rb [INPUT_FILE] [OUTPUT_FILE] [TEXT]
# $ ruby vips-overlay.rb [INPUT_FILE] [OUTPUT_FILE] [TEXT] [HEX_COLOR]
# $ ruby vips-overlay.rb vips-input.png vips-output.png "Your overlay text here" "#1c7cd8"
def hex_color_to_rgb_array(hex_color)
hex_color.match(/^#(..)(..)(..)$/)&.captures&.map(&:hex)
end
@ksouthworth
ksouthworth / form.html.haml
Last active February 6, 2019 02:55
SimpleForm Sticky Association Input
-# form.html.haml
= simple_form_for @project do |f|
-# normal SimpleForm association
= f.association :company
-# new and improved "sticky" association
= f.sticky_association :company
= f.input :name
= f.submit
@ksouthworth
ksouthworth / alloy.jmk.js
Last active September 2, 2015 20:20
Basic Theme support for Ti Alloy
/*
This custom JMK file hacks in some basic "Theme" support for this Alloy project
You can put .tss files under the app/styles/themes/ directory and they will be auto-injected
into the main app.tss file (at the end of the file)
It will also convert plain TSS style rules into "Custom Query Styles" so that the rules
in each theme file will only apply if that theme is "active" in the app.
http://docs.appcelerator.com/platform/latest/#!/guide/Alloy_Styles_and_Themes-section-35621526_AlloyStylesandThemes-CustomQueryStyles
@ksouthworth
ksouthworth / gist:a8e008b83cf089e57249
Last active August 29, 2015 14:04
Titanium Image Resizing : Comparing built-in BLOB methods vs Titanium "ImageFactory" module methods
var photoDir = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, "photos");
if(!photoDir.exists()) {
photoDir.createDirectory();
}
function takePhoto(e) {
// https://github.com/appcelerator-modules/ti.imagefactory
var ImageFactory = require('ti.imagefactory');
Ti.Media.showCamera({
@ksouthworth
ksouthworth / ruby-int-to-bcd.rb
Last active March 16, 2016 20:57
Ruby code to convert an Integer to a Binary Coded Decimal (BCD) array of bytes
# Convert an Integer to a "Packed" Binary Coded Decimal (BCD) formatted array of bytes
# http://en.wikipedia.org/wiki/Binary-coded_decimal
def int_to_bcd_bytes(int)
# BCD format takes each digit of an integer value and encodes it into a nibble (4 bits)
# It maintains the order of the original digits, so 15 would be 00010101
# Since we're dealing with nibbles, we have to zero-pad-left if the number has an odd number of digits
# Decimal digit Binary
# 0 0000
# 1 0001
# 2 0010
@ksouthworth
ksouthworth / refresh-all-sql-views.sql
Last active September 28, 2015 22:37
Refresh all SQL Views in database
DECLARE @view AS VARCHAR(255) ;
DECLARE ListOfViews CURSOR FOR
SELECT TABLE_SCHEMA + '.' +TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'VIEW'
AND OBJECTPROPERTY(OBJECT_ID(TABLE_NAME), 'IsMsShipped') = 0
ORDER BY TABLE_SCHEMA,TABLE_NAME