Skip to content

Instantly share code, notes, and snippets.

View mildfuzz's full-sized avatar

John Farrow mildfuzz

View GitHub Profile
$.fn.validateImageUpload = function(size){
//Accepts form file input fields $('input[type=file]').validateImageUpload();
//Also accepts size validation (in K), default is 700. Set to false in order to skip check
if(typeof size != "number" && size%1 != 0){size = 700}
var validate = function(x){
var files = $(x).get(0).files, that = x;
for (i = 0; i < files.length; i++){
if(!files[i].type.match(/(gif|jpg|JPG|jpeg|JPEG|gif|GIF|png|PNG)/)){
alert('Must be an image file.');
@mildfuzz
mildfuzz / Load jQuery bookmarklet
Created October 19, 2012 09:24
Load the lastest 1.x version of jQuery into any webpage
javascript:(function()%7Bif(typeof%20jQuery%20%3D%3D%20'function')%7Bdelete%20jQuery%3B%7Dvar%20newscript%20%3D%20document.createElement('script')%3Bnewscript.type%20%3D%20'text%2Fjavascript'%3Bnewscript.async%20%3D%20true%3Bnewscript.src%20%3D%20'https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fjquery%2F1%2Fjquery.min.js'%3B(document.getElementsByTagName('head')%5B0%5D%7C%7Cdocument.getElementsByTagName('body')%5B0%5D).appendChild(newscript)%3B%7D)()%3B
@mildfuzz
mildfuzz / max_length.js
Created November 2, 2012 11:30
Ensures a max length is adhered to in older browsers
var textareas = document.getElementById('user_summary');
for (var i = textareas.length; i--;) {
if (textareas[i].getAttribute('maxlength') && !textareas[i].maxlength) {
var max = textareas[i].getAttribute('maxlength');
textareas[i].onkeypress = function(event) {
var k = event ? event.which : window.event.keyCode;
if(this.value.length >= max) if(k>46 && k<112 || k>123) return false;
}
}
String.prototype.recursiveReplace = function(a,b){
var newString = this;
while(newString.match(a) !== null){newString = newString.replace(a,b);}
return newString;
};
@mildfuzz
mildfuzz / plugins.js
Last active October 12, 2015 13:58
Mild Fuzz Plugins
/*
JS Extentions by Mild Fuzz
*/
(function(){
//Adds sum functionality to the Array object
Array.prototype.sum = function(){
@mildfuzz
mildfuzz / mfBehaviours.js
Last active October 12, 2015 14:07
Behaviour Manager
/* Store for localised behaviours
*
* Requires jquery and Mild Fuzz's plugins.js (http://goo.gl/MVcH2)
* @mildfuzz
*
* Usage
*
* Create behaviour within case:
* case "BehaviourString":
* //some function
@mildfuzz
mildfuzz / helperjs.scss
Created November 12, 2012 11:56
Mild Fuzz JS Helpers
//Requires Compass
.cover_slide{
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
z-index: 9999;
@mildfuzz
mildfuzz / paperclip_help.rb
Created November 15, 2012 11:00
Paperclip File Size Help
has_attached_file :photo,
:styles => {
:tiny => "100x100", # fixed width and height
:thumb => "100>x100", # resize to a fixed width if original height if greather than specified
# dimension and fixed height
:small => "200x200>", # fixed width and resize to a fixed height if original height i greather than
# specified dimension
:medium => "200 "200x200<" # fixed width and resize to a fixed heigth if original height i less
# than specified dimension
}
@mildfuzz
mildfuzz / admin-users.rb
Created November 21, 2012 09:15
User Admin
ActiveAdmin.register User do
filter :first_name
filter :last_name
filter :company_name
filter :email
form do |f|
f.inputs "Contact" do
f.input :first_name
@mildfuzz
mildfuzz / scopes.rb
Created November 30, 2012 09:56
Example Rails 3 Scopes for reference
scope :scope, where("column=value")
scope :scope_with_input, lambda { |value| where("column =?", value)}
scope :cope_with_join_and_input, lambda { |value| joins(:other_table).where("other_table.other_table_column =?", value)}