Skip to content

Instantly share code, notes, and snippets.

@zyphlar
zyphlar / googlevisualr-helper.rb
Created July 11, 2012 23:14
Helper and model methods for creating GoogleVisualr charts
# This is a Rails helper for generating a single chart for a column from a data set.
# blood_tests is the data set, and column_name is the column from the set to use.
# It calls generate_chart_row for each record, passing the column_name argument.
# It also does some stuff with vertical axis labels and chart options.
def generateChart(blood_tests, column_name)
data_table = GoogleVisualr::DataTable.new
<?php
// Public variables -- CONFIGURE ME
$dbname = "exampledb";
$dbuser = "exampleuser";
$dbpass = "examplepassword";
// Connect to MySQL using PDO
try {
$dbh = new PDO('mysql:host=localhost;dbname='.$dbname, $dbuser, $dbpass);
}
@zyphlar
zyphlar / led_sign_rs232_protocolized.ino
Created August 10, 2012 17:46
Arduino code for SkyMotion Mark IV 16x72 RS232 LED matrix sign
#include <SoftwareSerial.h>
uint8_t la[8]={0x00,0x7c,0x44,0x44,0x7c,0x44,0x00,0x00};
uint8_t lb[8]={0x00,0x7c,0x44,0x78,0x44,0x7c,0x00,0x00};
uint8_t lc[8]={0x00,0x7c,0x40,0x40,0x40,0x7c,0x00,0x00};
uint8_t ld[8]={0x00,0x78,0x44,0x44,0x44,0x78,0x00,0x00};
uint8_t le[8]={0x00,0x7c,0x40,0x78,0x40,0x7c,0x00,0x00};
uint8_t lf[8]={0x00,0x7c,0x40,0x70,0x40,0x40,0x00,0x00};
uint8_t lg[8]={0x00,0x7c,0x40,0x4c,0x44,0x7c,0x00,0x00};
uint8_t lh[8]={0x00,0x44,0x44,0x7c,0x44,0x44,0x00,0x00};
@zyphlar
zyphlar / form-field-json-cookies.js
Created October 4, 2012 07:08
Storing & retrieving form fields in a JSON cookie
/* Storing & retrieving form fields in a JSON cookie
* copyright Will Bradley, 2012, released under a CC-BY license
*
* Change all instances of "myform" as necessary.
* Cookie will be stored under the current URL, but
* it won't include any hidden fields, etc.
*/
function setCookie(c_name,value,expireminutes)
{
@zyphlar
zyphlar / getfees.py
Created October 11, 2012 08:00
Get Fees - for accounting for PayPal fees properly in QuickBooks
#!/usr/bin/python
# Get Fees - for accounting for PayPal fees properly in QuickBooks
# Originally Written by Jose Diaz for HYPOXIC
# Distributed by Will Bradley (will@zyphon.com) under a CC-BY license.
#
# To use, change the "Pay Pal Account" value towards the bottom of the file
# to the name of the Quickbooks account you want PayPal feeds to go into.
#
# Run this Python script with the filename of the PayPal .iif file to use,
# and redirect its output to a file. Example: getfees.py > fees.iif
# TODO: http://gallery.technet.microsoft.com/scriptcenter/Outputs-directory-size-964d07ff
http://gallery.technet.microsoft.com/scriptcenter/Delete-files-older-than-x-13b29c09
http://gallery.technet.microsoft.com/scriptcenter/d81d620c-0d1b-4b7a-9c85-13660e929750
http://www.tek-tips.com/viewthread.cfm?qid=1687849
http://www.tek-tips.com/viewthread.cfm?qid=954944
## VBS:
On Error Resume Next
folderPath = "C:\windows"
@zyphlar
zyphlar / zendesk-report-mailer.php
Created February 5, 2013 23:02
Report Mailer for the ZenDesk API
<?php
// This script pulls two reports from ZenDesk and optionally emails them.
// Search for all instances of YOUR_ in this document and replace them.
// Uncomment the email-related lines at the bottom to enable sending emails.
// Copyright (c) 2012, Will Bradley, will@zyphon.com
// All rights reserved.
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
// Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
// Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
@zyphlar
zyphlar / pull_defaults.rb
Last active December 15, 2015 06:29
Gets default values from I18n.t() methods, replaces them, and outputs them in yml. In order to actually REMOVE :defaults from the files, uncomment the replace_content_of_file_with_i18n_queries line.
#!/usr/bin/env ruby
#NOTE: Must use Ruby 1.9+ and not 1.8.7.
# USAGE:
# Run and redirect output to a file for best results.
# example: ruby pull-defaults.rb > my-results.yml
# For now, you'll have to add the root en: element and increase
# the indent level for it to be a valid locale YML.
# Uncomment lines 160 and 161 (the ones that call
# replace_content_of_file_with_i18n_queries) to have this
Input: ["en.subnets.show.&nbsp"]
Output: {"en"=>{"subnets"=>{"show"=>{"&nbsp"=>{}}}}}
def hashify(strings)
strings.map { |s| s.split('.') }.each_with_object({}) do |segmented_string, h|
segmented_string.each do |segment|
h[segment] ||= {}
h = h[segment]
end
end
@zyphlar
zyphlar / dt-rails.sublime-snippet
Last active December 15, 2015 06:49
Sublime snippets to assist with replacing text with i18n symbols and methods. ruby-i18n is for inline ruby, ruby-erb-i18n is the same except with erb syntax, and dt-rails is for turning something like <%= show(@foo, :bar) %> into <dt><%= :bar %></dt><dd><%= @foo.bar %></dd>
<snippet>
<content><![CDATA[
<dt><%= ${1:${SELECTION/.*?(:\w*).*/$1/}} %></dt>
<dd><%= ${2:${SELECTION/.*?(@\w*).*?:(\w*).*/$1.$2/}} %></dd>
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>dt-</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>text.html.ruby</scope>
</snippet>