Skip to content

Instantly share code, notes, and snippets.

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";
}
}
@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;
}
@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

#Archive Process

##What you need

  • Fresh clone of the git repo : zipped
  • Screen shots of every unique page : in a folder zipped
  • Folder with all (production) assets if not in repo : zipped
  • Export of the Facebook insights : all exports
  • Export of any other tracking data
  • Dump of the database if needed : NO USER DATA
def save_thumb media_id
local_path = Rails.root.to_s + '/public/media_thumbs/thumbapp_' + media_id + '.png'
remote_path = 'http://emgklovf.rtmphost.com/http/thumbnail_app/thumbapp_'+media_id+'.png'
open(local_path, 'wb') do |file|
file << open(remote_path, :ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE).read
end
end
fb_query = {
:impressions => "SELECT value FROM insights WHERE object_id='#{post_id}' AND metric='post_impressions' AND period=0",
:impressions_unique => "SELECT value FROM insights WHERE object_id='#{post_id}' AND metric='post_impressions_unique' AND period=0",
:consumptions => "SELECT value FROM insights WHERE object_id='#{post_id}' AND metric='post_consumptions' AND period=0",
:consumptions_unique => "SELECT value FROM insights WHERE object_id='#{post_id}' AND metric='post_consumptions_unique' AND period=0",
:stories => "SELECT value FROM insights WHERE object_id='#{post_id}' AND metric='post_stories' AND period=0",
:storytellers => "SELECT value FROM insights WHERE object_id='#{post_id}' AND metric='post_storytellers' AND period=0",
:engaged_users => "SELECT value FROM insights WHERE object_id='#{post_id}' AND metric='post_engaged_users' AND period=0",
:negative_feedback => "SELECT value FROM insights WHERE object_id='#{post_id}' AND metric='post_negative_feedback' AND period=0"
}
env RAILS_ENV=production DATABASE_URL=scheme://user:[email protected]/dbname bundle exec rake assets:precompile 2>&1
#!/bin/bash
# A simple script to backup an organization's GitHub repositories.
GHBU_BACKUP_DIR=${GHBU_BACKUP_DIR-"github-backups"} # where to place the backup files
GHBU_ORG=${GHBU_ORG-"<CHANGE-ME>"} # the GitHub organization whose repos will be backed up
GHBU_UNAME=${GHBU_UNAME-"<CHANGE-ME>"} # the username of a GitHub account (to use with the GitHub API)
GHBU_PASSWD=${GHBU_PASSWD-"<CHANGE-ME>"} # the password for that account
GHBU_GITHOST=${GHBU_GITHOST-"<CHANGE-ME>.github.com"} # the GitHub hostname (see comments)
GHBU_PRUNE_OLD=${GHBU_PRUNE_OLD-true} # when `true`, old backups will be deleted
GHBU_PRUNE_AFTER_N_DAYS=${GHBU_PRUNE_AFTER_N_DAYS-3} # the min age (in days) of backup files to delete
#!/bin/bash
# Script to backup git repo to S3
# Set bucket, dir, password and account to use for the backup. I keep mine in local env vars
# These are set by localrc which lives on an encrypted home directory and is executed by my bashrc
bucket=$GITHUB_BACKUP_BUCKET
dir=$GITHUB_BACKUP_DIR
password=$GITHUB_BACKUP_PASSWORD
account=$GITHUB_ACCOUNT

Templating in EE vs. Craft

Lots of people have asked, so here are a few common tasks you might do in your templates, as they would be written in ExpressionEngine vs. Craft.

Table of Contents

  1. Comments
  2. Conditionals
  3. Loops