Skip to content

Instantly share code, notes, and snippets.

@chris-muller
chris-muller / newline-to-paragraph.php
Last active February 21, 2016 03:56
Convert text between newlines into html <p> tags.
<?php
public function nl2p($string) {
$paragraphs = '';
//split copy into pragraphs
foreach (explode("\n", $string) as $line) {
//trim line and if it isn't empty, add to output
if ($line = trim($line)) {
@chris-muller
chris-muller / sass-is-int-function.scss
Last active October 19, 2015 11:47
A Sass function that lets you detect if a value is a unitless integer.
@function isInt($value) {
@if round($value) == $value and unitless($value) {
@return true;
}
@return false;
}
@chris-muller
chris-muller / keybindings.json
Created October 28, 2015 04:44
Visual Studio Code Preferences
// Place your key bindings in this file to overwrite the defaults
[
{ "key": "ctrl+shift+s", "command": "workbench.action.files.saveAll" }
]
using System;
using System.Collections.Generic;
public class IcoSphereCreator
{
private struct TriangleIndices
{
public int v1;
public int v2;
public int v3;
@chris-muller
chris-muller / gulpfile.js
Created February 11, 2016 23:28
Default Sass Gulpfile Template
//Modules
var gulp = require('gulp');
var sass = require('gulp-sass');
//File Paths
var scssFilePath = "./Path/To/scss/**/*.scss";
var cssOutputPath = "./Path/To/css";
// Sass Build Task
gulp.task('css', function(){
@chris-muller
chris-muller / TrimStringProperties.cs
Created February 21, 2016 03:37
Object Extension to trim all string properties.
//http://stackoverflow.com/a/15328864
public static class StringExtensions
{
public static TSelf TrimStringProperties<TSelf>(this TSelf input)
{
var stringProperties = input.GetType().GetProperties()
.Where(p => p.PropertyType == typeof(string));
foreach (var stringProperty in stringProperties)
{
@chris-muller
chris-muller / headings-placeholder.scss
Last active February 26, 2016 08:46
Heading tags placeholder examples in Sass
// This applies all the rules
// targeting the headings
// placeholder class
h1, h2, h3,
h4, h5, h6 {
@extend %headings !optional;
}
// Example use of headings
@chris-muller
chris-muller / README.md
Last active March 29, 2016 00:18
Example code for a 'related links' include.

#Usage Use the below code to include a post from your posts with a title of "Hello World!" You can change the collection that the include uses instead of using posts.

{% include related.html item="Hello World!" collection=site.posts %}

Could also be changed to match a custom variable instead of title if name collisions are a concern.

// Nice way of getting the conciseness
// benefits of using an enum when using
// non-literal values
enum Size {
case Large
case Medium
case Small
var value: CGSize {
switch self {
@chris-muller
chris-muller / cookies.js
Last active May 2, 2017 23:24
Simple script to set cookies and check if cookie is still present.
var cookie = function () {
function setCookie(name, value, expiry) {
name = (typeof name !== 'undefined') ? name : "cookieName";
value = (typeof value !== 'undefined') ? value : "true";
expiry = (typeof expiry !== 'undefined') ? expiry : 1;
var date = new Date();
date.setTime(date.getTime() + (expiry * 1000 * 60 * 60 * 24));
var expires = "expires=" + date.toUTCString();