Skip to content

Instantly share code, notes, and snippets.

View bohman's full-sized avatar

Linus Bohman bohman

View GitHub Profile
@bohman
bohman / htmlstrip.js
Created May 11, 2011 11:00
Just a small thing I wanted to show someone else. I dislike it, because it's bad.
.replace(/<(?:.|\s)*?>/g, '')
.replace(/&auml;/gi, 'ä')
.replace(/&Auml;/gi, 'Ä')
.replace(/&ouml;/gi, 'ö')
.replace(/&Ouml;/gi, 'Ö')
.replace(/&aring;/gi, 'å')
.replace(/&Aring;/gi, 'Å')
.replace(/&amp;/gi, '&')
.replace(/&rdquo;/gi, '\"')
.replace(/&quot;/gi, '\"')
@bohman
bohman / viewport.js
Last active November 20, 2020 11:37
jQuery get viewport size
// -----------
// Debugger that shows view port size. Helps when making responsive designs.
// -----------
function showViewPortSize(display) {
if(display) {
var height = jQuery(window).height();
var width = jQuery(window).width();
jQuery('body').prepend('<div id="viewportsize" style="z-index:9999;position:fixed;top:40px;left:5px;color:#fff;background:#000;padding:10px">Height: '+height+'<br>Width: '+width+'</div>');
jQuery(window).resize(function() {
@bohman
bohman / getdb.sh
Created March 20, 2012 10:23
Database dump script
#!/usr/bin/env bash
# Remote database credentials
RDBNAME=""
RDBUSER=""
RDBPASS=""
# Local database credentials
LDBNAME=""
LDBUSER=""
@bohman
bohman / gist:2844242
Last active October 5, 2015 17:28
Random sharing thingies if you only want to use links
<a target="_blank" href="https://twitter.com/intent/tweet?text=YOUR-TITLE&url=YOUR-URL&via=TWITTER-HANDLE">Tweet</a>
<a target="_blank" href="http://www.facebook.com/sharer/sharer.php?u=YOUR-URL">Share on Facebook</a>
<a target="_blank" href="https://plus.google.com/share?url=YOUR-URL">Plus on Google+</a>
<a target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&url=YOUR-URL&title=YOUR-TITLE&summary=YOUR-SUMMARY&source=YOUR-URL">Share on LinkedIn</a>
<a target="_blank" href="http://pinterest.com/pin/create/button/?url=YOUR-URL&description=YOUR-DESCRIPTION&media=YOUR-IMAGE-SRC">Pin on Pinterest</a>
@bohman
bohman / sort_array_on_value.php
Created September 12, 2012 07:29
sort_array_on_value() - sorting multidimensional arrays into hyperspace
//
// Easy lil' sorting thingamajig. Mad creds to Antonio Navarro of 040.
//
function sort_array_on_value($array_to_sort, $sort_on_value, $descending = false) {
$sortArr = array();
foreach ($array_to_sort as $key => $value) {
$sortArr[$key] = $value[$sort_on_value];
}
@bohman
bohman / stretch.css
Last active December 11, 2015 02:19
Stretch: simple way to stretch boxes to edge of screen without additional elements. Here's a good article with description: http://css-tricks.com/full-browser-width-bars/
.center {
width: 980px;
margin-left: auto;
margin-right: auto;
}
html, body {
overflow-x: hidden; /* Prevents horizontal scroll */
}
@bohman
bohman / wp_update_url.sql
Created January 16, 2013 16:04
Simple query to update URLs in a WP install. Useful when moving a site. Wrote it a long time ago, lost it when my computer got stolen, was frustrated, decided to store it here.
SET @oldurl = 'dev1.nollfyranoll.se';
SET @newurl = 'pilgrimsvagen.se';
UPDATE wp_posts SET POST_CONTENT = replace(POST_CONTENT, @oldurl, @newurl);
UPDATE wp_posts SET GUID = replace(GUID, @oldurl, @newurl);
UPDATE wp_options SET OPTION_VALUE = replace(OPTION_VALUE, @oldurl, @newurl);
@bohman
bohman / responsiveeasteregg.css
Last active December 13, 2015 22:49
Small responsive easter egg. Do with it as you wish.
/*
This is pretty much the smallest you can make the firefox screen without programmatically setting the width.
Chrome and Safari prevents you from going below 400px. An iPhone is 320px, and the smallest Android about 240px IIRC.
The site is pretty much useless like this, so... have an egg.
*/
@media only screen and (max-width: 92px) {
body * {
display: none;
}
@bohman
bohman / gist:9526448
Last active August 29, 2015 13:57
example on how to modify queries with filters in wordpress
//---------------------------------
// Modify these taxonomy pages to show all posts
// and sort them alphabetically
//---------------------------------
add_filter('posts_orderby', 'mashcat_alphabetical');
add_filter('post_limits', 'mashcat_limits');
function mashcat_alphabetical($orderby) {
if(!is_admin() && (is_tax('foreign-apis') || is_tax('api-tags') || is_tax('mashup-tags'))) {
input[data-onoff]:empty {
margin-left: -9999px;
}
input[data-onoff]:empty ~ label {
position: relative;
float: left;
height: 22px;
line-height: 22px;
text-indent: 50px;