Skip to content

Instantly share code, notes, and snippets.

View jasonhofer's full-sized avatar

Jason Hofer jasonhofer

  • Sarnia, Ontario
View GitHub Profile
@jasonhofer
jasonhofer / CrudRepository.js
Last active October 5, 2021 14:02
Svelte/Sapper project files.
import isEmpty from 'lodash/isEmpty';
/* import isValidObjectId from 'Utils/isValidObjectId'; */
/* import matchByIdOr from 'Utils/matchByIdOr'; */
/**
* Assumes you are using Mongoose.
*/
export default class CrudRepository
{
#ModelClass;
@jasonhofer
jasonhofer / router.js
Last active April 4, 2019 16:52
CC Certified
import EmberRouter from '@ember/routing/router';
import config from './config/environment';
const Router = EmberRouter.extend({
location: 'none',
rootURL: config.rootURL
});
Router.map(function() {
<?php
/**
* Show a status bar in the console.
*
* <code>
* for ($x = 1; $x <= 100; ++$x) {
* show_status($x, 100);
* usleep(100000);
* }
* </code>
jQuery.fn.dataBind = function (bindings) {
if (this.length) {
var pairs = [];
for (var name in bindings) {
if (bindings.hasOwnProperty(name)) {
pairs.push(name + ': ' + bindings[name]);
}
}
this.attr('data-bind', pairs.join(', '));
}
@jasonhofer
jasonhofer / classnames.php
Last active July 13, 2018 21:26
PHP port of classnames.js
<?php
/**
* PHP port of https://github.com/JedWatson/classnames
*
* Examples:
* <code>
* classnames('foo', 'bar'); // "foo bar"
* classnames('foo', ['bar' => true]); // "foo bar"
* classnames(['foo-bar' => true]); // "foo-bar"
@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';
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 / 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.
<?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
<!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">