How to import and indicate empty request or reply messages:
import "google/protobuf/empty.proto";
service SomeService {
rpc SomeOperation (google.protobuf.Empty) returns (google.protobuf.Empty) {}
}
| package main | |
| import ( | |
| "bytes" | |
| "crypto/hmac" | |
| "crypto/sha256" | |
| "crypto/tls" | |
| "encoding/base64" | |
| "fmt" | |
| "io/ioutil" |
| package main | |
| import ( | |
| "context" | |
| "flag" | |
| "fmt" | |
| "log" | |
| "net/http" | |
| "os" | |
| "os/signal" |
How to import and indicate empty request or reply messages:
import "google/protobuf/empty.proto";
service SomeService {
rpc SomeOperation (google.protobuf.Empty) returns (google.protobuf.Empty) {}
}
| // ⚠ IMPORTANT: this is old and doesn't work for many different edge cases but I'll keep it as-is for any of you want it | |
| // ⚠ IMPORTANT: you can find more robust versions in the comments or use a library implementation such as lodash's `merge` | |
| // Merge a `source` object to a `target` recursively | |
| const merge = (target, source) => { | |
| // Iterate through `source` properties and if an `Object` set property to merge of `target` and `source` properties | |
| for (const key of Object.keys(source)) { | |
| if (source[key] instanceof Object) Object.assign(source[key], merge(target[key], source[key])) | |
| } |
| // haversin(θ) function | |
| func hsin(theta float64) float64 { | |
| return math.Pow(math.Sin(theta/2), 2) | |
| } | |
| // Distance function returns the distance (in meters) between two points of | |
| // a given longitude and latitude relatively accurately (using a spherical | |
| // approximation of the Earth) through the Haversin Distance Formula for | |
| // great arc distance on a sphere with accuracy for small distances | |
| // |
When working with API clients there are several distinct areas of concern. Each of these happen in sequence and are used with the goal of receiving a Domain Model at the end.
| class Integer | |
| def ! | |
| if self > 0 | |
| (1..self).reduce :* | |
| elsif self.zero? | |
| 1 | |
| else | |
| raise ArgumentError, "No factorial for #{self}" | |
| end | |
| end |
| #!/bin/bash | |
| # Source: https://gist.github.com/ryin/3106801 | |
| # Script for installing tmux on systems where you don't have root access. | |
| # tmux will be installed in $HOME/local/bin. | |
| # It's assumed that wget and a C/C++ compiler are installed. | |
| # exit on error | |
| set -e | |
| TMUX_VERSION=1.9 |
| test: | |
| ./node_modules/.bin/browserify test/suite.js > test/suite.bundle.js | |
| ./node_modules/.bin/mocha-phantomjs test/runner-cli.html | |
| rm test/suite.bundle.js | |
| .PHONY: test |
| require "active_record" | |
| namespace :db do | |
| db_config = YAML::load(File.open('config/database.yml')) | |
| db_config_admin = db_config.merge({'database' => 'postgres', 'schema_search_path' => 'public'}) | |
| desc "Create the database" | |
| task :create do | |
| ActiveRecord::Base.establish_connection(db_config_admin) |