Skip to content

Instantly share code, notes, and snippets.

View webinista's full-sized avatar

Tiffany Brown webinista

View GitHub Profile
@webinista
webinista / ucfirst.js
Created July 4, 2018 16:12
Uppercase the first letter of a word with JavaScript
function ucfirst(word) {
const wordarray = word.split('');
wordarray[0] = wordarray[0].toUpperCase();
return wordarray.join('');
}
@webinista
webinista / range.js
Last active April 13, 2018 03:51
Get a range of numbers that includes the min and max values. Integers only.
const range = (min, max) => {
const diff = max - min;
const spread = [...Array(diff).keys()].map(n => {return n + min});
spread.push(max);
return spread;
}
// Example usage
range(2,100);
@webinista
webinista / pelicanconf.py
Last active April 10, 2023 23:07
A Pelican configuration for having a home page and blog index or landing page.
#!/usr/bin/env python
# -*- coding: utf-8 -*- #
from __future__ import unicode_literals
# --------------------------------------
# Now compatible with Pelican 4.0.x!
# --------------------------------------
# Added by me
import time
@webinista
webinista / gist:29a7bace0c181104b00e6165edf7d8bc
Last active January 21, 2018 00:12
Apache won't start MAMP Pro 4.2, OS X
If you've recently added a self-signed SSL certificate to your keychain, try deleting it.
@webinista
webinista / index.js
Created December 13, 2017 17:23
Content-Security-Policy and other security-related headers for Node.js and AWS Lambda (for webinista.com, tiffanybbrown.com)
'use strict';
exports.handler = (event, context, callback) => {
const request = event.Records[0].cf.request;
const response = event.Records[0].cf.response;
// frame-src is deprecated, but Chrome AFAIK doesn't yet support child-src. Using both here.
response.headers['content-security-policy'] = [{
key: 'Content-Security-Policy',
value: "default-src 'self'; script-src 'self' https://webinista.us3.list-manage.com; font-src https://*; frame-src 'self' *.tiffanybbrown.com *.webinista.com; child-src 'self' *.tiffanybbrown.com *.webinista.com; img-src https://*; block-all-mixed-content"
@webinista
webinista / hsltorgb.js
Last active June 7, 2017 23:16
Convert from hsl to rgb string
const percentToFloat = (percentString) => {
return parseInt(percentString, 10) / 100;
}
/*
* Copied, pasted, and modified straight from the CSS4 spec
* https://drafts.csswg.org/css-color-4/#hsl-to-rgb
*/
const hueToRgb = (t1, t2, hue) => {
let hueValue;
@webinista
webinista / expandRGB.js
Last active June 5, 2017 00:42
Expand a 3-character hex string (beginning with #) into a 6 character one
export function expandRGB(string) {
if(!(/#[a-f0-9]{3}$/i).test(string)) return string;
const rgb = string.split('');
return `#${rgb[1]}${rgb[1]}${rgb[2]}${rgb[2]}${rgb[3]}${rgb[3]}`;
}
@webinista
webinista / gist:5f5931643d53cfbf67fb10b7aa4724e2
Last active December 19, 2016 03:20
PHP: Change a file name's extension for every file in an directory.
function change_extension($filename, $index, $extension) {
if (pathinfo($filename, PATHINFO_EXTENSION) == 'md'):
$fn = sprintf("%s.%s", pathinfo($filename, PATHINFO_FILENAME), (string)$extension);
$success = rename(sprintf('./%s', $filename), $fn);
endif;
if($success) {
printf("Success! %s was renamed to %s\n", $filename, $fn);
}
}
@webinista
webinista / Placeholder clearing
Created October 7, 2015 02:31
Faux placeholder clearing with CSS
:focus::-webkit-input-placeholder{
color: transparent;
}
:focus::-moz-placeholder {
color: transparent;
}
:focus:-ms-input-placeholder {
color: transparent;
@webinista
webinista / long-button.css
Last active August 29, 2015 14:27
Long buttons
body {
font: 200 18px / 1.5 Arial,sans-serif;
}
.long-button {
box-sizing: border-box;
background: rgba(153,50,204,.95);
color: whitesmoke;
font: inherit;
border: 1px solid transparent;
text-align: left;