Skip to content

Instantly share code, notes, and snippets.

View RhysC's full-sized avatar

Rhys Campbell RhysC

  • Perth; Australia
View GitHub Profile
@RhysC
RhysC / build_and_run.sh
Created July 29, 2018 05:40
Cron jobs in docker (using node base to show we can use that image)
docker build -f ./cron.docker --tag cronsample:local .
docker run -d cronsample:local --name cronsample_rhysc
# Wait a bit, a minute in fact
docker container cp cronsample_rhysc:/var/log/cron.log ./cron.log
cat ./cron.log
# Should see "Hello world" printed on a new line for every minute the container has been running
@RhysC
RhysC / generate_select.sql
Created July 6, 2017 08:20
Generate Select * (with column names defined ) in postgres
SELECT 'SELECT ' || string_agg(column_name, ', ') || ' FROM ' || table_name
FROM information_schema.columns
WHERE table_schema='my_schema'
GROUP BY table_name
@RhysC
RhysC / ActiveDirectorySnippets.txt
Created November 17, 2016 03:05
Active directory snippets
# opens a GUI to manage users under the given account - fine for adding/upodate one or two accounts
runas /user:myDomain\myusername "C:\Windows\System32\rundll32.exe dsquery, OpenQueryWindow"
##POWERSHELL – to load the users, done from a server so it has the AD PS modules
import-module activedirectory
# basic search using ps filters
Get-ADUser -filter {GivenName -like "rickie"}
@RhysC
RhysC / Calendar.html
Last active November 11, 2016 12:17
Schedule or calendar html page using Knockout bindings, vanilla js and bootstrap shell. View here https://gistpreview.github.io/?640b2b2a8fb038c6f1b62bbb3059628d
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Calendar Demo</title>
<!-- BEGIN CALENDAR CSS - ideally these would be in a separate file - eg /calendar-template.css -->
<style>
@RhysC
RhysC / CopyLibFilesAslinksToBgoToYour.Msbuild
Last active May 19, 2016 07:20
Getting pesky linked DLLs in to the bin dir without subfolders (MSBUILD in csproj files)
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- pervious msbuild project cruft clipped this is just a .csproj-->
<ItemGroup>
<Content Include="..\OtherProject\libs\**\*.dll">
<Link>libs\%(RecursiveDir)%(Filename)%(Extension)</Link>
<!-- copy after the build so i can have the dlls in a linked lib folder in the project bt in the root in bin -->
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
@RhysC
RhysC / IgnoreUntilFactAttribute.cs
Created March 18, 2016 11:10
Xunit skip/ignore until a given date
//using System;
//using Xunit;
public class IgnoreUntilFactAttribute : FactAttribute
{
public int Year { get; set; }
public int Month { get; set; }
public int Day { get; set; }
public override string Skip
{
@RhysC
RhysC / Dispatch.cs
Created January 5, 2016 08:29
Execute/Dispatch/Call all available methods on the object that can handle the parameter
void Main()
{
new MyObject().Dispatch(new Bar());
/* OUTPUT:
Easy more specific target
Hitting the Bar
Fooing it up
Easy target
*/
}
@RhysC
RhysC / BuildAllProjectsFromACleanState.ps1
Created October 30, 2015 03:33
Make sure that each project can be built from a clean state (ie no rouge dlls from previous builds)
$ErrorActionPreference = "Stop"
function cleanBin {
param ([string]$path)
write-host "Cleaning bin from: $path"
get-childitem $path -include bin -recurse | remove-item -force -confirm:$false -recurse
write-host "Cleaning obj from: $path"
get-childitem $path -include obj -recurse | remove-item -force -confirm:$false -recurse
@RhysC
RhysC / Guard.cs
Created September 3, 2015 08:00
Showing a proposed use of Guard with expression for static checks and correct name evaluation in exception messages
public static class Guard
{
public static void NotNull<T>(Expression<Func<T>> notNullableExpression) where T : class
{
var compliedExpression = notNullableExpression.Compile();
if (compliedExpression() == null)
{
var paramName = notNullableExpression.GetObjectNameGraph();
throw new ArgumentNullException(paramName);
@RhysC
RhysC / search-files.ps1
Last active August 29, 2015 14:28
Recursive file search
function search-files {
param ( [string]$fileFilter,
[string]$text)
$PathArray = @()
Get-ChildItem -Filter $fileFilter -Recurse |
Where-Object { $_.Attributes -ne "Directory"} |
ForEach-Object {
If (Get-Content $_.FullName | Select-String -Pattern $text) {
$PathArray += $_.FullName