Skip to content

Instantly share code, notes, and snippets.

Steven Swenson ctigeek

Block or report user

Report or block ctigeek

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ctigeek
ctigeek / Cache.cs
Last active Aug 29, 2015
Generic .net cache....
View Cache.cs
class Cache<T> where T : someBaseType
{
public readonly TimeSpan LifeSpan;
public readonly SemaphoreSlim semaphore;
private Dictionary<string, CacheItem<T>> itemDict;
public Cache(TimeSpan lifespan)
{
this.LifeSpan = lifespan;
@ctigeek
ctigeek / AlertInput.ino
Last active Aug 29, 2015
Sending an email from Arduino
View AlertInput.ino
const int sensorPin = A0; // the number of the pushbutton pin
long lastDebounceTime = 0; // the last time the output pin was toggled
long debounceDelay = 150; // the debounce time; increase if the output flickers
int sensorValue = 0;
int alreadyAlerted = 0;
void setup() {
Serial.begin(9600);
Serial.println(F("Serial is working.... "));
View CreateDomainForest.ps1
Install-WindowsFeature -Name Ad-Domain-Services -IncludeManagementTools
###local admin password....
$pass = ConvertTo-SecureString "XXXXXXXXXX" -AsPlainText -Force
Install-ADDSForest -DomainName "MyNewDomain.local" -SafeModeAdministratorPassword $pass
@ctigeek
ctigeek / scheduling.cs
Last active Aug 29, 2015
Sudo code for scheduling
View scheduling.cs
//The idea here is there's a difference between how the event repeats (Repetition) and when that repetition occurs (When/NotWhen).
// Between 9am and 6pm, run every 5 minutes, exactly on minute 0,5,10,etc., except on the last day of the month.
// Before 9am and after 6pm, run every 10 minutes, exactly on minute 0,10,20, etc, except on the last day of the month.
// On the last day of the month, run every 20 minutes, exactly on minute 0,20,40.
var config = ScheduleConfig.EveryMinute(5).OnTheMinute(0).When(Between(Hour(9),Hour(18))).WhenNot(DayOfMonth.Last).Named("DayTime")
.AddRepetition(Repetition.EveryMinute(10).OnTheMinute(0).When(Before(Hour(9)), After(Hour(18))).WhenNot(DayOfMonth.Last).Named("NightTime")
.AddRepetition(Repetition.EveryMinute(20).OnTheMinute(0).When(DayOfMonth.Last).Named("LastDayOfMonth");
var schedule = new Schedule(scheduleConfig); //This could also be IObservable....
@ctigeek
ctigeek / fileserver.js
Created Mar 18, 2015
Simple static file server
View fileserver.js
var http = require('http');
var url = require("url");
var path = require("path");
var fs = require('fs');
http.createServer(function(req, res) {
var uri = url.parse(req.url).pathname;
var filename = path.join(process.cwd(), uri);
if (fs.existsSync(filename)) {
var stats = fs.lstatSync(filename);
View EncryptString.cs
using System;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
namespace SandboxThing
{
class EncryptedString
{
private const int AesBlockSize = 128;
@ctigeek
ctigeek / StaticIP.ps1
Created Apr 7, 2015
Change server from DHCP to static...
View StaticIP.ps1
$adapter = Get-NetAdapter -Name "Ethernet"
$ipv4 = $adapter | Get-NetIPAddress -AddressFamily IPv4
## Remove IPv6 Address and disable IPv6 binding....
$ipv6 = $adapter | Get-NetIPAddress -AddressFamily IPv6 -ErrorAction SilentlyContinue
if ($ipv6) {
$ipv6 | Remove-NetIPAddress -Confirm:$false
}
$binding = (Get-NetAdapterBinding | Where-Object { $_.ComponentID -eq "ms_tcpip6" })
@ctigeek
ctigeek / RunPowershell.cs
Last active Sep 16, 2016
Run powershell file from c#
View RunPowershell.cs
using System.Management.Automation;
//....
public static async Task<string> RunPowershellScript(string scriptName, Dictionary<string,string> parameters)
{
using (var ps = PowerShell.Create())
{
var script = string.Format(". \"{0}\" {1}", scriptName, string.Join(" ", parameters.Select(p => "-" + p.Key + " '" + p.Value + "'")));
if (debug)
{
log.Debug("Running the following script:\r\n " + script);
@ctigeek
ctigeek / Clear-Memcache.ps1
Created May 14, 2015
Flush memcache from powershell...
View Clear-Memcache.ps1
function Clear-Memcache($server, $port = 11211)
{
$msg = [System.Text.Encoding]::ASCII.GetBytes("flush_all`r`nquit`r`n")
$c = New-Object System.Net.Sockets.TcpClient($server, $port)
$str = $c.GetStream()
$str.Write($msg, 0, $msg.Length)
$buf = New-Object System.Byte[] 4096
$count = $str.Read($buf, 0, 4096)
[System.Text.Encoding]::ASCII.GetString($buf, 0, $count)
$str.Close()
@ctigeek
ctigeek / Get-XApiSignature.ps1
Last active Aug 29, 2015
Creates an X-Api-Signature for making a REST API Call.
View Get-XApiSignature.ps1
function Get-XapiSignature($userAgent, $apiKey, $apiSecret) {
$dateTime = [DateTime]::UtcNow.ToString("yyyyMMddHHmmss");
$dataToSign = [String]::Format("{0}{1}{2}{3}", $apikey, $userAgent, $dateTime, $apiSecret);
$sha1 = [System.Security.Cryptography.SHA1]::Create();
$signedBytes = $sha1.ComputeHash([System.Text.Encoding]::UTF8.GetBytes($dataToSign));
$signature = [System.Convert]::ToBase64String($signedBytes);
$sha1.Dispose()
[String]::Format("{0}:{1}:{2}", $apikey, $dateTime, $signature);
}
You can’t perform that action at this time.