Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / fb-open-graph.liquid
Last active August 24, 2020 16:02 — forked from chrisjhoughton/fb-open-graph.liquid
Facebook Open Graph meta tags for Shopify. Add this as a snippet called "fb-open-graph.liquid" in your theme, and then add `{% render 'fb-open-graph' %}` to your `theme.liquid` file.
{% if template contains 'product' %}
<meta property="og:type" content="product">
<meta property="og:title" content="{{ product.title | strip_html | escape }}">
<meta property="og:category" content="{{ product.type }}" />
{% for image in product.images limit:3 %}
<meta property="og:image" content="http:{{ image.src | product_img_url: 'master' }}">
<meta property="og:image:secure_url" content="https:{{ image.src | product_img_url: 'master' }}">
{% endfor %}
<meta property="og:price:amount" content="{{ product.price | money_without_currency | stip_html | escape | remove: ',' }}">
<meta property="og:price:currency" content="{{ shop.currency }}">
@yemster
yemster / svg-ico-sprite-mixin.scss
Created March 1, 2017 09:39
Automate SVG Sprite Background Image Variations with a SCSS Mixin
/*
Automate SVG Sprite Background Image Variations with a SCSS Mixin
- see egghead.io video: https://egghead.io/lessons/css-automate-svg-sprite-background-image-variations-with-a-scss-mixin
• This utilises a sass mixing to generate the necessary code for the icons within the sprite
*/
$ico-width-default: 3em;
$ico-width-small: 2em;
$icons: plug, star, umbrella;

Are your Ruby HTTPS API calls secure?

Let's check:

2.0.0-p481 :001 > OpenSSL::SSL::SSLContext::DEFAULT_PARAMS
 => {:ssl_version=>"SSLv23", :verify_mode=>1, :ciphers=>"ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW", :options=>-2147482625}
2.0.0-p481 :002 > rating = JSON.parse(RestClient::Resource.new("https://www.howsmyssl.com/a/check" ).get)['rating']
 => "Bad"
<!DOCTYPE html>
<html>
<head>
<style>
/* How to select a range of children
* (Here, 3rd-7th children, inclusive):
*/
ul li:nth-child(n+3):nth-child(-n+7) {
outline: 1px solid #0f0;
}
@yemster
yemster / adequate-template-engine.js
Last active January 28, 2021 21:17
Adequate template engine - Minimalist but entirely more than adequate Js templating engine
/*****************************************
* Usage:
* engine = Adqt.TemplateEngine
* template = 'My name is <% this.name %>'
* hash = { name: 'Yemi' }
*
* compiled = engine.compile(template) // => "var r=[]; r.push("My name is "); r.push( this.name ); return r.join("");"
* engine.render(compiled, hash) // => My name is Yemi
*
* engine.render(compiled, { name: 'Mike' }) // => My name is Mike
@yemster
yemster / module-boilerplate.js
Created October 5, 2017 15:52
Snippet / boilerplate or starting new modules / library closures. --// Parked here until I find a better home for it
MyModule = MyModule || {}
MyModule.Foo = (function() {
// declare private methods
var _myPrivateMethod = function() {
console.log('\t >>>>> I am a private method call <<<<<<')
}
// expose public methods
return {
myPublicMethod: function(someArgs) {