Skip to content

Instantly share code, notes, and snippets.

View cmmartin's full-sized avatar

Charlie Martin cmmartin

  • Founderpath
  • Brooklyn, NY
View GitHub Profile
@cmmartin
cmmartin / BlurredBackgroundView.swift
Created January 22, 2016 03:37
UIVisualEffectView with a background image
import UIKit
class BlurredBackgroundView: UIView {
let imageView: UIImageView
let blurView: UIVisualEffectView
override init(frame: CGRect) {
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.Dark)
blurView = UIVisualEffectView(effect: blurEffect)
imageView = UIImageView(image: UIImage(name: "someBackgroundImage.jpg"))
@cmmartin
cmmartin / VibrantNavigationBar.swift
Created January 22, 2016 03:34
Apple a UIVibrancyEffect to an iOS navigation bar
override func viewWillAppear(animated: Bool) {
// Make the bar actually transparent by setting an empty image as the background
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: .Default)
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.translucent = true
var bounds = (self.navigationController?.navigationBar.bounds)!
// make it cover the status bar by offseting y by -20
bounds.offsetInPlace(dx: 0.0, dy: -20.0)
bounds.size.height = bounds.height + 20.0
@cmmartin
cmmartin / MusicalNotes.swift
Created December 11, 2015 04:23
Musical notes mapped to their frequencies in Hz
let musicalNotes = [
// name + octave: frequency (Hz)
"C0": 16.35,
"C#0": 17.32,
"D0": 18.35,
"D#0": 19.45,
"E0": 20.60,
"F0": 21.83,
"F#0": 23.12,
"G0": 24.50,
@cmmartin
cmmartin / BufferStream.js
Last active November 17, 2015 05:54
Convert a stream to a Buffer in Node.js
import { Writable } from 'stream'
/**
* Create a Buffer from a stream (warning: loads all chunks into memory)
* Usage: myStream.pipe(new BufferStream(buffer => {}, err => {}))
*/
export default class BufferStream extends Writable {
data = []
@cmmartin
cmmartin / dokku_deploy.sh
Created October 19, 2015 17:14
A simple script for deploying to various dokku instances
#!/bin/bash
readonly user="my_dokku_username"
readonly host="my_hostname"
readonly targets=(
# git branch | project name | virtual host
# list your dokku instances here...
)
# execute from the project root
@cmmartin
cmmartin / .bash_profile
Created October 5, 2015 21:43
Never accidentally commit console.log again
gitadd() {
git diff | grep "console.log" || git add $1
}
@cmmartin
cmmartin / server.js
Last active August 29, 2015 14:27
Streaming server middleware
import koa from 'koa'
import router from 'koa-route'
import streamView from './stream-view'
const app = koa()
const toJS = str => JSON.parse(str)
const toJSON = js => JSON.stringify(js)
// stream an html page with asynchronous data
app.use(router.get('/html/:title', streamView('html', function* (title) {
@cmmartin
cmmartin / stream-view.js
Last active August 29, 2015 14:27
An example of streaming html to the browser in ES2015
// An example of streaming html to the browser in ES2015
// inspired by https://github.com/koajs/examples/tree/master/stream-view
// *** Usage ***
// const app = koa()
// app.use(function* () {
// this.type = 'html'
// this.body = new StreamView(this)
// })
// app.listen(3000)
@cmmartin
cmmartin / cover-image.css
Last active August 29, 2015 14:23
CSS background image cover
background: url('https://placeholdit.imgix.net/~text?txtsize=72&txt=background%20image&w=1020&h=860') no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
@cmmartin
cmmartin / javascript-lies.js
Last active May 7, 2021 05:24
Javascript lies
null + null === 0 // true
[] + [] === '' // true
null + 1 === 1 // true
isNaN(null) // false
NaN === NaN // false