Skip to content

Instantly share code, notes, and snippets.

View davidsharp's full-sized avatar

David Sharp davidsharp

View GitHub Profile
@bkeepers
bkeepers / .profile
Created June 19, 2009 13:41
Split bash profile into multiple files
# My ~/.profile file was getting too messy and unmaintainable, so I
# split everything out into separate files and sourced them
for file in ~/.profile.d/*
do
source $file
done
@mathewbyrne
mathewbyrne / slugify.js
Created October 12, 2011 04:34
Javascript Slugify
function slugify(text)
{
return text.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, ''); // Trim - from end of text
}
@tetsuok
tetsuok / answer_pic.go
Created April 2, 2012 02:40
An answer of the exercise: Slices on a tour of Go
package main
import "code.google.com/p/go-tour/pic"
func Pic(dx, dy int) [][]uint8 {
// Allocate two-dimensioanl array.
a := make([][]uint8, dy)
for i := 0; i < dy; i++ {
a[i] = make([]uint8, dx)
}
@jaygooby
jaygooby / git_notes.md
Last active October 16, 2023 16:26
Git, you bloody git

Overwrite untracked files in current branch from a remote branch

In a similar vein to git reset --hard feature/weavils you can just overwrite untracked working files (typically left over from branch experiments) which are part of the remote branch you're pulling like this:

git reset --hard origin/feature/weavils

Normally, if you tried git checkout feature/weavils you'd get warnings like untracked working tree files would be overwritten by merge, so hit them with the --hard hammer instead.

(Found via https://stackoverflow.com/q/17404316/391826 and one of the answers: https://stackoverflow.com/a/36824493/391826)

@NoobsArePeople2
NoobsArePeople2 / gist:5121597
Last active November 10, 2023 14:33
Configure media keys on a non-Apple keyboard to control Spotify via AppleScript and USB Overdrive on OSX.

Requirements

  1. USB Overdrive
  2. A non-Apple keyboard with media keys (or keys you want to make "media" keys). For reference, I'm using a Microsoft Sidewinder X4

Set Up

  1. Plug in your keyboard and install USB Overdrive.
  2. Open USB Overdrive. Click into the Settings tab.
  3. Click the dropdown and select "Any Keyboard, Any Application"
@addyosmani
addyosmani / README.md
Last active April 2, 2024 20:18 — forked from 140bytes/LICENSE.txt
108 byte CSS Layout Debugger

CSS Layout Debugger

A tweet-sized debugger for visualizing your CSS layouts. Outlines every DOM element on your page a random (valid) CSS hex color.

One-line version to paste in your DevTools

Use $$ if your browser aliases it:

~ 108 byte version

@gaearon
gaearon / AudioPlayer.jsx
Created October 31, 2014 22:13
React <audio> wrapper
/** @jsx React.DOM */
'use strict';
var React = require('react'),
{ PropTypes } = React;
var AudioPlayer = React.createClass({
propTypes: {
source: PropTypes.string.isRequired,
isPlaying: PropTypes.bool.isRequired,
@bennadel
bennadel / get-watch-count.js
Created November 28, 2014 13:26
Counting The Number Of Watchers In AngularJS - Updated For Isolate Scopes
// I return the count of watchers on the current page.
function getWatchCount() {
// Keep track of the total number of watch bindings on the page.
var total = 0;
// There are cases in which two different ng-scope markers will actually be referencing
// the same scope, such as with transclusion into an existing scope (ie, cloning a node
// and then linking it with an existing scope, not a new one). As such, we need to make
// sure that we don't double-count scopes.
"use strict";
var fragmentText = function(ctx, lines, index, maxWidth) {
var line = lines[index];
var nextLine;
var tooLong = true;
while (tooLong) {
var width = ctx.measureText(line.join(" ")).width;
anonymous
anonymous / untitled
Created April 27, 2015 13:44
IFTTT Spotify Alarm Clock
Spotify Alarm
Utilizing [IFTT recipe](https://ifttt.com/recipes/283707-spotify-alarm-clock)
In your mail client:
Create a rule in your mail client with the following properties
- Message content contains #wakeup
- Actions: Delete Message, Run AppleScript
Create an AppleScript with the following statements.