Skip to content

Instantly share code, notes, and snippets.

View jasonhofer's full-sized avatar

Jason Hofer jasonhofer

  • Sarnia, Ontario
View GitHub Profile
const init = new function () {
let funcs = [],
booted = 0,
doc = document,
ready = fn => {
'loading' === doc.readyState ?
doc.addEventListener('DOMContentLoaded', fn) :
fn();
};
!(function () {
// Allow: <!--{ fullName }-->
// Instead of: <!-- ko text: fullName --><!-- /ko -->
// See: https://knockoutjs.com/documentation/binding-preprocessing.html
ko.bindingProvider.instance.preprocessNode = function (node) {
if (node.nodeType !== Node.COMMENT_NODE) {
return;
}
const match = node.nodeValue.match(/^[{](.*)[}]$/);
// Originally from https://github.com/ebryn/rsvp-ajax
RSVP.ajax = {
_ajax: function (url, type, params, data) {
var promise = new RSVP.Promise(),
xhr = new XMLHttpRequest();
if (params) { url = url + '?' + $.param(params); }
xhr.onreadystatechange = function (event) {
/*
<head>
<style id="antiClickjack">body {
display: none !important;
}</style>
<script type="text/javascript">
if(self === top) {
var antiClickjack = document.getElementById("antiClickjack");
antiClickjack.parentNode.removeChild(antiClickjack);
} else {
top.location = self.location;
<!doctype html>
{% block html_tag %}<html lang="{% block lang 'en' %}">{% endblock %}
<head>
<meta charset="{% block charset 'utf-8' %}">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>{% block title '' %}</title>
<meta name="description" content="{% block description '' %}">
<meta name="viewport" content="width=device-width, initial-scale=1">
{% block head %}{% endblock %}
<!doctype html>
{% block html_tag -%}
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="{% block lang 'en' %}"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="{{ block('lang') }}"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9" lang="{{ block('lang') }}"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="{{ block('lang') }}"> <!--<![endif]-->
{%- endblock %}
<head>
<meta charset="{% block charset 'utf-8' %}">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<?php
/**
* Resolves a path just like realpath(), except the file or directory does not have to exist.
*
* Works for Unix-based and Windows systems.
*
* @param string $path
* @param string $ds This is only here to make testing easier.
*
* @return string
@jasonhofer
jasonhofer / simple-http-kernel.php
Last active July 21, 2021 17:22
A simplified version of the Symfony HttpKernel to help show what it does.
<?php
use Psr\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation as Http;
/**
* HttpKernel: "Get the response, and get out."
*
* As soon as the kernel gets its hands on a Response object, it says "I'm done" and returns it.
* It is only interested in finding a Response object, at which point it will call it a day.
Ember.Object.keys = function (obj) {
if (!(obj instanceof Ember.Object)) {
return Object.keys(obj);
}
if (obj instanceof DS.Model) {
return Object.keys(obj.toJSON());
}
let constructor = obj.constructor,
objectKeys = [],
rx = /^[a-z][a-z0-9_]*$/i;
@jasonhofer
jasonhofer / symfony-bare.php
Last active June 22, 2018 18:24
An example of using the core Symfony components outside of a framework.
<?php
//
// Symfony Bare
//
// php -S localhost:8181 symfony-bare.php
//
// http://localhost:8181/is-leap-year
//
require_once 'vendor/autoload.php';