Skip to content

Instantly share code, notes, and snippets.

@ian128K
ian128K / bash_colours
Last active March 8, 2021 18:26
Shell script colours
## Colours and font styles
## Syntax: echo -e "${FOREGROUND_COLOUR}${BACKGROUND_COLOUR}${STYLE}Hello world!${RESET_ALL}"
# Escape sequence and resets
ESC_SEQ="\x1b["
RESET_ALL="${ESC_SEQ}0m"
RESET_BOLD="${ESC_SEQ}21m"
RESET_UL="${ESC_SEQ}24m"
# Foreground colours
@ian128K
ian128K / CSS Test-Button.md
Created September 21, 2014 07:23
Pure CSS button
@ian128K
ian128K / 1-Original.html
Last active August 29, 2015 14:06
By viewing the source and just minifying the inline JavaScript in the Opportunity Dashboard view from the mock Salesforce project that comes with the trial of Tableau Online, I was able to cut the file size from 42 KB to 32 KB — a reduction of almost 24%!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta name="csrf-param" content="authenticity_token"/>
<meta name="csrf-token" content="xpGnHlrBwMt4Sski2rk7xIKRT50B4KgNYXmlk3FY6wA="/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=2.0" />
<meta http-equiv="Expires" content="Thu, 01 Jan 1970 00:00:00 GMT"/>
@ian128K
ian128K / longestword.js
Created October 2, 2014 04:17
Function takes an input string and returns the longest word in the string
function LongestWord(sen) {
if(typeof sen = "undefined") {
return "You have to pass a sentence in as a string.";
} else {
var words = sen.split(" ");
if(words.length = 1) {
return words[0];
} else {
var largest = 0;
var output = "";
@ian128K
ian128K / factorial.js
Created October 2, 2014 04:26
Function for outputting the factorial of a number
function factorial(num) {
// If the number is less than 0, reject it.
if (num < 0) {
return "You can't do a factorial on negative numbers.";
}
// If the number is 0, its factorial is 1.
else if (num == 0) {
return 1;
}
var output = num;
@ian128K
ian128K / reversestring.js
Created October 2, 2014 04:34
Function for reversing all the letters in a string
function reverseString(str) {
var output;
if((typeof str === "undefined") || (typeof str !== "string")) {
return "You have to pass a string as an argument."
}
output = str.split("").reverse().join("");
return output;
}
@ian128K
ian128K / lettershifter.js
Created October 2, 2014 05:24
Function for shifting all letters in a string one letter forward in the alphabet
function letterShifter(message) {
var lc_alphabet, uc_alphabet, lc_key, uc_key, coded, i, ch, index;
lc_alphabet = "abcdefghijklmnopqrstuvwxyz";
uc_alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
lc_key = "bcdefghijklmnopqrstuvwxyza";
uc_key = "BCDEFGHIJKLMNOPQRSTUVWXYZA";
coded = "";
for(i = 0; i < message.length; i++) {
@ian128K
ian128K / addfrom1tonum.js
Created October 2, 2014 05:33
Function for adding all numbers from 1 to a given number
function addFromOneToNum(num) {
var output;
output = num;
for(var i = 1; i < num; i++) {
output += i;
}
return output;
}
@ian128K
ian128K / firstlettercapitalise.js
Created October 2, 2014 06:41
Function for capitalising the first letters in a sentence
function FirstLetterCapitalise(message) {
if((typeof message === "undefined") || (typeof message !== "string")) {
return "You have to pass in a string.";
} else {
var buffer, blength, newbuf, newstr, nblength, char, result;
buffer = message.split(" ");
blength = buffer.length;
result = "";
for(var i = 0; i < blength; i++) {
char = buffer[i].charAt(0);