Skip to content

Instantly share code, notes, and snippets.

View raducugheorghe's full-sized avatar

Raducu Gheorghe raducugheorghe

  • Romania
View GitHub Profile
@raducugheorghe
raducugheorghe / Powershell app backup script
Created February 6, 2015 09:01
[Powershell] Backup website and database from script
Import-Module SQLPS -DisableNameChecking
Import-Module PSCX
$dt = Get-Date -Format yyyyMMddHHmmss
$dbname = 'DBNAME'
Backup-SqlDatabase -ServerInstance .\SQLEXPRESS -Database $dbname -BackupFile "C:\Backups\$($dbname)_db_$($dt).bak"
write-zip "C:\WebSites\SITENAME\*" "C:\Backups\$($dbname)_website_$($dt).zip"
@raducugheorghe
raducugheorghe / NTP Setup
Last active March 1, 2016 08:50
[Powershell][Config] Set internet time server (NTP).ps1
Stop-Service w32time
w32tm /config /manualpeerlist:"0.ro.pool.ntp.org 1.ro.pool.ntp.org pool.ntp.org" /syncfromflags:MANUAL
Start-Service w32time
@raducugheorghe
raducugheorghe / AutocompleteTextarea
Last active August 29, 2015 14:14
[Javascript] Autocomplete Textarea from localStorage
var AutocompleteTextarea = function () {
this.lastFocus = {};
};
AutocompleteTextarea.prototype = (function () {
function setSave(textareaId, storageKey) {
$("form").on("submit", function (ev) {
@raducugheorghe
raducugheorghe / Sanitize folder name
Created December 9, 2014 12:51
[C#] Sanitize string to use as folder name
public static string SanitizeFolderName(string name)
{
string regexSearch = new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars());
var r = new Regex(string.Format("[{0}]", Regex.Escape(regexSearch)));
return r.Replace(name, "");
}
@raducugheorghe
raducugheorghe / Ensure file name does not exist
Created December 8, 2014 09:55
[C#] Ensure file name is unique at a given path (puts <filename (count).ext>)
private string EnsureFileNameDoesNotExist(string storagePath, string fileName)
{
while (System.IO.File.Exists(Path.Combine(storagePath, fileName)))
{
var extension = Path.GetExtension(fileName);
var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);
var fileCountMarker = new Regex("\\((?<count>[0-9]+)\\)$");
var matchResult = fileCountMarker.Match(fileNameWithoutExtension);