Skip to content

Instantly share code, notes, and snippets.

@volpoli
volpoli / RunPSScriptAsAdmin.bat
Created July 5, 2018 20:04
Run a powershell script as Admin from cmd
REM use the same filename for both .ps1 and .bat
@echo off
PowerShell.exe -Command "& {Start-Process PowerShell.exe -ArgumentList '-ExecutionPolicy Bypass -File ""%~dpn0.ps1""' -Verb RunAs}"
PAUSE
@volpoli
volpoli / AddLocalAdminAccount.ps1
Last active July 5, 2018 20:06
POWERSHELL SCRIPT - add a local admin user and set password for never expires & cannot be changed
#N.B. POWERSHELL 5.1 REQUIRED
$Username = ""
$Password = ""
$group = "Administrators"
$adsi = [ADSI]"WinNT://$env:COMPUTERNAME"
$existing = $adsi.Children | where {$_.SchemaClassName -eq 'user' -and $_.Name -eq $Username }
@volpoli
volpoli / php_objects_references.php
Last active May 30, 2018 01:53
PHP: Objects and references - difference between cloning an object vs assigning an object to a variable
<?php
class A {
public $a = 1;
}
$a = new A();
$b = $a;
@volpoli
volpoli / gist:570e4ab8f93d3ff4e83e
Created September 24, 2014 17:04
stop gif loop javascript
setTimeout(function() {
setInterval(function() {
$('#img1').attr('src',$('#img1').attr('src'))
},1)
}, 2000)
@volpoli
volpoli / gist:8f27465ef81d54e7fc28
Last active August 29, 2015 14:03
convert seconds to readable time string in PHP
/**
* Convert seconds to readable time string
*
* @param integer $seconds => seconds es: 3600(1h)
* @return string $finalTime => time string like 1:00:00 or 0:34
* or an empty string if @param $seconds isn't numeric
*/
public function secondsToTime($seconds){
if(is_numeric($seconds) && $seconds > 0){
$hours = floor($seconds / 3600);