Skip to content

Instantly share code, notes, and snippets.

View mkaraim's full-sized avatar

Michael Karaim mkaraim

  • Complex.com
  • New York
View GitHub Profile
/**
* Load a script asynchronously
* @param {string} src - url to the script you're trying to load
* @returns {Promise}
*/
function loadScript(src) {
return new Promise(function (resolve, reject) {
const script = document.createElement('script');
let ready = false;
<form method="POST"
action="https://form.io"
enctype="multipart/form-data"
onsubmit="return trackSubmit()">
</form>
<script>
function trackSubmit() {
ga('send', 'event', 'webform', document.title, 'SUBMIT button clicked');
return true;
@mkaraim
mkaraim / jquery-reverse-indices.js
Created January 7, 2020 18:46
jQuery Reverse Indices
/**
* Sets z-indices of reference's children in reverse order
* @param {Node} $slider
*/
function setZIndices($slider) {
const slideCount = $slider.children().length;
$slider.children().css('zIndex', function(i){
return slideCount - i;
});
}
@mkaraim
mkaraim / load-script-syncronously.html
Created December 13, 2019 20:40
Load a script syncronously on spot
<script>
var xhrObj = new XMLHttpRequest();
xhrObj.open('GET', "https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore.js", false);
xhrObj.send('');
var script = document.createElement('script');
script.type = "text/javascript";
script.text = xhrObj.responseText;
document.head.appendChild(script);
</script>
<!-- Trying it out -->
@mkaraim
mkaraim / header_is_set.php
Created November 6, 2019 17:26
Check whether a header is present in request
function header_is_set($header_name) {
if (!function_exists('getallheaders')) {
$headers = [];
foreach ($_SERVER as $name => $value) {
if (substr($name, 0, 5) == 'HTTP_') {
$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
}
}
@mkaraim
mkaraim / rssToJson
Created February 27, 2019 22:48 — forked from BilalBudhani/rssToJson
PHP function to convert simple RSS to JSON
public function Parse ($url) {
$fileContents= file_get_contents($url);
$fileContents = str_replace(array("\n", "\r", "\t"), '', $fileContents);
$fileContents = trim(str_replace('"', "'", $fileContents));
$simpleXml = simplexml_load_string($fileContents);
$json = json_encode($simpleXml);
return $json;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style id="jsbin-css">
#target {
background: cadetblue;
height: 20vh;