Skip to content

Instantly share code, notes, and snippets.

View damieng's full-sized avatar
🏠
Working from home

Damien Guard damieng

🏠
Working from home
View GitHub Profile
### Keybase proof
I hereby claim:
* I am damieng on github.
* I am damieng (https://keybase.io/damieng) on keybase.
* I have a public key ASA8deTgucv6MkZXIKGoqPTL9-Tw1C1HZPVR_iOyfEsQfgo
To claim this, I am signing this object:
@damieng
damieng / PageViewCount.csx
Created May 16, 2017 03:47
Page View Count function in C# for Azure Functions
#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
damieng / AwfulCSharpCode.cs
Created May 16, 2017 18:46
A sample C# file that messes with syntax highlighters
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
#endif
/* Mult-line
comment */
public abstract class Outside { }
@damieng
damieng / LINQOrExpressionCombiner.cs
Created May 17, 2017 05:42
OR together LINQ expressions for Where clauses etc
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
damieng / npm-win-proxy.ps1
Last active September 21, 2017 10:04
Apply Windows proxy settings to npm automatically
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 }
}
}
}
@damieng
damieng / daily-backup.sh
Last active October 6, 2017 15:37
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
damieng / Mehkee96.json
Last active December 17, 2017 20:37
Mehkee 96 bootmapper with split number/arrow area
[
[
[
{
"index": 103,
"label": "LCtrl"
},
{
"index": 104,
"label": "LShift"
@damieng
damieng / nsfw-watcher.js
Created October 28, 2016 18:36
Watch the filesystem using NSFW from the command line
#!/usr/bin/env node
const nsfw = require('nsfw')
const process = require('process')
const path = require('path')
if (process.argv.length == 0) {
console.log(`Usage: ${process.argv[0]} [path]`)
process.exit(0)
}
@damieng
damieng / algolia-search.html
Last active May 30, 2018 04:54
Algolia search from damieng.com
<script src="https://cdn.jsdelivr.net/npm/algoliasearch@3/dist/algoliasearchLite.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/algoliasearch-helper@2.26.0/dist/algoliasearch.helper.min.js"></script>
<script>
let searchForm = document.getElementById('search-form')
let hits = document.getElementById('hits')
let algolia = algoliasearch('{your-site-id}', '{your-search-token}')
let helper = algoliasearchHelper(algolia, '{your-index-name}', { hitsPerPage: 10, maxValuesPerFacet: 1, getRankingInfo: false })
helper.on("result", searchCallback)
function runSearch() {
@damieng
damieng / config.yml
Last active June 3, 2018 01:50
CircleCI config for damieng.com
version: 2
jobs:
build:
docker:
- image: circleci/ruby:2.3
working_directory: ~/jekyll
environment:
- JEKYLL_ENV=production
- NOKOGIRI_USE_SYSTEM_LIBRARIES=true
- JOB_RESULTS_PATH=run-results