Skip to content

Instantly share code, notes, and snippets.

@bradley
bradley / dabblet.css
Created February 26, 2012 23:52
The first commented line is your dabblet’s title
/**
* The first commented line is your dabblet’s title
*/
background: #f06;
background: linear-gradient(45deg, #f06, yellow);
min-height:100%;
@bradley
bradley / gist:2484138
Created April 24, 2012 21:47
Create new JS object for each input field and send AJAX call when user stops typing.
// =========== Input Field Listener with AJAX Callback ==============
function FieldListener(entity){
var t = this;
this.typingTimer; // Timer identifier
this.doneTypingInterval = 750; // Time in ms. e.g.; 5000 = 5secs
this.entity = entity;
this.noticeSpan = this.entity.siblings("span");
this.parentForm = entity.parents('form:first');
entity.on("keyup", function(){t.setTimer();});
@bradley
bradley / gist:ed290aab1a2f5cfb21d1
Created November 24, 2014 20:17
swift output ints from regex
// Playground - noun: a place where people can play
import Foundation
class Regex {
let internalExpression: NSRegularExpression
let pattern: String
init(_ pattern: String) {
self.pattern = pattern
/* requestAnimationFrame polyfill
---------------------------------------------------------------------------------*/
(function() {
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];
for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame']
|| window[vendors[x]+'CancelRequestAnimationFrame'];
@bradley
bradley / map_join.html.haml
Last active July 14, 2017 22:21
using Map/Join for HAML markup
= raw (@employee.documents.active.map do |document|
- link_to document.display_name, document.file.expiring_url
- end.join(", "))
@bradley
bradley / Digital-Ocean-SSH-and-Subdomains.md
Last active February 5, 2022 04:05
Digital Ocean SSH and Subdomains

Basic Getting Started Ubuntu 16.04

SSH into your server at root:

ssh root@myserver.com

Crate a new user:

adduser my_username

Make the new user a sudo user:

## Bare Bones
1. Create your droplet, adding the 1-click install dokku app and giving it at least 1GB memory which Dokku will need for deployment, then navigate to your server's IP and complete the process in the dokku form that will exist there. Also be sure you've followed the guide [here](https://gist.github.com/bradley/0c06d3f2d3c63b097ea5e27befd4beb3) to set up the various accounts youll need on your ubuntu server correctly before proceeding.
2. SSH into your droplet: `ssh root@droplet-ip`
3. Create your dokku app: `dokku apps:create app-name`
4. By default your app is located at myapp.mydomain.com. If you want your app to be accessible via the root domain, then just add the root domain as one of your app's domains. `dokku domains:add app-name mydomain.com`.
5. On your local machine, in your project’s Git repository, add your droplet as a remote: `git remote add dokku dokku@droplet-ip:app-name`
6. Dokku will start your node app itself by calling `nmp start` but if you want to modify that create a `Procf
@bradley
bradley / blotter_channelsplitmaterial_hover_example.js
Created February 14, 2018 17:24
Blotter ChannelSplitMaterial Mouse Detection with Rotation
function angleBetweenPointsInDegrees(x1, y1, x2, y2) {
var angle = Math.atan2(y2 - y1, x2 - x1) * 180.0 / Math.PI;
angle = 180 + angle;
return angle;
}
function distanceBetweenPoints(x1, y1, x2, y2) {
var a = x1 - x2;
@bradley
bradley / routing-example.js
Created March 18, 2018 23:05
Simple route handling express.
// In app.js
require("./config/routes")(app, passport);
// In /config/routes.js
module.exports = function(app, passport) {
[
"users",
"sessions",
"stories"
].forEach(function (routeName) {
@bradley
bradley / rails_production_csv_export.rb
Created October 3, 2018 16:39
Export a CSV on a production Rails Server
# When ran in the rails console, this code will create and place a
# new csv file in the tmp directory of your rails app. Once done,
# simply exit the rails console and cd into the tmp directory, cat
# the file, and copy its content to a local file. There are probably
# better ways to do this but this does work. Be sure to clean up
# after yourself by rm'ing the file when youre done with it.
require 'csv'
zoo = Zoo.find(id)