Skip to content

Instantly share code, notes, and snippets.

@colelawrence
colelawrence / regex-console.re
Last active August 29, 2015 14:23
Remove all console.log statements from JavaScript in Sublime, acknowledging quotes, newlines, and parenthesis
Ensure regex button is selected and then type this in the search field.
\s*console\.(log|warn|debug|info|count)\((?:[^("'`]+|(["'`])[^\1]*?\1|(\()[^\2]*\2)*?\);?
@colelawrence
colelawrence / hash-object.js
Last active January 14, 2022 13:25
Create an md5 hash string of a javascript object using crypto createHash, update, and digest hex
var crypto = require('crypto');
exports.hashObject = function (object) {
var hash = crypto.createHash('md5')
.update(JSON.stringify(object, function (k, v) {
if (k[0] === "_") return undefined; // remove api stuff
else if (typeof v === "function") // consider functions
return v.toString();
else return v;
}))
@colelawrence
colelawrence / NewtonsSqrt.go
Created August 30, 2015 16:32
Newtons Sqrt
package main
import (
"fmt"
)
func abs(x float64) float64 {
if x > 0 {
return x
} else {
@colelawrence
colelawrence / drawLine in Go.go
Created August 30, 2015 21:05
drawing lines and stuff in Go
package main
import "golang.org/x/tour/pic"
import "math"
func lemp(x1, y1, dx, dy, t float64) (tx, ty float64) {
tx = x1 - t * dx
ty = y1 - t * dy
return
}
package main
import "golang.org/x/tour/tree"
import "fmt"
// Walk walks the tree t sending all values
// from the tree to the channel ch.
func _walk(t *tree.Tree, ch chan int) {
if t.Left != nil { _walk(t.Left, ch) }
ch <- t.Value
Clear()
# Nominal GDP
Say "2008 Nominal GDP: " + gdp08 = 1 * 115 + 2 * 175
Say "2009 Nominal GDP: " + gdp09 = 2 * 150 + 4 * 180
Say "2010 Nominal GDP: " + gdp10 = 4 * 120 + 4 * 190
# Real GDP
Say "2008 Real GDP b08: " + gdp0808 = 1 * 115 + 2 * 175
Say "2009 Real GDP b08: " + gdp0908 = 1 * 150 + 2 * 180
Say "2010 Real GDP b08: " + gdp1008 = 1 * 120 + 2 * 190
/* Based on Isaac Muse's ExportHtml Color theme */
/* Based on Sublime Text's Monokai theme */
.cm-s-lawr.CodeMirror {background: white/*#272822*/; color: black/*#f8f8f2*/; font: 11pt "Consolas", "Courier", Monospace;}
.cm-s-lawr div.CodeMirror-selected {background: dodgerblue/*#49483E*/ !important;}
.cm-s-lawr span.CodeMirror-selectedtext {color: white !important;}
.cm-s-lawr .CodeMirror-gutters {background: white/*#272822*/; border-right: 0px;}
.cm-s-lawr .CodeMirror-linenumber {color: rgba(0,0,0,0.2)/*#d0d0d0*/;}
.cm-s-lawr .CodeMirror-cursor {border-left: 1px solid black/*#f8f8f0*/ !important;}
.cm-s-lawr .CodeMirror-cursor {border-right: 1px solid black/*#f8f8f0*/ !important;}
/* Based on Isaac Muse's ExportHtml Color theme */
/* Based on Sublime Text's Monokai theme */
/* also based on http://www.colourlovers.com/palette/245002/Deutanopia-Safe_1 */
.cm-s-lawr .error-message {background: #f30; color: white;}
.cm-s-lawr.CodeMirror {background: white/*#272822*/; color: black/*#f8f8f2*/;
/*border-bottom: 5px solid rgba(0,0,0,0.2);*/
margin-bottom: 2em;
}
.cm-s-lawr .CodeMirror-lines {padding: 0;}
@colelawrence
colelawrence / .drone.yml
Last active June 23, 2016 04:54
Drone reporting to github example scaffolding
# TOC
# 1. Run Linting / Run Tests
# 1.1 Upload Test Report
# 1.2 Status Test Report
# 1.3 Comment Linting
# 2. Run Diff-cover
# 2.1 Upload Diff-cover
# 2.2 Comment Diff-cover
# 3. Post Comments and Statuses to Github
@colelawrence
colelawrence / create-status.bash
Created July 22, 2016 16:20
Create github API call with curl
# DRONE_COMMIT commit sha
# DRONE_BUILD_LINK
# DRONE_REPO_OWNER repository owner
# DRONE_REPO_NAME repository name
# From github:
# POST /repos/:owner/:repo/statuses/:sha
export GITHUB_API=https://api.github.com
export BODY=<< EOF
{