Skip to content

Instantly share code, notes, and snippets.

View sam0x17's full-sized avatar

Sam Johnson sam0x17

View GitHub Profile
@sam0x17
sam0x17 / rails generate migration timestamp
Created March 4, 2015 20:54
Rails generate migration timestamp
Time.now.strftime("%Y%m%d%H%M%S")
@sam0x17
sam0x17 / smart_img_resize.inc.php
Last active December 22, 2015 00:48
The Ultimate Smart Image Re-sizing Routine. You provide the original image, and a desired width and/or height. This function will intelligently re-size the original image to fit, centered, within the specified dimensions. Either width or height can be omitted to have the re-size "lock" only on width or height. Fantastic for thumbnail generation.…
<?
function smart_img_resize($orig, $dest_width=null, $dest_height=null)
{
$orig_width = imagesx($orig);
$orig_height = imagesy($orig);
$vertical_offset = 0;
$horizontal_offset = 0;
if($dest_width == null)
{
@sam0x17
sam0x17 / pantheon terminal with login shell (for rvm)
Last active September 11, 2016 05:19
this bash script will run pantheon terminal as a login shell, so you can use rvm etc with pantheon-terminal
#!/bin/bash
pantheon-terminal . source ~/.bashrc
@sam0x17
sam0x17 / rebase and pull
Last active October 26, 2016 17:11
rebase and pull (update to upstream changes in git)
git pull --rebase origin master
@sam0x17
sam0x17 / force_ssl.js.coffee
Created November 29, 2016 15:15
force ssl on rails google app engine
index = window.location.href.indexOf('localhost')
index2 = window.location.href.indexOf('127.0.0.1')
if window.location.protocol != 'https:' && !(index > -1 || index2 > -1)
window.location.href = 'https:' + window.location.href.substring(window.location.protocol.length)
@sam0x17
sam0x17 / README.md
Last active January 24, 2017 17:43
ancestor UUID's

A UUID is a globally unique universal identifier. These are extremely useful in a CRM-like environment, because they can express descendant/ancestor relationships without the need to traverse a join chain of intermediate relationships. You can get everything "belonging" to a particular user/record/account/whatever in a single SELECT statement with no JOINS.

for every row in the database across ALL tables:

  • assign a database-wide unique UUID record.uuid
  • the first two digits of the UUID identify the table to which the record belongs
  • add an array field called ancestor_uuids containing the UUIDs of all ancestor records (up to Account)

so a Task record might have UUIDs for a RepeatingTask, User, and Account in its ancestor_uuids array

Now what can we do with this?

@sam0x17
sam0x17 / README.md
Created January 24, 2017 17:52
model flattening

The problem

CRM data is hierarchical, but RDBMSes are not. In a hierarchical system, deleting is as easy as deleting a single node. In an RDBMS, especially one with CRM data, this can be extremely difficult because there is a dense hierarchy of polymorphic relationships standing between you and the records you want to delete (or access!).

How to fix it

We need flat models!! This means that if there is a hierarchy of records, for example an Account has many Users, which each have many tasks, which in turn can have custom field values, then every single custom value record should have a task_id, a user_id, and an account_id ON THE RECORD. Even if custom field values are used on non-task tables, then the custom field values should simply have id's associated with those tables as well. For example if Projects can have custom field values,

@sam0x17
sam0x17 / cors_policy
Last active September 21, 2017 03:24
Allow all S3 CORS policy
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>HEAD</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>DELETE</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
# Configure touchpads to use xf86-input-synaptics X input driver
Section "InputClass"
Identifier "touchpad"
MatchIsTouchpad "on"
MatchDevicePath "/dev/input/event*"
Driver "synaptics"
Option "MinSpeed" "0.4"
Option "MaxSpeed" "1.0"
Option "AccelFactor" "0.0035"
@sam0x17
sam0x17 / cac.sh
Last active March 21, 2018 15:57
Ubuntu CAC Setup
#!/bin/bash
sudo apt-get update
sudo apt-get install -y libpcsclite1 coolkey pcsc-tools libpcsc-perl libccid pcscd libnss3-tools
sudo service pcscd start
curl http://militarycac.com/maccerts/AllCerts.zip > ~/DOD_Certs.zip
modutil -dbdir sql:/home/`whoami`/.pki/nssdb/ -add "CAC Module" -libfile /usr/lib/pkcs11/libcoolkeypk11.so