Skip to content

Instantly share code, notes, and snippets.

Damien Guard damieng

Block or report user

Report or block damieng

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
damieng / LINQOrExpressionCombiner.cs
Created May 17, 2017
OR together LINQ expressions for Where clauses etc
View LINQOrExpressionCombiner.cs
class Or
public static Expression<Func<T, bool>> Combine<T>(Expression<Func<T, bool>> left, Expression<Func<T, bool>> right)
var parameter = Expression.Parameter(typeof(T), "p");
var combined = new ParameterReplacer(parameter).Visit(Expression.OrElse(left.Body, right.Body));
return Expression.Lambda<Func<T, bool>>(combined, parameter);
class ParameterReplacer : ExpressionVisitor
damieng / AwfulCSharpCode.cs
Created May 16, 2017
A sample C# file that messes with syntax highlighters
View AwfulCSharpCode.cs
extern alias b;
using System;
class A { public dictionary<int, String> func(int a) { } }
struct hi { byte q; int a = /* */ 1; char c = 'c'; }
void A() { }
#if ABC // Testing
/* Mult-line
comment */
public abstract class Outside { }
damieng / PageViewCount.csx
Created May 16, 2017
Page View Count function in C# for Azure Functions
View PageViewCount.csx
#r "Microsoft.WindowsAzure.Storage"
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Table;
using System.Net;
public static async Task<object> Run(HttpRequestMessage req, TraceWriter log)
var page = req.GetQueryNameValuePairs().FirstOrDefault(kv => string.Compare(kv.Key, "page", true) == 0);
if (String.IsNullOrEmpty(page.Value)) return req.CreateResponse(HttpStatusCode.BadRequest);
damieng /
Last active Oct 6, 2017
DamienG daily backup script to S3
cd ~/backup
rm *
_today=$(date +"%Y%m%d")
tar -c --xz -f $_today-nginx-config-dedicated.tar.xz -C /etc nginx
tar -c --xz -f $_today-damieng-files.tar.xz -C /var/www damieng
mysqldump wpDamieng | xz -9 -c - > $_today-damieng-wordpress-db.xz
cp ../*.sh .
damieng / download-with-fetch.flow.js
Last active May 20, 2019
Download a file with progress indication using just window.fetch + node (FlowType version)
View download-with-fetch.flow.js
// @flow
import fs from 'fs';
// Public: Download a file and store it on a file system using streaming with appropriate progress callback.
// * `sourceUrl` Url to download from.
// * `targetFile` File path to save to.
// * `progressCallback` Callback function that will be given a {ByteProgressCallback} object containing
// both bytesDone and percent.
damieng / download-with-fetch.flow.js
Created Mar 13, 2017
Download a file using just window.fetch (flowtype version)
View download-with-fetch.flow.js
// @flow
import fs from 'fs';
export default async function download(sourceUrl: string, targetFile: string, progressCallback: ?ByteProgressCallback, length: ?number): Promise<void> {
const request = new Request(sourceUrl, {
headers: new Headers({'Content-Type': 'application/octet-stream'})
const response = await fetch(request);
View gist:d1a3bf30f36e14a954b94448fe51f44a
### Keybase proof
I hereby claim:
* I am damieng on github.
* I am damieng ( on keybase.
* I have a public key ASA8deTgucv6MkZXIKGoqPTL9-Tw1C1HZPVR_iOyfEsQfgo
To claim this, I am signing this object:
damieng / getproxieswindows.js
Created Jan 11, 2017
Get Proxy servers on Windows
View getproxieswindows.js
exports.getProxyServers = (callback) => {
try {
new Registry('\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings')
.get('ProxySever', (err, val) => {
callback(err, err ? undefined || Object.assign({}, ...val.split(';').map(v => v.split('=')).map(v => ({[v[0]]: v[1]}))))
} catch (err) {
damieng / npm-win-proxy.ps1
Last active Sep 21, 2017
Apply Windows proxy settings to npm automatically
View npm-win-proxy.ps1
try {
$proxyKey = (Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" -Name ProxyServer -ErrorAction Stop).ProxyServer
foreach($proxy in $proxyKey.Split(';')) {
$parts = $proxy.Split('=')
switch ($parts[0]) {
'http' { iex "npm config set proxy http://$parts[1]"; break }
'https' { iex "npm config set https-proxy http://$parts[1]"; break }
View Compaq-G80-1800.kbd.json
"backcolor": "#000000",
"name": "Compaq G80-1800",
"author": "Damien Guard",
"background": {
"name": "ABS WFK",
"style": "background-image: url('/bg/plastic/abs-wfk.jpg');"
"switchMount": "cherry",
You can’t perform that action at this time.