Skip to content

Instantly share code, notes, and snippets.

View freshsnippets's full-sized avatar

Freshmade freshsnippets

View GitHub Profile
@freshsnippets
freshsnippets / ellipsis.js
Created March 8, 2012 16:53 — forked from qwertypants/ellipsis.js
JavaScript: Add ellipsis
function ellipsis(numOfWords, text, wordCount ) {
wordCount = text.trim().replace(/\s+/g, ' ').split(' ').length;
if(numOfWords <= 0 || numOfWords === wordCount){
return text;
} else {
text = text.trim().split(' ');
text.splice(numOfWords, wordCount, '...');
return text.join(' ');
}
}
@freshsnippets
freshsnippets / Fallback for CDN hosted jQuery.js
Created March 8, 2012 16:56
JavaScript: Fallback for CDN hosted jQuery
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
if (typeof jQuery == 'undefined') {
    document.write(unescape("%3Cscript src='/js/jquery-1.9.1.min.js' type='text/javascript'%3E%3C/script%3E"));
}
</script>
@freshsnippets
freshsnippets / html5.html
Created March 9, 2012 15:48
HTML: HTML5 Template
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Your Website</title>
</head>
<body>
<header>
<nav>
@freshsnippets
freshsnippets / ie7-select-cutoff.js
Created March 9, 2012 16:10
JavaScript: Fix Select Dropdown Cutoff in IE7
// Safely use $
(function($) {
$.fn._ie_select=function() {
return $(this).each(function() {
var a = $(this),
p = a.parent();
@freshsnippets
freshsnippets / jquery.ba-tinypubsub.js
Created March 21, 2012 17:15 — forked from cowboy/HEY-YOU.md
JavaScript: jQuery Tiny Pub/Sub
/* jQuery Tiny Pub/Sub - v0.7 - 10/27/2011
* http://benalman.com/
* Copyright (c) 2011 "Cowboy" Ben Alman; Licensed MIT, GPL */
(function($) {
var o = $({});
$.subscribe = function() {
o.on.apply(o, arguments);
@freshsnippets
freshsnippets / replaceText.js
Created April 3, 2012 19:21
JavaScript: jQuery replaceText
jQuery.fn.replaceText = function( search, replace, text_only ) {
return this.each(function(){
var node = this.firstChild,
val,
new_val,
remove = [];
if ( node ) {
do {
if ( node.nodeType === 3 ) {
val = node.nodeValue;
@freshsnippets
freshsnippets / Delete a File.php
Created May 3, 2012 03:11
PHP: Delete a File
$my_file = 'file.txt';
unlink($my_file);
@freshsnippets
freshsnippets / Close a File.php
Created May 3, 2012 03:12
PHP: Close a File
$my_file = 'file.txt';
$handle = fopen($my_file, 'w') or die('Cannot open file: '.$my_file);
//write some data here
fclose($handle);
@freshsnippets
freshsnippets / Append to a File.php
Created May 3, 2012 03:12
PHP: Append to a File
$my_file = 'file.txt';
$handle = fopen($my_file, 'a') or die('Cannot open file: '.$my_file);
$data = 'New data line 1';
fwrite($handle, $data);
$new_data = "\n".'New data line 2';
fwrite($handle, $new_data);
@freshsnippets
freshsnippets / Write to a File.php
Created May 3, 2012 03:13
PHP: Write to a File
$my_file = 'file.txt';
$handle = fopen($my_file, 'w') or die('Cannot open file: '.$my_file);
$data = 'This is the data';
fwrite($handle, $data);