Skip to content

Instantly share code, notes, and snippets.

View colynb's full-sized avatar
🎯
Focusing

C Brown colynb

🎯
Focusing
View GitHub Profile
@colynb
colynb / functions.php
Last active May 22, 2023 05:09
PHP - convert any dollar/cents amount into just cents
<?php
function to_pennies($value)
{
return intval(
strval(floatval(
preg_replace("/[^0-9.]/", "", $value)
) * 100)
);
}
@colynb
colynb / PHP match
Last active April 4, 2021 15:05
test
$name = 'dog';
$value = match ($name) {
'dog' => 1,
'cat' => 2,
'horse' => 3,
default => throw new \Exception,
};
@colynb
colynb / server.go
Created June 13, 2017 22:18
Stupid JSON server in golang
package main
import (
"net/http"
"encoding/json"
)
type Person struct {
ID int `json:"id"`
Firstname string `json:"firstname"`
@colynb
colynb / dabblet.css
Created December 22, 2011 03:24
Radio Button Hack - CSS Only
input[type=radio] {
position: absolute;
top: -9999px;
left: -9999px;
}
label {
cursor: pointer;
text-align: center;
font-family: sans-serif;
On client page
```html
<re-widget type="youtube" src="https://www.youtube.com/embed/TwAFQZLK79A"></re-widget>
<script>
(function (fn) {
var d = document, s = d.createElement('script');
s.onload = fn; d.head.appendChild(s); s.src = 'embed.js';
})(function () {
@colynb
colynb / FSBOEvent.php
Created April 28, 2017 01:03
Simple PHP event handling class
<?php
namespace Events;
class FSBOEvent
{
/**
* @var array
*/
protected static $eventHandlers = [];
@colynb
colynb / cloudSettings
Last active December 21, 2017 00:11
Visual Studio Code Settings Sync Gist
{"lastUpload":"2017-12-21T00:08:27.138Z","extensionVersion":"v2.8.7"}
@colynb
colynb / test.js
Created August 1, 2017 18:05
Is a Palindrome
function isPalindrome (str) {
str = str.replace(/[^a-zA-Z]/g, '').toLowerCase()
var len = Math.floor(str.length / 2)
return (str.substring(0, len) === str.substring(len + 1).split('').reverse().join(''))
}
console.log(isPalindrome('A dog! A panic in a pagoda!')) // true
console.log(isPalindrome('Able was I ere I saw Elba.')) // true
console.log(isPalindrome('not a palindrome')) // false
@colynb
colynb / index.html
Created July 9, 2017 20:43
Star Rating
<h1>Pure CSS Star Rating Widget</h1>
<fieldset class="rating">
<input type="radio" id="star5" name="rating" value="5" /><label class = "full" for="star5" title="Awesome - 5 stars"></label>
<input type="radio" id="star4half" name="rating" value="4 and a half" /><label class="half" for="star4half" title="Pretty good - 4.5 stars"></label>
<input type="radio" id="star4" name="rating" value="4" /><label class = "full" for="star4" title="Pretty good - 4 stars"></label>
<input type="radio" id="star3half" name="rating" value="3 and a half" /><label class="half" for="star3half" title="Meh - 3.5 stars"></label>
<input type="radio" id="star3" name="rating" value="3" /><label class = "full" for="star3" title="Meh - 3 stars"></label>
<input type="radio" id="star2half" name="rating" value="2 and a half" /><label class="half" for="star2half" title="Kinda bad - 2.5 stars"></label>
<input type="radio" id="star2" name="rating" value="2" /><label class = "full" for="star2" title="Kinda bad - 2 stars"
@colynb
colynb / components.js
Created July 1, 2017 19:51
Ways to write React components
class MyComponent {
render () {
return (
<h1>My Component</h1>
)
}
}
var HelloWorld = function(props) {
return (