Skip to content

Instantly share code, notes, and snippets.

@joshellington
joshellington / sftp-ubuntu.md
Created March 28, 2012 07:07
Basic tutorial for creating a SFTP-only user on Ubuntu 9.04 and greater

Adding SFTP-only user to Ubuntu Server

To add a SFTP-only user, you'll need to make sure your SSH config settings are correct, add a new user/group and set permissions for your new user. For step-by-step directions, see below. Omit sudo if you're logged in as root.

Directions

  1. Edit /etc/ssh/sshd_config and make sure to add the following at the end of the file:

     Match group filetransfer
    

ChrootDirectory %h

@joshellington
joshellington / wp-path.php
Created March 27, 2012 20:18
wordpress image path
function get_image_path($img_src) {
global $blog_id;
if (isset($blog_id) && $blog_id > 0) {
$imageParts = explode('/files/', $img_src);
if (isset($imageParts[1])) {
$img_src = '/blogs.dir/' . $blog_id . '/files/' . $imageParts[1];
}else {return $imageParts ;}
}
return $img_src;
}
function deleteAllCookies() {
var cookies = document.cookie.split(";");
for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i];
var eqPos = cookie.indexOf("=");
var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
}
}
$.getJSON('https://graph.facebook.com/me/likes?access_token='+response.authResponse.accessToken+'&callback=?', function(d) {
console.log(d.data);
});
var mobile = (/iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));
if (mobile) {
// DROPKICK
}
@joshellington
joshellington / gist:1777497
Created February 9, 2012 05:10
Send URL to phone
javascript:(
function() {
var s = prompt('Enter the number you want to send to.', '15035363309');
if ( s != null && s != '' ) {
var req = new XMLHttpRequest();
var u = 'http://phonehome-app.heroku.com/sms/send/'+s+'?url='+encodeURIComponent(window.location.href);
req.open('GET', u, false);
req.send(null);
}
}
@joshellington
joshellington / gist:1705896
Created January 30, 2012 18:45
HTML5 Boilerplate Downloader Alias
alias html5='wget --no-check-certificate http://github.com/h5bp/html5-boilerplate/zipball/v3.0stripped ./; mv ./v3.0stripped ./boilerplate.zip; unzip boilerplate.zip; mv h5bp-html5-boilerplate-*/* .; rm -rf ./boilerplate.zip; rm -rf ./h5bp-html5-*;'
function build() {
var images = [];
$('.image').each(function() {
var position = $(this).data('isotope-item-position'),
img = $(this).find('img'),
src = $(img).attr('src'),
w = $(img).width(),
h = $(img).height();
def self.new_image(images, uid)
final = Magick::Image.new(1000, 600).matte_reset!
last = images.length - 1
images.each_with_index do |image, index|
o = image[1]
n = Magick::Image.read($dir+'/'+o[:src]).first
n.scale!(200, o[:height].to_i)
@joshellington
joshellington / gist:1144369
Created August 13, 2011 23:36
MongoMapper counting loop
date_started = Date.parse("2011-08-09")
date_now = Date.today
@by_day = []
@days_passed = date_now.mjd - date_started.mjd
(1..@days_passed).each do |day|
date = Kit.where(:created_at.gte => day.days.ago, :created_at.lte => (day-1).days.ago).fields(:created_at).first
count = Kit.count(:created_at.gte => day.days.ago, :created_at.lte => (day-1).days.ago)
@by_day.push("date" => date.created_at.strftime("%m/%d"), "count" => count)