Skip to content

Instantly share code, notes, and snippets.

🤡
-

Steve Wagner lanwin

🤡
-
View GitHub Profile
@lanwin
lanwin / gist:852890
Created Mar 3, 2011
Simply object extension with provides an maybe monad.
View gist:852890
public static class ObjectExtensions
{
public static IEnumerable<T> ToMaybe<T>(this T obj)
{
return Equals(obj,null) ? Enumerable.Empty<T>() : new[] {obj};
}
}
@lanwin
lanwin / add_users_to_projects.sh
Created Feb 2, 2012
Script to Automatically add all GitLab users to all projects
View add_users_to_projects.sh
#!/bin/sh
baseurl=http://mygitlaburl
usermail=adminuser@mymailserver
userpass=adminpassword
repo_access=2 #0=denied 1=read 2=read&write
project_access=2 #0=deined 1=read 2=report 3=admin
# login
curl -s -I -c cookies.txt -d "utf8=✓&user[email]=$usermail&user[password]=$userpass&commit=Sign+in" $baseurl/users/sign_in
@lanwin
lanwin / rabbit_based_message_bus.cs
Created Feb 14, 2012
This is an example how to use our Rabbit Service Bus.
View rabbit_based_message_bus.cs
/* Initialize bus. In this case via Autofac */
builder.RegisterModule(new RabbitModule
{
HostName = "localhost",
UserName = "user",
Password = string.Empty,
Exchanges = {
new Exchange("exchange1"){Durable=true;},
new Exchange("exchange2"){Durable=true;}
}
@lanwin
lanwin / objectdiff.cs
Created May 31, 2012
ObjectDiff to compare objects with checking if properties, fields, and arrays are the same
View objectdiff.cs
static class ObjectDiff
{
static IEnumerable<Member> GetMembers(object obj)
{
foreach(var propertyInfo in obj.GetType().GetProperties().Where(p => p.CanRead))
{
var info = propertyInfo;
yield return new Member
{
Name = info.Name,
@lanwin
lanwin / gist:2948383
Created Jun 18, 2012
ASP.Net WebApi: Answer text/html requests with application/json
View gist:2948383
public class JsonWithHtmlMediaTypeFormatter : JsonMediaTypeFormatter
{
public JsonWithHtmlMediaTypeFormatter()
{
SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));
}
public override void SetDefaultContentHeaders(Type type, HttpContentHeaders headers, string mediaType)
{
base.SetDefaultContentHeaders(type, headers, mediaType);
@lanwin
lanwin / kudu_with_subdomain.patch
Created Aug 9, 2012
This patch extens Kudu to use the given app subdomains instead random ports with localhost for site bindings.
View kudu_with_subdomain.patch
Kudu.SiteManagement/SiteManager.cs | 31 ++++++++++++++++++-------------
1 file changed, 18 insertions(+), 13 deletions(-)
diff --git a/Kudu.SiteManagement/SiteManager.cs b/Kudu.SiteManagement/SiteManager.cs
index 43a6012..87b466d 100644
--- a/Kudu.SiteManagement/SiteManager.cs
+++ b/Kudu.SiteManagement/SiteManager.cs
@@ -6,12 +6,15 @@
using System.Net.NetworkInformation;
using System.Threading;
@lanwin
lanwin / oom.cs
Created Oct 28, 2012
Raven Client 1.2.2127 OOM on inserting large amounts of data
View oom.cs
public class OutOfMemoryTest
{
public void Run()
{
// client version 1.2.2127
using(var store = new DocumentStore
{
Url = "http://TestRaven:8080",
DefaultDatabase = "Test",
})
@lanwin
lanwin / gist:4124736
Created Nov 21, 2012
constructor function - but R# Name dose not match rule 'Local Variable'. Suggested name is app.
View gist:4124736
(function() {
"use strict";
// constructor function - but R# Name dose not match rule 'Local Variable'. Suggested name is app.
var App = function() {
// ...
};
ko.applyBindings(new App());
})();
@lanwin
lanwin / gist:4138801
Created Nov 24, 2012
Immutable type checking for Simon
View gist:4138801
class Mutable {
}
[Immutable]
public class ImmutableB
{
public readonly A = new ImmutableA();
}
@lanwin
lanwin / object_stream_merging.js
Created Aug 6, 2013
Nodejs merging object streams. Here is my current working example. But I dont like it. A MergeStream with one 'end' event would be much better. A sidenode: FeedParser implements node TransformStream and set its objectmode to true so that in the end we stream objects instead buffers. This could be better solved with RxJS. But what I currently don…
View object_stream_merging.js
var data = [];
exampleFeeds.forEach(function(feedFile) {
fs.createReadStream(feedFile)
.pipe(new FeedParser())
.on('meta', function(meta) {
data.push(meta);
if(data.length===exampleFeeds.length){
console.log('done '+data.length);
// do something
}
You can’t perform that action at this time.