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 / 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,
};
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 / 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 (
@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 / server.go
Created June 13, 2017 21:46
stupid server in golang
package main
import (
"net/http"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
w.Write([]byte("Hello World"))
})
@colynb
colynb / range.go
Created June 13, 2017 18:32
Golang slice example
package main
import (
"fmt"
)
func main() {
mySlice := []string{"One", "Two", "Three"}
for index, item := range mySlice {
@colynb
colynb / affix.html
Created May 11, 2017 00:54 — forked from Cezarion/affix.html
Affix js with vanilla js
<script type="text/javascript">
window.onscroll = scroll;
function scroll () {
var scrollTop = window.pageYOffset;
console.log(scrollTop);
if( scrollTop > 363 ){
document.getElementById('summary').style.top="20px";
document.getElementById('summary').style.position="fixed";
}
else