Skip to content

Instantly share code, notes, and snippets.

View andmos's full-sized avatar

Andreas Mosti andmos

View GitHub Profile
@andmos
andmos / extract
Created October 10, 2014 07:59
The famous Extract-method for youre shell. Add to .bash_profile or add script to $path.
function extract {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar e $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xf $1 ;;

##Self-hosted HTTP service in C# with Nancy and TopShelf

I found myself in need of a standalone, self-hosted HTTP Service for a REST-backend at work the other day. I like my services to be flexible and easy to deploy with a low footprint. Here's the catch: At work we write in .Net and I truly hate IIS. I kinda like C#, but I don't want my webservices to be tightly locked onto the platform-specific overhead hell that is IIS. Thanks to OWIN, Nancy and TopShelf it easy to write a self-hosted HTTP service (Ruby or Node.js style!) in C# and have it run as a standalone application or as a Windows Service. Here is a super duper easy example using Nancys Self-Host and TopShelf.

###The Code First of all we need som packages from NuGet:

	Install-Package Nancy.Hosting.Self 

Install-Package Topshelf

@andmos
andmos / Build, test and deploy .NET apps with Vagrant and Docker.md
Created January 30, 2015 20:17
Build, test and deploy .NET apps with Vagrant and Docker

Build, test and deploy .NET apps with Vagrant and Docker

On a resent project at work we build a cross-platform chat-application with Xamarin and SignalR. The SignalR-hub was to find it's home on a Linux-server, given ASP.NETs new found love for other platforms than Windows and IIS. We had limited time and the back-end guys were developing the hub in Visual Studio. To help them make sure the code they wrote would be Mono-compatible (and easy to deploy for testing), I turned to my two favorite pieces of open source technology: Vagrant and Docker.

###The code First, I wrote a simple Dockerfile based on the latest Mono-baseimage that adds the code and runs xbuild in the build-process. When the container is run without parameters, it deploys the server.

FROM mono:latest

@andmos
andmos / Updating a SolrCloud schema in a live enviroment.md
Last active May 2, 2017 10:14
Updating a SolrCloud schema in a live enviroment

Updating a SolrCloud schema in a live enviroment

I can guarantee this will happen to you at some point: You find out that you need to add some more feilds in a Solr schema becouse you want to index some more data from you're documents. Does that mean taking down the live nodes, changing the schema and then start them up again? Thankfully, no. With the help of Zookeeper and the Solr schema REST API we can do this live without any pain.

###The API calls:

First of, let's update the new config to the zookeeper:

	./zkcli.sh -zkhost myZookeeper:2181 -cmd upconfig -confname myConfig -confdir /path/to/my/conf/
@andmos
andmos / nginxproxy.md
Created February 14, 2017 16:23 — forked from soheilhy/nginxproxy.md
How to proxy web apps using nginx?

Virtual Hosts on nginx (CSC309)

When hosting our web applications, we often have one public IP address (i.e., an IP address visible to the outside world) using which we want to host multiple web apps. For example, one may wants to host three different web apps respectively for example1.com, example2.com, and example1.com/images on the same machine using a single IP address.

How can we do that? Well, the good news is Internet browsers

@andmos
andmos / install_recent_terraform.sh
Created April 26, 2017 20:56
Install latest Terraform
#!/usr/bin/env bash
sudo apt-get install jq unzip
# Get URLs for most recent versions
terraform_url=$(curl --silent https://releases.hashicorp.com/index.json | jq '{terraform}' | egrep "linux.*64" | sort -rh | head -1 | awk -F[\"] '{print $4}')
# Create a move into directory.
cd
mkdir terraform && cd $_
#! "netcoreapp2.0"
#r "nuget:NetStandard.Library,2.0.0"
#r "nuget: Octopus.Client, 4.27.1"
#r "nuget: Octopus.Client.Extensibility, 3.0.1"
#r "nuget: Newtonsoft.Json, 10.0.3"
using System.Threading.Tasks;
using Octopus.Client;
using Octopus.Client.Model;
using Octopus.Client.Model.Endpoints;
using Newtonsoft.Json;
#!/bin/bash
hostname="{{ ansible_host }}"
serverUrl="{{ octopusHost }}"
apiKey="{{ octopusAPIKey }}"
localIp="{{ ansible_default_ipv4.address }}"
environment="{{ octopusEnvironment }}"
accountId="{{ octopusSSHAccount }}"
fingerprint=$(ssh-keygen -E md5 -lf /etc/ssh/ssh_host_rsa_key.pub | cut -d' ' -f2 | cut -d: -f2- | awk ' { print $1}') #MD5
machineName="{{ ansible_hostname }}"
function jsonToEnvironment {
if [ -f $1 ]; then
for s in $(jq -r "to_entries|map(\"\(.key)=\(.value|tostring)\")|.[]" $1)
do
export $s
done
fi
}
### Usage:
$ mkcert -install
Created a new local CA at "/Users/andreasmosti/Library/Application Support/mkcert" 💥
The local CA is now installed in the system trust store! ⚡️
The local CA is now installed in the Firefox trust store (requires browser restart)! 🦊
$ mkcert localhost 127.0.0.1
Using the local CA at "/Users/andreasmosti/Library/Application Support/mkcert" ✨
Created a new certificate valid for the following names 📜
- "localhost"