Skip to content

Instantly share code, notes, and snippets.

View johnbabb's full-sized avatar

John Babb johnbabb

View GitHub Profile
@johnbabb
johnbabb / Ubuntu-VM-Create-Script.bicep
Last active December 3, 2021 16:10
Azure Ubuntu SFTP Configuration
/*
This script will:
- Depends on gist: https://gist.github.com/johnbabb/e385e10ea9dd06ddc3ea3160e7403dab
- This script provides the install script, create user script, mount user sftp drives script,
and sshd_confg file.
- create user script, mount user sftp drives script are copied to /usr/local/bin
- these scripts are used to add sftp users and mount their drives in /home/<user>/<downloads|uploads>
- sshd_confg is copied over to /etc/ssh/sshd_config
- Creates a virtual network
@johnbabb
johnbabb / page-page-size-to-skip-take.cs
Last active June 19, 2020 09:37
Code to covert page and page size into sql to skip rows and take rows.
void Main()
{
int? page = 3;
int? pageSize = 25;
if (page.HasValue && pageSize.HasValue)
{
var skip = (page.Value - 1) * pageSize.Value;
var take = pageSize.Value;
skip = skip < 0 ? 0 : skip;
To Export the Application Pools on IIS 7 :
%windir%\system32\inetsrv\appcmd list apppool /config /xml > c:\apppools.xml
To import the Application Pools:
%windir%\system32\inetsrv\appcmd add apppool /in < c:\apppools.xml
To Export all you’re website:
%windir%\system32\inetsrv\appcmd list site /config /xml > c:\sites.xml
@johnbabb
johnbabb / percona-xtrabackup.sh
Created December 1, 2016 17:08 — forked from jaygooby/percona-xtrabackup.sh
Call via crontab on whatever schedule suits you; keep n full mysql Percona xtrabackups of your mysql database, with binary logs applied. Also does a full mysqldump that can then have the binary logs applied to restore to a point-in-time backup via the binlogs. Copy all of this (backup, mysqldump, binlogs) to S3.
#!/bin/bash
#
# Carries out a full mysqldump, calls percona-xtrabackup and then
# copies the sql dump, the percona backup and your mysql bin logs
# to S3 using s3cmd http://s3tools.org/s3cmd
#
# TODO: extract out the S3 backup stuff to make it optional, and so
# other s3 programs can replace the s3cmd call.
# TODO: the if [ $? == 0 ] alert blocks should be a function
# TODO: make the if [ $? == 0 ] if [ $? != 0 ] more consistent - test
@johnbabb
johnbabb / http_performance_test_concurrent.cs
Last active May 20, 2022 23:54
C# http performance test
string baseUrl = "http://localhost";
void Main()
{
var urls = new string[] {
"/url/endpoint",
};
var concurrentRequests = new int[]{ 1, 5, 25, 50, 100, 500, 1000};
var numberOfTurns = 10;
RunTests(urls, concurrentRequests, numberOfTurns);
@johnbabb
johnbabb / Config.cs
Created December 1, 2014 10:56
Edit Config - Replace Key Value
private void SaveConfig(string key, string value)
{
var config = ConfigurationManager.OpenExeConfiguration(Path.Combine(AssemblyDirectory, Assembly.GetExecutingAssembly().ManifestModule.Name));
var applicationSectionGroup = config.GetSectionGroup("applicationSettings");
var applicationConfigSection = applicationSectionGroup.Sections["AsyncLogging.Properties.Settings"];
var clientSection = (ClientSettingsSection)applicationConfigSection;
var applicationSetting = clientSection.Settings.Get(key);
applicationSetting.Value.ValueXml.InnerText = value;
@johnbabb
johnbabb / CustomAssemblyResolver.cs
Created November 25, 2014 14:35
CustomAssemblyResolver
public class CustomAssemblyResolver : DefaultAssembliesResolver
{
private Assembly[] plugins = (
from file in Directory.GetFiles(
AssemblyDirectory, "*.dll",
SearchOption.AllDirectories)
let assembly = Assembly.LoadFile(file)
select assembly)
.ToArray();
@johnbabb
johnbabb / gist:2d69374455e386eae87a
Last active December 2, 2017 15:35
Chrome Dev Tools - Save Large Variable to File.
var JsonNetDecycle = (function () {
function JsonNetDecycle() { }
JsonNetDecycle.decycle = function decycle(obj) {
var catalog = [];
var newObj = JsonNetDecycle.getDecycledCopy(obj, catalog);
return newObj;
}
JsonNetDecycle.getDecycledCopy = function getDecycledCopy(obj, catalog) {
var i;
var name;