Skip to content

Instantly share code, notes, and snippets.

Avatar

Dillon de Voor CrocoDillon

View GitHub Profile
View ba-objecttotype.js
// See http://javascriptweblog.wordpress.com/2011/08/08/fixing-the-javascript-typeof-operator/
(function(global) {
// Maintain a map of already-encountered types for super-fast lookups. This
// serves the dual purpose of being an object from which to use the function
// Object.prototype.toString for retrieving an object's [[Class]].
var types = {};
// Return a useful value based on a passed object's [[Class]] (when possible).
Object.toType = function(obj) {
@kopiro
kopiro / sudoku-solver-with-bt.js
Created May 11, 2015
Sudoku solver with backtracking
View sudoku-solver-with-bt.js
function getp(puzzle, x, y) {
var hash = {};
for (var u = 0; u < 9; u++) hash[ puzzle[y][u] ] = 1;
for (var u = 0; u < 9; u++) hash[ puzzle[u][x] ] = 1;
for (var u = 0; u < 9; u++) hash[ puzzle[ 3*((y/3)|0) + ((u/3)|0) ][ 3*((x/3)|0) + (u%3) ] ] = 1;
var poss = [];
for (var i = 1; i <= 9; i++) if (!(i in hash)) poss.push(i);
return poss;
}
@bubbleheadinc
bubbleheadinc / gist:5725438
Created Jun 6, 2013
Mixin loop to spit out span classes based on # of grid columns for JustifyGrid.com SCSS
View gist:5725438
@mixin grid-spans($col-span){
@while $col-span > 0{
.grid-span-#{$col-span}{
width: grid-span($col-span);
}
$col-span: $col-span - 1;
}
}
View polyfills.js
if (typeof Promise === 'undefined') {
require.ensure([], (require) => {
require('imports?this=>window!es6-promise')
})
}
if (typeof fetch === 'undefined') {
require.ensure([], (require) => {
require('imports?self=>window!whatwg-fetch')
})
@cahnory
cahnory / middleware.js
Created Dec 21, 2015
koa-webpack-middleware
View middleware.js
import connect from 'koa-connect';
import compose from 'koa-compose';
import webpack from 'webpack';
import webpackDev from 'webpack-dev-middleware';
import webpackHot from 'webpack-hot-middleware';
export default function (config = {}) {
let compiler = webpack(config);
return compose([
View css-tricks_chrisburton_readability_DB.php
<?php
// you can't just get this as JSON in the first place, can you ...?
$xml = simplexml_load_file( "http://readability.com/christopherburton/latest/feed" );
$json = json_encode( $xml );
$array = json_decode( $json,TRUE );
$items = $array['channel']['item'];
// we're doing this now so we can sanitize the data without requiring a second loop
// (substitute your actual DB credentials)
$DB = new mysqli( DB_HOST,DB_USER,DB_PASS,DB_NAME );
View our_setup_script.js
db = db.getSisterDB("config");
var mongosConn = db; // assume we connected to a mongos to get going
var res = null;
function check() {
printjson(res);
if( !res || !res.ok ) {
throw "check(): not ok, stopping";
@cheeaun
cheeaun / js-error-logging-services.md
Last active Nov 4, 2021
JavaScript error logging services
View js-error-logging-services.md
@corydorning
corydorning / Cross-Browser ::before and ::after pseudo-class polyfill
Last active Feb 18, 2022
Cross-Browser ::before and ::after pseudo-class polyfill
View Cross-Browser ::before and ::after pseudo-class polyfill
/* =============================================================================
CSS Declarations
========================================================================== */
/* ==|== The Standard Way =================================================== */
.foo::before {
/* ...css rules... */
}
@razwan
razwan / _baseline.scss
Created Apr 14, 2014
Aligning type to baseline the right way with SASS
View _baseline.scss
$base-font-size: 16px;
$base-line-height: 1.5;
// this value may vary for each font
// unitless value relative to 1em
$cap-height: 0.68;
@mixin baseline($font-size, $scale: 2) {