Skip to content

Instantly share code, notes, and snippets.

@yemster
yemster / svg-image-replacer.js
Created October 20, 2016 11:13
SVG IMG replacer: Replace a given IMG linking to an SVG file with the actual SVG file injected into the page.
// Extract and inject SVG logo into document
$(document).ready(function() {
$('img[src*=".svg"]').each(function() {
var $img = jQuery(this), $svg,
imgURL = $img.attr('src').replace(/\.svg(\?\w+)/,'.svg'), // strip timestaps from img URL
imgAttributes = $img.prop("attributes");
$.get(imgURL, function(data) {
$svg = jQuery(data).find('svg'); // Get the SVG tag, ignore the rest
$svg = $svg.removeAttr('xmlns:a'); // Remove any invalid XML tags
@yemster
yemster / random-string.js
Last active June 26, 2019 15:46
Random string generator in Javascript / nonce generator
/*
Generate a random string of a given length.
@params:
length: *required* - length of string to generate
kind: *optional* - character set or sets to use for string generation (default: 'aA#')
Available options
'a' => for lowercase alphabets [a-z]
'A' => for uppercase alphabets [A-Z]
'#' => numbers [0-9]
'!' => special character as defined
@yemster
yemster / jqueryLoader.html
Last active September 8, 2016 09:06
jQuery loader for a widget/embed container. Boilerplate for building a web widget that is dependent on jQuery * Checks to see if a specific version of jQuery already present on the host page If present and regEx matches our target version, we use it - ala `window.jQuery` If not, a specific version is downloaded from CDN and added ala jquery no c…
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Script loader</title>
<!-- Comment out next line to test "jquery missing on page" scenario -->
<!-- <script type="text/javascript" src="https://code.jquery.com/jquery-1.11.2.min.js"></script> -->
<!-- <script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.min.js"></script> -->
</head>
<body>
@yemster
yemster / dedecimalised-integers.rb
Created August 13, 2016 10:34
Dedecimalised whole numbers in ruby - This extends and overrides ruby core `BigDecimal#to_s`. Caution: Don't do this - bad things begin to happen very quickly in other gems and third part addons PS: If must be used, use with extreme caution as this behaviour will likely cause issues and incompatibility with other libraries.
# Extends Ruby BigDecimal class so we have an updated to_s method that returns numbers witheout the ZERO at the end
# if the number is an integer.
# e,g. '12.0'.to_s => 12
# '9.23'.to_s => 9.23
class BigDecimal
alias_method(:original_to_s, :to_s) unless method_defined?(:original_to_s)
def is_whole_number?
self % 1 == 0
@yemster
yemster / installing-imagemagick-ec2
Last active November 3, 2020 19:19
Installing or updating ImageMagick on EC2 Linux AMI
# ******************
# *** FYI :: This turned out to be the missing link in the process *****
# Install the devel packages for png, jpg, tiff. these are dependencies of ImageMagick
# Time taken: ~ 3secs
# ******************
sudo yum -y install libpng-devel libjpeg-devel libtiff-devel
# ******************
# Download and Install Imagemagick
@yemster
yemster / form-attribute_fallback.js
Created May 17, 2016 10:05
Backward compartibility of HTML 5 form-attribute submissions
E.g.
$('.js-show-spinner').click(function() {
var $saveButton = $(this)
$saveButton.html($('<div>').addClass('loader'))
setTimeout(function() { $('#' + $saveButton.attr('form')).submit(); })
return false
})
@yemster
yemster / share-tool-lite.html
Created May 13, 2016 15:05
Lightweight share tool snippet for specific services
<script type="text/javascript">
// Create pop-up box to sharing destination
popOutSharer(t){
var e=600,
n=screen.width;
n>e&&(n=e);
var i=window.open(t,"name","height=200,width="+n);
return window.focus&&i.focus(),!1
}
// MINIFIED version :: popOutSharer(t){var e=600,n=screen.width;n>e&&(n=e);var i=window.open(t,"name","height=200,width="+n);return window.focus&&i.focus(),!1}
@yemster
yemster / 0_reuse_code.js
Created May 12, 2016 10:21
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@yemster
yemster / schema_format.rake
Created March 17, 2016 10:22 — forked from vjt/schema_format.rake
Rails SQL schema load support for PostgreSQL. Put both files in `lib/tasks`.
import File.expand_path(File.dirname(__FILE__) + '/schema_format.rb')
namespace :db do
# Define PG environment utility methods
task :pg_env => :environment do
def pg_get_config
ActiveRecord::Base.configurations.fetch(Rails.env).tap do |config|
ENV['PGHOST'] = config['host'].to_s if config.key?('host')
ENV['PGPORT'] = config['port'].to_s if config.key?('port')
ENV['PGPASSWORD'] = config['password'].to_s if config.key?('password')
@yemster
yemster / metatags.html
Created November 10, 2015 09:57 — forked from itsbalamurali/metatags.html
18 Meta Tags Every Webpage Should Have in 2013
<title>Up to 70 Characters of Keyword-relevant text here</title>
<meta name=”description” content=”155 characters of message matching text with a call to action goes here”>
<meta name="author" content="" />
<meta name="copyright" content="&copy;" />
<link rel=”author” href=”https://plus.google.com/[YOUR PERSONAL G+ PROFILE HERE]“/>
<meta property=”og:title” content=”iAcquire’s awesome blog”/>
<meta property=”og:type” content=”article”/>
<meta property=”og:image” content=”http://www.iacquire.com/some-thumbnail.jpg”/>
<meta property=”og:url” content=”http://blog.iacquire.com”/>
<meta property=”fb:admins” content=”USER_ID”/>