Skip to content

Instantly share code, notes, and snippets.

View Integralist's full-sized avatar
🎯
Making an impact

Mark McDonnell Integralist

🎯
Making an impact
View GitHub Profile
@Integralist
Integralist / 1. Simplest Rack server.rb
Last active February 3, 2025 23:51
Rack Server Example
run lambda { |env| [200, {"Content-Type"=>"text/html"}, ["Hello World"]] }
@yocontra
yocontra / gulpfile.js
Last active January 1, 2016 00:29
gulpfile for a simple livereload static web server. this is a proof of concept that uses no plugins to do the work. obviously there are plugins that eliminate almost all of this code but i thought it would be a fun demonstration. this will trigger livereload any time any file is modified in the current working directory. it also serves the curre…
var gulp = require('gulp');
var gutil = require('gulp-util');
var express = require('express');
var path = require('path');
var tinylr = require('tiny-lr');
var createServers = function(port, lrport) {
var lr = tinylr();
lr.listen(lrport, function() {
gutil.log('LR Listening on', lrport);
@Integralist
Integralist / 1. WindowMock.js
Last active November 9, 2020 20:51
Mocking the `window` object in JavaScript unit tests
define([
'module/bootstrap', // this is jQuery and PubSub libs
], function (lib) {
var windowMock = {
resizeSet: false, // set within the fake `lib` object below
createFakeWindow: function(width, height) {
return {
document: {
documentElement: {
@Integralist
Integralist / rules for good testing.md
Last active March 5, 2025 21:19
Sandi Metz advice for writing tests

Rules for good testing

Look at the following image...

...it shows an object being tested.

You can't see inside the object. All you can do is send it messages. This is an important point to make because we should be "testing the interface, and NOT the implementation" - doing so will allow us to change the implementation without causing our tests to break.

@Integralist
Integralist / typeCheck.js
Last active December 27, 2015 15:59
JavaScript: function to determine object's type
var type = function (o) {
// handle null in old IE
if (o === null) {
return 'null';
}
// handle DOM elements
if (o && (o.nodeType === 1 || o.nodeType === 9)) {
return 'element';
@Integralist
Integralist / Grid.scss
Created August 13, 2013 15:23
Sass mixin that handles span'ing content based off of a 12 column grid (could be updated to accept dynamic content)
/* =============================================================================
Creates vendor-prefixed CSS declaration blocks in one go
Example usage:
@include vendor(box-sizing, border-box);
Notes:
Majority of the usage will be a basic property (that needs to be prefixed)
followed by a corresponding value.
@Integralist
Integralist / 1. bad.js
Created July 12, 2013 15:45
Strategy pattern to remove the need for conditionals. If you find yourself writing conditionals then that's really just an object waiting to be made. Yes there are more lines of code, but this enforces the 'open/closed principle' which means the code is open for extension but closed for modification and means our code can scale a lot more easily…
function test(condition){
if (condition === 'a') {
console.log('test a here');
} else if (condition === 'b') {
console.log('test b here');
} else if (condition === 'c') {
console.log('test c here');
}
}
@EvanHahn
EvanHahn / app.js
Last active September 29, 2023 14:14
Do you love anime?
// Start Express
const express = require("express");
const app = express();
// Set the view directory to /views
app.set("views", __dirname + "/views");
// Let's use the Pug templating language
app.set("view engine", "pug");
@addyosmani
addyosmani / Readme.md
Created May 6, 2013 20:55 — forked from NV/Readme.md
stopBefore.js

stopBefore.js

2min screencast

Examples

stopBefore(document, 'getElementById')
stopBefore('document.getElementById') // the same as the previous
stopBefore(Element.prototype, 'removeChild')
@Integralist
Integralist / Closure.php
Created March 26, 2013 09:44
Basic Closure example in PHP
<?php
function doSomething($multiplier)
{
return array_map(function ($item) {
return $item * $multiplier;
}, array(1, 2, 3));
}
function doSomethingWithClosure($multiplier)
{