Skip to content

Instantly share code, notes, and snippets.

View botaor's full-sized avatar

Rui Botão botaor

View GitHub Profile
@botaor
botaor / app.exe.config
Created February 25, 2016 15:46
Internal logging for log4net
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
...
<appSettings>
<add key="log4net.Internal.Debug" value="true"/>
</appSettings>
<system.diagnostics>
<trace autoflush="true">
<listeners>
<add
@botaor
botaor / Defer.html
Created January 2, 2014 14:20
Defer loading of Javascript files untill the page is already loaded
<script type="text/javascript">
function downloadJSAtOnload() {
var element = document.createElement("script");
element.src = "defer.js";
document.body.appendChild(element);
}
if (window.addEventListener)
window.addEventListener("load", downloadJSAtOnload, false);
else if (window.attachEvent)
window.attachEvent("onload", downloadJSAtOnload);
@botaor
botaor / ChangeScreenOrientation.c
Created December 5, 2013 11:43
Change the screen orientation in Windows programatically
// code copied from: http://msdn.microsoft.com/en-us/library/ms812499.aspx
// Not acutally tested on a real system
DEVMODE dm;
// initialize the DEVMODE structure
ZeroMemory(&dm, sizeof(dm));
dm.dmSize = sizeof(dm);
if (0 != EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm))
{
@botaor
botaor / unplug.cmd
Created July 4, 2013 09:07
Call unplug applet from the command line (windows)
C:\WINDOWS\system32\rundll32.exe shell32.dll,Control_RunDLL hotplug.dll
@botaor
botaor / Language.php
Created May 28, 2013 10:25
Detect browser language
function get_client_language($availableLanguages, $default='en')
{
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
$langs=explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']);
foreach ($langs as $value){
$choice=substr($value,0,2);
if(in_array($choice, $availableLanguages)){
return $choice;
}
@botaor
botaor / Errors.php
Created May 28, 2013 10:24
Email error logs to yourself
<?php
// Our custom error handler
function my_error_handler($number, $message, $file, $line, $vars)
{
$email = "
<p>An error ($number) occurred on line
<strong>$line</strong> and in the <strong>file: $file.</strong>
<p> $message </p>";
@botaor
botaor / Distance.js
Created May 28, 2013 10:23
Calculate distance between two points
function getDistanceBetweenPointsNew($latitude1, $longitude1, $latitude2, $longitude2)
{
$theta = $longitude1 - $longitude2;
$miles = (sin(deg2rad($latitude1)) * sin(deg2rad($latitude2))) + (cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * cos(deg2rad($theta)));
$miles = acos($miles);
$miles = rad2deg($miles);
$miles = $miles * 60 * 1.1515;
$feet = $miles * 5280;
$yards = $feet / 3;
$kilometers = $miles * 1.609344;
@botaor
botaor / Sanitize.php
Created May 28, 2013 10:21
Sanitize database inputs in PHP
<?php
function cleanInput($input)
{
$search = array(
'@<script[^>]*?>.*?</script>@si', // Strip out javascript
'@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags
'@<style[^>]*?>.*?</style>@siU', // Strip style tags properly
'@<![\s\S]*?--[ \t\n\r]*>@' // Strip multi-line comments
);
@botaor
botaor / Dialog.cpp
Last active December 15, 2015 00:08
In Windows MFC if you have a dialog based application, do not exit it with <enter> or <esc>.
class CMyDlg : public CDialog
{
....
protected:
afx_msg void OnCancel();
afx_msg void OnOK();
afx_msg void OnClose();
afx_msg void OnMyExit();
....
@botaor
botaor / SheetName
Created March 13, 2013 10:52
Get the names of the sheets in an Excel Workbook
Function SHEETNAME(Optional ShtOrder As Long = 0, _
Optional ByVal IncludeHiddenSheet As Boolean = False) As Variant
'// Developed by Kris @ ExcelFox.com
Dim ShtCount As Long
Dim i As Long
Dim n As Long
ShtCount = ThisWorkbook.Worksheets.Count