Skip to content

Instantly share code, notes, and snippets.

@liquorice
liquorice / gist:1041979
Created June 23, 2011 05:49
bare bones method for grabbing and updating a users latest tweet (with no error handling whatsoever)
$.ajax({
url: 'http://api.twitter.com/1/statuses/user_timeline.json?screen_name=someonesplendid',
dataType: 'jsonp',
success: function(data) {
var tweet = data[0].text;
tweet = tweet.replace(/(http\:\/\/[A-Za-z0-9\.\/_]+)/g, '<a href="$1">$1</a>');
tweet = tweet.replace(/@([a-zA-Z0-9_]+)/g, '<a href="http://twitter.com/$1">@$1</a>');
$('#tweet').html(tweet);
}
});
defaults write com.apple.dock persistent-apps -array-add '{tile-data={}; tile-type="spacer-tile";}'
defaults write com.apple.dock persistent-apps -array-add '{tile-data={}; tile-type="spacer-tile";}'
defaults write com.apple.dock persistent-apps -array-add '{tile-data={}; tile-type="spacer-tile";}'
defaults write com.apple.dock persistent-apps -array-add '{tile-data={}; tile-type="spacer-tile";}'
defaults write com.apple.dock persistent-apps -array-add '{tile-data={}; tile-type="spacer-tile";}'
defaults write com.apple.dock persistent-apps -array-add '{tile-data={}; tile-type="spacer-tile";}'
defaults write com.apple.dock persistent-apps -array-add '{tile-data={}; tile-type="spacer-tile";}'
defaults write com.apple.dock persistent-apps -array-add '{tile-data={}; tile-type="spacer-tile";}'
defaults write com.apple.dock persistent-apps -array-add '{tile-data={}; tile-type="spacer-tile";}'
defaults write com.apple.dock persistent-apps -array-add '{tile-data={}; tile-type="spacer-tile";}'
@liquorice
liquorice / gist:1068689
Created July 7, 2011 00:47
remove dropbox "conflict" files
find . -type f -name "* conflicted *" -exec rm -f {} \;
@liquorice
liquorice / gist:1113000
Created July 29, 2011 02:14
animated hash-link scrolling
$('.scroll-to').click(function(e) {
target = $($(this).attr('href'));
if (target.offset()) {
$('html, body').animate({scrollTop: target.offset().top + 'px'}, 500);
}
e.preventDefault();
});
@liquorice
liquorice / gist:1228474
Created September 20, 2011 06:04
truncate text to nearest word boundry
# truncate text without chopping words
# where d = text to truncate
# x = maximum amount of characters
(d.length <= x) ? d : d[0..x].split()[0...-1].join(' ') + '...'
@liquorice
liquorice / gist:1440692
Created December 6, 2011 23:57
in place array shuffling with fisher-yates
Array.prototype.shuffle = function() {
var l = this.length, t, r;
if (l == 0) return;
while (l--) {
r = Math.floor(Math.random() * l + 1);
t = this[l];
this[l] = this[r]
this[r] = t;
}
@liquorice
liquorice / _breakpoints.scss
Created September 23, 2013 01:53
SASS breakpoints mixin
@mixin breakpoint($points) {
@if index($points, large) {
@media screen and (min-width: 1000) { @content; }
html.ie-large & { @content; }
}
@if index($points, medium) {
@media screen and (max-width: 999) and (min-width: 600) { @content; }
}
@if index($points, small) {
@media screen and (max-width: 599) { @content; }
@liquorice
liquorice / gist:7538042
Created November 19, 2013 00:33
SASS prefixer mixin
// Usage:
// @include prefix(transform-origin, 0 0 0, webkit o moz);
@mixin prefix($property, $value, $prefixes) {
@each $prefix in $prefixes {
-#{$prefix}-#{$property}: $value;
}
#{$property}: $value;
}
@liquorice
liquorice / Unrandom.js
Last active December 30, 2015 05:09
Unrandom — for when someone says they want a random selection, but what they mean is uniformly sampled without repetition.
// Usage:
// var randomiser = new Unrandom(["alpha", "bravo", "charlie", "delta"]);
// console.debug(randomiser.get());
var Unrandom = function(_items) {
var items,
last_item,
marker = 0;
@liquorice
liquorice / gist:8394584
Last active January 3, 2016 02:19
set document.location.href without causing the viewport to scroll
var set_document_hash = function(hash) {
var id = hash,
temp_id = "TEMP-" + hash,
target = $("#" + id);
if (target.length) target.attr("id", temp_id);
document.location.hash = hash;
if (target.length) target.attr("id", id);
}