Skip to content

Instantly share code, notes, and snippets.

View mrsweaters's full-sized avatar
🥜

Jordan Humphreys mrsweaters

🥜
View GitHub Profile
@mrsweaters
mrsweaters / purdy.js
Last active December 24, 2015 00:39
Make percentages purdy. Whole numbers don't display decimals by default, will force defined decimal length for floats, all customizable.
var PurdyPercent = function (num, options) {
this.settings = {
hide_decimal_on_whole : true,
decimals : 2,
truncate : false, // (soon)
match_decimals: true, // forces floats to match defined decimal count
postfix : '%'
};
// helper methods
#!/bin/sh
# Output file for HTML5 video
# requirements: ffmpeg .6+
# usage: ./html5video.sh infile.mp4 640x360
target_directory='converted'
file=`basename $1`
filename=${file%.*}
filepath=`dirname $1`
@mrsweaters
mrsweaters / index.php
Created January 6, 2014 21:58
reveal issue with php server validation.
<!doctype html>
<html class="no-js" lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Foundation | Welcome</title>
<link rel="stylesheet" href="css/foundation.css" />
<link rel="stylesheet" href="css/app.css" />
<script src="js/modernizr.js"></script>
</head>
@mrsweaters
mrsweaters / csv_data_dump.rb
Created January 10, 2014 22:28
quick csv data dump from rails console
require 'csv'
file = "#{Rails.root}/public/users.csv"
userrefs = UserReference.where(:tenant_id => 7)
CSV.open( file, 'w' ) do |writer|
userrefs.each do |ur|
next unless ur.user.present?
writer << [ur.user.username, ur.user.email]
# SSL self signed localhost for rails start to finish, no red warnings.
# 1) Create your private key (any password will do, we remove it below)
$ openssl genrsa -des3 -out server.orig.key 2048
# 2) Remove the password
$ openssl rsa -in server.orig.key -out server.key
@mrsweaters
mrsweaters / SassMeister-input.scss
Created February 1, 2014 00:50
Generated by SassMeister.com.
// ----
// libsass (v0.7.0)
// ----
$namespace: false !default;
@function data($attr) {
@if $namespace {
@return '[data-' + $namespace + '-' + $attr + ']';
}
@mrsweaters
mrsweaters / object_key_matcher.js
Last active August 29, 2015 13:56
find match in object keys
function(attrs, exp) {
if (typeof attrs === 'object' && attrs !== null) {
var keys = Object.getOwnPropertyNames(attrs),
i = keys.length,
type = '';
while (i--) {
var attr = attrs[keys[i]];
if (typeof attr === 'object') {
@mrsweaters
mrsweaters / utf8.sql
Created March 3, 2014 18:40
convert mysql database to utf 8
ALTER DATABASE databasename CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE tablename CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
@mrsweaters
mrsweaters / backup_and_restore.sql
Created March 3, 2014 18:41
backup and restory mysql database
backup: # mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql
restore:# mysql -u root -p[root_password] [database_name] < dumpfilename.sql
@mrsweaters
mrsweaters / at_least_one.js
Created May 7, 2014 02:31
At least one checkbox checked.
$(document).on('valid', '[data-abide]', function () {
var vehicles = $('input:checked', this);
if (vehicles.length > 0) {
// post your form via ajax
} else {
// show custom error message.
}
});