Skip to content

Instantly share code, notes, and snippets.

@linuslundahl
linuslundahl / .inputrc
Created February 9, 2010 20:52
Bash key shortcuts
"\e[1~": beginning-of-line # Home key
"\e[4~": end-of-line # End key
"\e[3~": delete-char # Delete key
"\e[5C": forward-word # Ctrl+right
"\e[5D": backward-word # Ctrl+left
"\e\e[C": forward-word # Alt+right
"\e\e[D": backward-word # Alt+left
"\C-K": unix-line-discard # Ctrl+K
"\e\"": "@{}\e[D" # Insert @{} move cursor into braces
@linuslundahl
linuslundahl / Ignore .DS_Store forever
Created September 13, 2010 09:55
Make git always ignore .DS_Store
$ git config --global core.excludesfile ~/.gitignore
$ echo .DS_Store >> ~/.gitignore
@linuslundahl
linuslundahl / remove-wp-attachment-thumbs.php
Created November 28, 2010 19:27
Remove generated attachment thumbnails from wordpress database.
global $wpdb;
$query = "SELECT meta_value, meta_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attachment_metadata'";
$result = $wpdb->get_results($query);
foreach ($result as $item) {
$meta = unserialize($item->meta_value);
unset($meta['sizes']);
$wpdb->update( 'wp_vira_postmeta', array('meta_value' => serialize($meta)), array('meta_id' => $item->meta_id) );
}
@linuslundahl
linuslundahl / move_wordpress_blog.php
Created February 11, 2011 10:32
Change wordpress url in code, when there's no access to phpMyAdmin.
global $wpdb;
$query = "UPDATE $wpdb->posts SET post_content = REPLACE (
post_content,
'http://old.com',
'http://new.com')";
$wpdb->query($query);
$query = "UPDATE $wpdb->posts SET guid = REPLACE (
@linuslundahl
linuslundahl / jquery.el-in-view.js
Created December 10, 2011 11:20
jQuery Function that checks if an element is currently in the browser viewport.
function isScrolledIntoView(elem) {
var $win = $(window),
$elem = $(elem),
docViewTop = $win.scrollTop(),
docViewBottom = docViewTop + $win.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
return ((elemBottom >= docViewTop) && (elemTop <= docViewBottom) && (elemBottom <= docViewBottom) && (elemTop >= docViewTop));
}
@linuslundahl
linuslundahl / _mixins.sass
Last active October 27, 2015 09:37 — forked from simme/_mixins.sass
SASS Mixins and Functions
// Rounds all the corners of a box
@mixin vector-bg-with-fallback($name) {
background-image: image-url('#{$name}.png');
background-image: none, image-url('#{$name}.svg');
}
@mixin border-radius($radius, $clip: padding-box)
-webkit-border-radius: $radius
-moz-border-radius: $radius
-o-border-radius: $radius
@linuslundahl
linuslundahl / services-resource.php
Created April 11, 2012 10:04
Services resource definition
$resources['ur_segment'] = array(
'operations' => array(
'create' => array(
'callback' => '_ur_segment_create',
'help' => t('Creates a segment.'),
'args' => array(
array(
'name' => 'segment',
'optional' => FALSE,
'source' => 'data',
@linuslundahl
linuslundahl / sass-button.sass
Created May 22, 2012 08:16
SASS with Compass button style
@mixin button($bg, $color)
background: $orange
@include background-image(linear-gradient(($bg*1.6), $bg 40%, $bg))
@include box-shadow(($bg*2) 0 1px 1px 0 inset)
@include border-radius(5px)
border: 1px solid ($bg/1.2)
color: $color
font: normal normal 300 1em/150% "Helvetica Neue", Arial, sans-serif
margin: 0 10px 0 0
padding: 5px 10px
@linuslundahl
linuslundahl / siteup
Created August 31, 2012 11:53
Linode vhost script
#! /bin/bash
#
# =======================
# Linode vhost script
# =======================
function make_vhost
{
cat <<- _EOF_
<VirtualHost *:80>
@linuslundahl
linuslundahl / error_log
Created August 31, 2012 12:23
Send php error_log to OS X console.
$ mate /etc/php.ini
Add: error_log = /Users/USERNAME/Library/Logs/php.log
$ sudo chmod 755 ~/Library/ && sudo chmod 755 ~/Library/Logs && sudo touch ~/Library/Logs/php.log && sudo chmod 777 ~/Library/Logs/php.log