Skip to content

Instantly share code, notes, and snippets.

@bolerap
bolerap / GoMgoSample-1.go
Created August 16, 2017 04:26 — forked from ardan-bkennedy/GoMgoSample-1.go
Sample Go and MGO example
type (
// BuoyCondition contains information for an individual station.
BuoyCondition struct {
WindSpeed float64 `bson:"wind_speed_milehour"`
WindDirection int `bson:"wind_direction_degnorth"`
WindGust float64 `bson:"gust_wind_speed_milehour"`
}
// BuoyLocation contains the buoy's location.
BuoyLocation struct {
// helper functions
private resizeImage(img, maxWidth, maxHeight, callback) {
return img.onload = () => {
// get image dimension
let width = img.width;
let height = img.height;
// set width and height to the max values
if (width > height) {
if (width > maxWidth) {
@bolerap
bolerap / authentication.ts
Created May 28, 2017 15:29 — forked from btroncone/authentication.ts
Angular 2 application role access decorator, wrapping built in CanAccess functionality. Prevents view transitions when user roles are not appropriate.
import { Injectable } from 'angular2/core';
import { Storage } from './storage';
import { CurrentUser } from '../interfaces/common';
@Injectable()
export class Authentication{
private _storageService : Storage;
private _userKey : string = "CURRENT_USER";
constructor(storageService : Storage){
@bolerap
bolerap / benchmark+go+nginx.md
Created April 13, 2017 14:19
Benchmarking Nginx with Go

Benchmarking Nginx with Go

There are a lot of ways to serve a Go HTTP application. The best choices depend on each use case. Currently nginx looks to be the standard web server for every new project even though there are other great web servers as well. However, how much is the overhead of serving a Go application behind an nginx server? Do we need some nginx features (vhosts, load balancing, cache, etc) or can you serve directly from Go? If you need nginx, what is the fastest connection mechanism? This are the kind of questions I'm intended to answer here. The purpose of this benchmark is not to tell that Go is faster or slower than nginx. That would be stupid.

So, these are the different settings we are going to compare:

  • Go HTTP standalone (as the control group)
  • Nginx proxy to Go HTTP
  • Nginx fastcgi to Go TCP FastCGI
  • Nginx fastcgi to Go Unix Socket FastCGI
import 'rxjs/add/operator/toPromise';
import {Injectable} from "@angular/core";
import {Http, Headers} from "@angular/http";
import {Poem} from './poem';
@Injectable()
export class PoemService {
// Properties
import "rxjs/add/operator/switchMap";
import {Component, OnInit} from "@angular/core";
import {ActivatedRoute} from "@angular/router";
@Component({
selector: 'app-card',
templateUrl: './card.component.html',
styleUrls: ['./card.component.css']
})
import { Component, OnInit } from '@angular/core';
import {Router} from '@angular/router';
import {Poem} from '../shared/poem';
import {PoemService} from '../shared/poem.service';
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css']
// Use middleware to serve static
router.Use(static.Serve("/", static.LocalFile("./frontend/dist", true)))
router.Use(static.Serve("/download", static.LocalFile("./output", true)))
// model
type Poem struct {
Title string `json:"title" binding:"required"`
Body []string `json:"body" binding:"required"`
Author string `json:"author" binding:"required"`
}
// Routes
api := router.Group("/api/v1")
{
api.POST("/card", func(c *gin.Context) {
// Gather data from post form
var poem Poem
c.BindJSON(&poem)
// Read image
im, err := gg.LoadImage("frames/f1.png")