Skip to content

Instantly share code, notes, and snippets.

@cbejensen
cbejensen / get_full_url.php
Last active February 15, 2018 16:16
Get the full URL in PHP
<?php
function get_full_url() {
$url = ( isset( $_SERVER['HTTPS'] ) && 'on' === $_SERVER['HTTPS'] ) ? 'https' : 'http';
$url .= '://' . $_SERVER['SERVER_NAME'];
$url .= in_array( $_SERVER['SERVER_PORT'], array( '80', '443' ) ) ? '' : ":" . $_SERVER['SERVER_PORT'];
$url .= substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], '/') + 1);
return $url;
}
@cbejensen
cbejensen / index.html
Last active April 25, 2018 17:17
Easy Carousel with Text
<div class="easy-slides">
<div class="easy-slide active" style="background-image:url('https://source.unsplash.com/random/800x400');"></div>
<div class="easy-slide" style="background-image:url('https://source.unsplash.com/random/700x400');"></div>
<div class="easy-slide" style="background-image:url('https://source.unsplash.com/random/800x300');"></div>
<div class="easy-slide-text">
Hello World!
</div>
</div>
@cbejensen
cbejensen / index.html
Last active April 30, 2018 18:33
Social Icons
<ul class="social-icons">
<li class="social-icon social-icon__fb">
<a href="" rel="external noopener" target="_blank">
<svg height="100%" viewBox="0 0 48 48" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g class="social-icon-graph social-icon-graph__fb" transform="translate(-200.000000, -160.000000)">
<path d="M225.638355,208 L202.649232,208 C201.185673,208 200,206.813592 200,205.350603 L200,162.649211 C200,161.18585 201.185859,160 202.649232,160 L245.350955,160 C246.813955,160 248,161.18585 248,162.649211 L248,205.350603 C248,206.813778 246.813769,208 245.350955,208 L233.119305,208 L233.119305,189.411755 L239.358521,189.411755 L240.292755,182.167586 L233.119305,182.167586 L233.119305,177.542641 C233.119305,175.445287 233.701712,174.01601 236.70929,174.01601 L240.545311,174.014333 L240.545311,167.535091 C239.881886,167.446808 237.604784,167.24957 234.9555
@cbejensen
cbejensen / form-handler.js
Last active October 30, 2018 17:51
Simple Form with Ajax
(function() {
const forms = document.querySelectorAll('.js-contact-form');
let statusElems = [];
let status = "";
forms.forEach(function(form) {
if (!form) return;
form.addEventListener('submit', function(e) {
e.preventDefault();
const xhr = new XMLHttpRequest();
xhr.open('POST', 'submit.php');
@cbejensen
cbejensen / client.js
Last active December 6, 2018 19:11
Getting no response when sending GET request from localhost:3000 to localhost:8000
// currently running on localhost:3000
const xhr = new XMLHttpRequest()
const url = 'localhost:8000/'
xhr.open('GET', url)
xhr.onreadystatechange = function() {
console.log(xhr.responseText) // logs nothing
}
xhr.send()
@cbejensen
cbejensen / settings.json
Last active January 7, 2019 18:53
VS Code Theme
{
"workbench.colorTheme": "One Dark Pro",
"workbench.colorCustomizations": {
"[One Dark Pro]": {
// dark 1 (darkest)
"input.background": "#1f252b",
"badge.background": "#1f252b",
"sideBar.background": "#1f252b",
"sideBarSectionHeader.background": "#1f252b",
"tab.inactiveBackground": "#1f252b",
@cbejensen
cbejensen / Brownies.jsx
Last active March 29, 2019 22:11
Async Effect Hook
import React from 'react'
import useEffectAsync from './useEffectAsync'
export default function Brownies() {
const [brownies, setBrownies] = useState('Loading')
useEffectAsync(
async didUnmount => {
const res = await fetch(`https://api.brownies.com`)
if (!didUnmount) setBrownies(res)
@cbejensen
cbejensen / ips.fish
Created April 5, 2019 19:09
Easily get and read your IP address
function ips
set eth (ipconfig getifaddr en0)
echo "Ethernet: $eth"
set wifi (ipconfig getifaddr en1)
echo "Wireless: $wifi"
end
@cbejensen
cbejensen / script.js
Created April 15, 2019 16:19
Check for support of :focus-within
let supportsCSSFocusWithin = false
try {
document.querySelector(':focus-within')
} catch (err) {
supportsCSSFocusWithin = false
}
const wrapper = document.querySelector('wrapper')
@cbejensen
cbejensen / index.js
Last active September 30, 2019 01:51
Nodemailer with cors not working
const express = require('express')
const bodyParser = require('body-parser')
const cors = require('cors')
const app = express()
const nodemailer = require('nodemailer')
const port = 8000
app.use(bodyParser.json())