Skip to content

Instantly share code, notes, and snippets.

@jrdmb
jrdmb / extract_urls_from_string.php
Created January 10, 2016 00:38
PHP: Extract Urls from String
<?php
function getUrls($string) {
//adapted from: https://stackoverflow.com/questions/11588542/get-all-urls-in-a-string-with-php
$regex = '/https?\:\/\/[^\" \n]+/i';
preg_match_all($regex, $string, $matches);
//note below that we use $matches[0], this is because we have an array of arrays
foreach ($matches[0] as $url) {
$s1 = substr($url, 0, strlen($url)-2);
$s2 = '<a href="' . $s1 . '">' . $s1 . '</a>';
echo "$s2<br />\n";
Option Explicit
Dim oFSO, oFolder, oSubFolder, oSubFolders, sDirectoryPath, sTempDir
Dim oFileCollection, oFile, sDir
Dim iDaysOld, iFiles, iFolders
Dim wshShell
'Get user Temp directory path from environment variable
Set wshShell = CreateObject( "WScript.Shell" )
sTempDir = wshShell.ExpandEnvironmentStrings( "%TEMP%" )
'An alternate is "%LOCALAPPDATA%\Temp"
@jrdmb
jrdmb / Changing E-Mail Addresses Globally
Last active August 29, 2015 14:20
from Pro-Git eBook
# from topic "Changing E-Mail Addresses Globally in Pro-Git eBook (location 3892 of 9052)
git filter-branch --commit-filter '
if [ "$GIT_AUTHOR_EMAIL" = "my_old_email@me.com" ];
then
GIT_AUTHOR_EMAIL="my_new_email.@me.com";
git commit-tree "$@";
else
git commit-tree "$@";
fi' HEAD
------------------------------------------------------------------------
-- Create a Comma Delimited List Using SELECT Clause From Table Column
-- from: http://tinyurl.com/7ac6yaj (blog.sqlauthority.com)
------------------------------------------------------------------------
USE AdventureWorks
GO
DECLARE @listStr VARCHAR(MAX)
SELECT @listStr = COALESCE(@listStr+',' ,'') + Name
FROM dbo.Product
SELECT @listStr
@jrdmb
jrdmb / vba_advapi32_64-bit.vb
Created April 9, 2015 16:47
How to Use advapi32.dll Encryption Functions in 64-bit VBA
Option Compare Database
Option Explicit
'Reference: http://khoiriyyah.blogspot.com/2012/06/vb6-hash-class-md5-sha-1-sha-256-sha.html
'The above article is excellent but that code works for 32-bit Access/Excel only.
'This works on both 32-bit and 64-bit Access/Excel.
'Requires no dll References in the VB Editor. It uses advapi32.dll, which needs no Reference
' as these are Windows API calls only.
'I have not seen documented anywhere else on the Internet how to make these calls in 64-bit apps.
@jrdmb
jrdmb / tsql_string_encryption.sql
Created April 9, 2015 02:30
Sql Server String Encryption
SELECT HASHBYTES('sha2_512', 'mypassword')
--algorithms: MD2 | MD4 | MD5 | SHA | SHA1 | SHA2_256 | SHA2_512
declare @enc varbinary(256)
select @enc = EncryptByPassPhrase('key', 'mypassword' )
--returns: 0x01000000D6191ADF19FF136F0A82E469E55AF781FC9D61904BA73039971C82FE88D3E758
select Cast(DECRYPTBYPASSPHRASE('key', @enc) as varchar(4000))
-- #sqlserver #tsql #encryption
@jrdmb
jrdmb / Chrome_Dev_Tools.md
Last active August 29, 2015 14:18
Chrome Dev Tools
@jrdmb
jrdmb / angularjs_tips.md
Last active August 29, 2015 14:18
AngularJS Tips
@jrdmb
jrdmb / javascript_tips.md
Last active August 29, 2015 14:18
Javascript Tips

[Tips, Tricks, Best Practices] (http://modernweb.com/2013/12/23/45-useful-javascript-tips-tricks-and-best-practices/) | [Style Guide] (https://github.com/airbnb/javascript) | [Resources Collection] (https://gist.github.com/Neener54/3774166) |

2 – use === instead of ==

The == (or !=) operator performs an automatic type conversion if needed. The === (or !==) operator will not perform any conversion. It compares the value and the type, which could be considered faster than ==.

[10] === 10    // is false
[10]  == 10    // is true
'10' == 10     // is true
@jrdmb
jrdmb / github_gist_tips
Last active August 29, 2015 14:18
GitHub and Gist Tips
To list remote Git branches (from: http://rakhesh.com/coding/list-remote-branches/):
git ls-remote
git remote show origin
Create and delete local and remote Git branches
http://rakhesh.com/coding/creating-and-delete-remote-git-branches/
Move the .git folder out of the working tree
http://rakhesh.com/coding/how-to-move-separate-the-git-folder-out-of-your-working-tree/