Skip to content

Instantly share code, notes, and snippets.

@CarlRevell
CarlRevell / toString(base).js
Last active January 1, 2016 18:19
Don't forget JavaScript will return strings converted to a given base from a number...
parseInt(64).toString(); // "64"
parseInt(64).toString(10); // "64"
parseInt(64).toString(2); // "1000000"
parseInt(64).toString(8); // "100"
parseInt(64).toString(16); // "40"
@CarlRevell
CarlRevell / ie6-and-ie7-one-character-hacks
Created December 30, 2013 15:14
Old but sometimes useful single character CSS hacks for targeting IE6 and IE7, typically when testing some bugfix for these old browsers.
#myelement {
color: #999; /* shows in all browsers */
*color: #999; /* notice the * before the property - shows in IE7 and below */
_color: #999; /* notice the _ before the property - shows in IE6 and below */
}
@CarlRevell
CarlRevell / git-snippets
Last active January 1, 2016 18:19
Useful Git commands I've used and forgotten...
# shows changes required to get from master branch to recyclingMicrosite; effectively what’s in recyclingMicrosite that’s NOT in master.
git diff --name-status master..recyclingMicrosite
# The triple-dot syntax ... shows what is in either master OR recyclingMicrosite but not both
# typically these are commits since recyclingMicrosite was branched from master.
git diff --name-status master...recyclingMicrosite
# remove the recyclingMicrosite branch from the repo
@CarlRevell
CarlRevell / dos-date-time-snippets.bat
Created December 30, 2013 15:37
Useful DOS .cmd/.bat file date and time snippets.
SET YEAR=%DATE:~6,4%
SET MONTH=%DATE:~3,2%
SET DAY=%DATE:~0,2%
SET HOUR=%TIME:~0,2%
IF /I %HOUR% LEQ 9 SET HOUR=0%HOUR:~1,1%
SET MINUTE=%TIME:~3,2%
SET SECOND=%TIME:~6,2%
SET ISODATE=%YEAR%-%MONTH%-%DAY%_%HOUR%-%MINUTE%-%SECOND%
@CarlRevell
CarlRevell / mount-windows-share-on-CentOS
Last active January 1, 2016 18:28
Mounts a Windows share on CentOS. You can exclude the password= and it will prompt for the password.
mount -t cifs //ntserver/share -o username=bobM,password=myPassword /mnt/ntserver
@CarlRevell
CarlRevell / MySQL-log-to-table
Created December 30, 2013 15:45
Turn on SQL statement logging in MySQL to a table mysql.general_log
SET GLOBAL log_output = 'TABLE';
SET GLOBAL general_log = 'ON';
@CarlRevell
CarlRevell / MySQL-log-to-file
Created December 30, 2013 15:46
Turn on SQL statement logging in MySQL to the file /path/to/your/logfile.log
SET GLOBAL log_output = "FILE"; --which may be set by default, I think.
SET GLOBAL general_log_file = "/path/to/your/logfile.log"
SET GLOBAL general_log = 'ON';
@CarlRevell
CarlRevell / Microsoft-Word-reverse-page-numbering
Created December 30, 2013 15:49
Using a combination of Ctrl-F9 (to insert field codes), F9 (to show field codes) and Alt-F9 (not sure) I inserted the following formula into the document footer to display reverse page numbers.
{= {NUMPAGES} - {PAGE} + 1}
@CarlRevell
CarlRevell / cacheBusterMinutes.js
Created December 30, 2013 15:52
Returns the same cache buster value for a given number of minutes. I use it by appending '&cb=' + cacheBusterMinutes(5) for example to ensure the same URL is used for 5 minutes and then changes after 5 minutes with a different &cb querystring value.
function cacheBusterMinutes(cache_for_minutes) {
var d = new Date;
return d.getFullYear() + ("0" + d.getMonth()).slice(-2) + ("0" + d.getDate()).slice(-2) + ("0" + d.getHours()).slice(-2) + ("0" + parseInt(d.getMinutes() / cache_for_minutes)).slice(-2);
}
@CarlRevell
CarlRevell / styling-based-on-number-of-elements.css
Created December 30, 2013 15:56
Neat CSS trick styling child elements based on how many of them there are... I used this concept on a contacts page to increase line-height when there were only three contact details (name, title and tel) and reduce line-height when there were four details (name, title, tel and email) to maintain the same height for the contact block.
/* one item */
.employee span:first-child:nth-last-child(1) {
width:100%;
}
/* two items */
.employee span:first-child:nth-last-child(2)
, span:first-child:nth-last-child(2) ~ span {
width:50%;
}