Skip to content

Instantly share code, notes, and snippets.

View seantunwin's full-sized avatar

Sean T. Unwin seantunwin

View GitHub Profile
@seantunwin
seantunwin / delayed-text-display.js
Last active December 18, 2015 03:19
This is the original script that compelled me to make a modular version in order to be reusable - https://github.com/seantunwin/chardelay.js | View the project: http://seantunwin.github.io/chardelay.js
/**
* This is the original script that compelled me to make a modular version in order to be reusable
* - Repo: https://github.com/seantunwin/chardelay.js
* - View the project: http://seantunwin.github.io/chardelay.js
**/
/* Set Array */
var arr = [1,2,3,4];
/* Create <p> element */
var el = document.createElement('p');
@seantunwin
seantunwin / Remove then add CSS style tags from an HTML document
Last active December 18, 2015 09:59
Removing then adding CSS via locating <style> tags in the document using jQuery In this example we locate the first <style> tag and remove it while keeping reference to the content of it in a variable. When our checkbox is clicked we re-add the CSS style(s) to the docuemnt.
/*
* Removing then adding CSS via locating <style> tags in the document using jQuery
*
* In this example we locate the first <style> tag and remove it
* while keeping reference to the content of it in a variable.
*
* When our checkbox is clicked we re-add the CSS style(s) to the docuemnt.
*
*/
<script>
@seantunwin
seantunwin / lazy-load-files.js
Last active June 10, 2021 06:07
Lazy load JavaScript files
/* This is a technique to lazy load your javascript files
* Handy for those pesky slow, load blocking off-site scripts
* function lazyLoad
* @s: String of path to file
*/
function lazyLoad(s) {
var d = window.document,
b = d.body, /* appends at end of body, but you could use other methods to put where you want */
e = d.createElement("script");
@seantunwin
seantunwin / _get-middle.function.scss
Created March 19, 2014 19:43
Sass: Find the middle of a line segment. Useful for when you have multiple elements with defined widths or heights and need to find the mid-point.
//find the middle of a line segment
@function get-middle($values...) {
$result: 0;
@each $value in $values {
$result: ($value / 2) + $result;
}
@return $result;
}
@seantunwin
seantunwin / change-button-text.js
Last active August 29, 2015 14:06
Function to change the text of a button using textContent with a fallback for old browsers
/* Try it at Codepen.io - http://codepen.io/seantunwin/pen/aDsHE */
/**
* Change the text of a button
* @param {el} object HTMLElement: button to change text of
* @param {dText} string: default text
* @param {nText} string: new text
**/
function changeText(el, dText, nText) {
var content = '',
@seantunwin
seantunwin / sublime-user-preferences
Last active August 29, 2015 14:06
My Sublime User Preferences
{
"auto_complete_commit_on_tab": true,
"bold_folder_labels": true,
"color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme",
"file_exclude_patterns":
[
"*.zip"
],
"font_face": "FantastiqueSansMono",
"font_size": 11,
@seantunwin
seantunwin / posPow.js
Last active August 29, 2015 14:16
Easy power function (like Math.pow()) for positive exponents using the shift-left bitwise operator
// Where @var exponent is less than or equal to 1
// @return is @var num
function posPow(num, exponent) {
return num << ((exponent > 1) ? (exponent - 1) : 0 );
}
@seantunwin
seantunwin / file-get-chmod.sh
Created March 24, 2015 14:31
Get the numerical permission of a file or folder
stat -c %a $file
@seantunwin
seantunwin / cwd-dos2cygwin.js
Last active August 29, 2015 14:19
When using Nodejs with Cygwin it is sometimes helpful to convert DOS paths to linux with the Cygwin prefix.
/**
* Convert slashes in DOS path strings to linux
* @use replace(/\\/g, '/')
*
* And
*
* Replace drive letter and colon with 'cygwin/' then the drive letter
* @use .replace(/^(\w):/i, 'cygwin/$1')
**/
var dir = process.cwd().replace(/\\/g, '/').replace(/^(\w):/i, 'cygwin/$1');
@seantunwin
seantunwin / create-pyramid.js
Created April 17, 2015 20:16
Output a textual pyramid
/**
* Create a pyramid
* @uses pyramid(<Number:Integer>)
* @var steps: [Number:Int] Number of pyramid steps
* @returns String
*
* @example:
* console.log(pyramid(6));
* Outputs:
* #