Skip to content

Instantly share code, notes, and snippets.

View codfish's full-sized avatar

Chris O'Donnell codfish

View GitHub Profile
// You are looking for the /.../s modifier, also known as the dotall modifier. It forces the dot . to also match newlines, which it does not do by default.
// The bad news is that it does not exist in Javascript. The good news is that you can work around it by using a character class (e.g. \s) and its negation (\S) together, like this:
var htmlStringWithScriptTags = "sdf <script>test fsajkdfn</script> a sdasda <script> sdfsdfsdf \n \
sdfsdfsd </script> sjkndfjkasnd <script> sdfsdfsdf \n \
sdfsdfsd </script>sjkndfjkasnd <script> sdfsdfsdf \n \
sdfsdfsd </script>";
// incorrect
htmlStringWithScriptTags.replace(/<script.*?<\/script>/g, '');
@codfish
codfish / webkit-line-clamp.css
Created October 24, 2013 01:21
"-webkit-line-clamp is an unsupported WebKit property that limits the number of lines of text displayed in a block element. In order to achieve the effect, it needs to be combo-ed with a couple of other exotic WebKit properties."
/**
* Truncate paragraph with an ellipsis, while specifying exactly how many lines you want
* source: http://dropshado.ws/post/1015351370/webkit-line-clamp
*/
#content-body {
overflow : hidden;
text-overflow: ellipsis;
display: -webkit-box;
@codfish
codfish / gist:6993840
Created October 15, 2013 15:56
Flush DNS on mac
sudo killall -HUP mDNSResponder
@codfish
codfish / gist:6624919
Last active December 23, 2015 10:59
Browser caching your scripts and styles intelligently
<link rel="stylesheet" type="text/css" href="/css/main.<?php echo filemtime('/path/to/css/main.css'); ?>.css" />
<script language="javascript" src="/js/common.<?php echo filemtime('/path/to/js/common.js'); ?>.js">
</script>
# Add a rewrite in apache
RewriteRule ^(css|js)/(.*)\.[0-9]+\.(.*)$ /$1/$2.$3 [L]
# nginx
rewrite ^(css|js)/(.*)\.[0-9]+\.(.*)$ /$1/$2.$3 last;
@codfish
codfish / gitDiffBranches.sh
Last active December 21, 2015 00:08
Compare Git Branches, Compare Two Files in Different Branches
# http://blog.firsthand.ca/2011/05/compare-git-branches-compare-two-files.html
# diff two branches
$ git diff --name-status branch1..branch2
# diff of a specific file between two commits/branchs
$ git diff feature-branch master -- myfile.css
$ git diff eaa241d 4d49814 -- myfile.css
@codfish
codfish / textRendering.css
Last active December 20, 2015 18:29
Improve text legibility for webkit browsers
text-rendering: optimizeLegibility;
@codfish
codfish / dynamic_iframe_height.js
Last active September 16, 2015 20:52
Update the height of an iframe dynamically based on the height of the source content. Code is dependent on jQuery, and will only work when iframe is the same host/domain as the parent page, or if you have access to the content of the iframe. Reference: http://goo.gl/Rz3Ryz
// @example
// <iframe src="/form.html" id="infographic-iframe"></iframe>
document.getElementById('infographic-iframe').style.height = $('#infographic-iframe').contents().height() + 'px';
@codfish
codfish / php_show_errors.php
Last active August 29, 2015 14:25
Quick way to display all php errors on your page for debugging purposes.
<?php
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);
@codfish
codfish / regex-html-attribute.js
Last active August 29, 2015 14:24
Quick and dirty way to grab the value of an attribute from an HTML string with regex.
var html = '<iframe width="420" height="315" src="https://www.youtube.com/embed/cwhLueAWItA" frameborder="0" allowfullscreen></iframe>';
var width = html.match( /(?:.*width="(.*?)".*)?/i ).pop();
var height = html.match( /(?:.*height="(.*?)".*)?/i ).pop();
var src = html.match( /(?:.*src="(.*?)".*)?/i ).pop();
@codfish
codfish / clean-multi-line-string.js
Last active August 29, 2015 14:22
Interesting way to write a multiline string in JS, to keep things clean.
var multiLiner = String() +
'<section>' +
'<div class="content-wrapper">' +
'<a href="#" class="js-link">Click Here</a>' +
'</div>' +
'</section>';