Skip to content

Instantly share code, notes, and snippets.

View aaronpowell's full-sized avatar
😶‍🌫️

Aaron Powell aaronpowell

😶‍🌫️
View GitHub Profile
@aaronpowell
aaronpowell / output.js
Created May 12, 2014 23:14
Sweet.js classes combined with type-safe properties via ES6 Proxies
function Person(name) {
this.name = name;
return new Proxy(this, {
set: function (target, property, val) {
var currentType = typeof target[property];
var newType = typeof val;
if (property in target && currentType !== newType) {
throw new Error('Property ' + property + ' must be a ' + currentType);
}
target[property] = val;
@aaronpowell
aaronpowell / AppTabby.cs
Last active August 29, 2015 14:01
A simple app which issues alt + tab (or ctrl + tab) periodically
using System;
using System.Threading;
using System.Windows.Forms;
namespace AltTabby
{
class Program
{
static void Main(string[] args)
{
@aaronpowell
aaronpowell / in.sjs
Created May 6, 2014 05:44
sweet.js in operator to handle arrays
operator (in) 10 left { $l, $r} => #{ Array.isArray($r) ? !~$r.indexOf($l) : !!$r[$l] }
var x = 7 in [1,2,3,4];
@aaronpowell
aaronpowell / gist:e7bcb3942848c3a9a67d
Created May 6, 2014 04:08
Handling merge conflicts during a rebase (or any time) when you just want someone's version
git ss | grep "^UU" | sed 's/UU//' | while read i; do git checkout --theirs $i && git add $i; done
# change `--theirs` to `--ours` to take your own version
@aaronpowell
aaronpowell / gist:14eadedddbd1b8f91c6c
Last active August 29, 2015 14:00
Sweet.js sublime text build system
{
"cmd": ["sjs", "$file", "-o", "$file_base_name.js"],
/*"file_regex": "", TODO: Work this out*/
"selector": "source.sjs"
}
//ref: http://docs.sublimetext.info/en/latest/file_processing/build_systems.html
public class AuthenticationController : ApiController {
public void SomethingThatIsPublic(Something something) { /* not important */ }
public HttpResponseMessage Post(LoginModel model) {
//do login
//return
}
}
@aaronpowell
aaronpowell / gist:d798507cbca08d86b41a
Created April 30, 2014 05:13
Find csproj files referencing an assembly
Get-ChildItem -Filter *.csproj -Recurse |
Select-Object -Property FullName,@{N="Xml"; E = {
Select-Xml -Path $_.FullName -XPath //b:Reference -Namespace @{b='http://schemas.microsoft.com/developer/msbuild/2003'} |
Select-Object -ExpandProperty Node |
Select-Object -Property Include, HintPath |
Where-Object { $_.HintPath -ne $null } |
Where-Object { $_.Include -eq "My.Assembly.Name" }
} } |
Where-Object { $_.Xml -ne $null } |
Out-GridView
@aaronpowell
aaronpowell / gist:10618558
Created April 14, 2014 05:29
Number of document type properties grouped by document type and ordered by the number of documents using them
CmsPropertyTypes
.GroupBy(pt => pt.ContentTypeId)
.Join(CmsDocumentTypes, x => x.Key, x => x.ContentTypeNodeId, (pts, dt) => new {
Property = pts,
DocumentType = dt
})
.Join(UmbracoNodes, x => x.DocumentType.ContentTypeNodeId, x => x.Id, (x, n) => new {
x,
n.Text
})
@aaronpowell
aaronpowell / gist:10609659
Created April 14, 2014 01:26
Umbraco document types grouped by the count of pages that use it (run via LINQPad)
(from dt in CmsDocumentTypes
join n in UmbracoNodes on dt.ContentTypeNodeId equals n.Id
select new {
n.Id,
n.Text,
Docs = CmsContents.Where(c => c.ContentType == n.Id).Where(c => !c.Node.Trashed).Count(),
IsNested = n.ParentID != -1
})
.Distinct()
.GroupBy(x => x.Docs)
@aaronpowell
aaronpowell / null-guard.sjs
Last active August 29, 2015 13:58
Trying out the C# vNext `?.` operator in Sweet.js
macro null_helper {
rule { ($processed ...) ($rest) } => {
$processed (.) ... . $rest
}
rule { ($processed ...) ($rest_head $rest ...) } => {
$processed (.) ... . $rest_head
&& null_helper ($processed ... $rest_head) ($rest ...)
}
}