Skip to content

Instantly share code, notes, and snippets.

@steverydz
steverydz / extensions.md
Last active November 26, 2020 11:40
VS Code setup
  • EditorConfig for VS Code
  • ESLint
  • Prettier - Code formatter
  • Python
  • stylelint
@steverydz
steverydz / binary-search.js
Last active April 9, 2018 09:24
JavaScript binary search algorithm
function binarySearch(list, item) {
var low = 0;
var high = list.length - 1;
while (low <= high) {
var mid = low + Math.floor((low + high) / 2);
var guess = list[mid];
if (guess === item) {
return mid;
@steverydz
steverydz / .htaccess
Created December 12, 2017 18:08
HTAccess for https, 404 and remove .html
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://steverydz.com/$1 [R,L]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule !.*\.html$ %{REQUEST_FILENAME}.html [QSA,L]
ErrorDocument 404 /404.html
@steverydz
steverydz / function-wrappers.js
Created January 2, 2017 09:25
How to use function wrappers
// When wrapping a function, such as console.log for example,
// you should use the implicit arguments object rather than
// passing in your own parameters.
// Examples:
// Bad
var logWrapper = function (message) {
console.log(message);
};
/* Sane box model */
html {
box-sizing: border-box;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
@steverydz
steverydz / grid.scss
Last active August 29, 2015 13:57
An example grid system using Sass mixins.
// Config
$container-width: 96% !default;
$container-max-width: 1200px !default;
$grid-base-outer-width: 940 !default;
$grid-base-col-width: 60 !default;
$grid-base-gutter-width: 20 !default;
$grid-cols: 12 !default;
// Clearfix
@steverydz
steverydz / checkWidth.js
Created November 19, 2013 22:50
Responsive JavaScript
function checkWidth() {
var viewportWidth = window.innerWidth;
// If the viewport width is greater than 640px
if (viewportWidth > 640) {
// Execute your code
} else {
// Do something else
}
/*
JavaScript class helpers
See: http://toddmotto.com/creating-jquery-style-functions-in-javascript-hasclass-addclass-removeclass-toggleclass/
*/
function hasClass(elem, className) {
return new RegExp(" " + className + " ").test(" " + elem.className + " ");
}
function addClass(elem, className) {
@steverydz
steverydz / prettydate
Created July 2, 2013 20:24
This is a plugin for Jekyll that adds ordinals to dates.
require 'date'
require 'facets/integer/ordinal'
module Jekyll
module DateFilter
def prettydate(date)
"#{date.strftime('%e').to_i.ordinalize} #{date.strftime('%B')} #{date.strftime('%Y')}"
end
end
end