Skip to content

Instantly share code, notes, and snippets.

View crftr's full-sized avatar

Mike Herrera crftr

View GitHub Profile
@crftr
crftr / no_frills_cms_adapter.html
Created July 9, 2024 12:52
Pull in and display extra content on a webpage without having to reload the whole page. It's handy for keeping things updated and flexible by loading bits of HTML from other places on the fly.
<div id="landingpageContent"></div>
<script>
fetch("{{htmlFragmentUrl}}")
.then(response => response.text())
.then(html => {
const range = document.createRange();
range.selectNode(document.getElementById('landingpageContent'));
const documentFragment = range.createContextualFragment(html);
document.getElementById('landingpageContent').appendChild(documentFragment);
@crftr
crftr / SuiteCommerce Advanced Dev bookmarklet.js
Last active January 3, 2024 23:01
When developing a SuiteCommerce Advanced site, it's nice to browse against the local version of code. This browser bookmarklet will add the "-local" to the current URL.
javascript: (function () {
var locationStr = window.location.toString(),
shopping = SC.SESSION.touchpoints.viewcart.replace(
"goToCart",
"shopping-local"
);
if (/-local.ssp/.test(locationStr)) {
window.location = locationStr.replace("-local.ssp", ".ssp");
} else if (/(my_account|checkout).ssp/.test(locationStr)) {
window.location = locationStr.replace(".ssp", "-local.ssp");
@crftr
crftr / haversineEarthDistance.js
Last active October 5, 2021 21:43
Calculate the distance between two latitude/longitude coordinate pairs using the haversine formula.
/* By default this will return the distance in kilometers, but will return
* miles when the inMiles argument is true.
*/
function haversineEarthDistance(lat1, lon1, lat2, lon2, inMiles) {
function toRads(x) { return (x * Math.PI) / 180; }
var EARTH_RADIUS_KM = 6373;
var KM_PER_MI = 1.609344;
var dLat = toRads(lat2 - lat1);
@crftr
crftr / openssl_tls_1.2.patch
Last active April 9, 2021 13:14 — forked from maxjustus/openssl_tls_1.2.patch
Source patch to add support to TLS 1.1 and 1.2 to Ruby 1.9.3
diff --git a/ext/openssl/ossl_ssl.c b/ext/openssl/ossl_ssl.c
--- a/ext/openssl/ossl_ssl.c
+++ b/ext/openssl/ossl_ssl.c
@@ -107,6 +107,18 @@
OSSL_SSL_METHOD_ENTRY(TLSv1),
OSSL_SSL_METHOD_ENTRY(TLSv1_server),
OSSL_SSL_METHOD_ENTRY(TLSv1_client),
+#if defined(HAVE_TLSV1_2_METHOD) && defined(HAVE_TLSV1_2_SERVER_METHOD) && \
+ defined(HAVE_TLSV1_2_CLIENT_METHOD)
+ OSSL_SSL_METHOD_ENTRY(TLSv1_2),
@crftr
crftr / sum_to.rb
Last active August 29, 2015 14:21
Given an array of numbers, find what operations will evaluate to a target value.
#
# www.reddit.com/r/programming/comments/358tnp/five_programming_problems_every_software_engineer/
#
# THE 5TH EXERCISE:
#
# Write a program that outputs all possibilities to put + or - or nothing between
# the numbers 1, 2, ..., 9 (in this order) such that the result is always 100.
# For example: 1 + 2 + 34 – 5 + 67 – 8 + 9 = 100.
#
@crftr
crftr / PowerShell Local Shutdown.ps1
Created May 14, 2012 21:54
For when you want to easily schedule a local shutdown. e.g. a windows sleep timer. This is a simple UI to assist.
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = "Shutdown Timer"
$objForm.Size = New-Object System.Drawing.Size(300,200)
$objForm.StartPosition = "CenterScreen"
$objForm.KeyPreview = $True
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Enter")