Skip to content

Instantly share code, notes, and snippets.

View grevych's full-sized avatar
🤓

Gerardo Reyes grevych

🤓
View GitHub Profile
@ranggasama
ranggasama / post.go
Created January 20, 2021 11:08
Sample Golang application to send HMAC authentication
package main
import (
"bytes"
"crypto/hmac"
"crypto/sha256"
"crypto/tls"
"encoding/base64"
"fmt"
"io/ioutil"
@enricofoltran
enricofoltran / main.go
Last active April 1, 2024 00:17
A simple golang web server with basic logging, tracing, health check, graceful shutdown and zero dependencies
package main
import (
"context"
"flag"
"fmt"
"log"
"net/http"
"os"
"os/signal"
@subfuzion
subfuzion / empty-example.md
Last active February 26, 2024 20:39
Protocol Buffer example of importing and using empty

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) {}
}
@ahtcx
ahtcx / deep-merge.js
Last active May 10, 2024 14:29
Deep-Merge JavaScript objects with ES6
// ⚠ 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]))
}
@cdipaolo
cdipaolo / HaversinFormula.go
Created April 15, 2015 01:31
Golang functions to calculate the distance in meters between long,lat points on Earth.
// 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
//
@nateklaiber
nateklaiber / design.md
Last active April 24, 2024 18:11
API Client Design
@jleeothon
jleeothon / combs.rb
Last active August 29, 2015 14:08
Ruby combinatorics
class Integer
def !
if self > 0
(1..self).reduce :*
elsif self.zero?
1
else
raise ArgumentError, "No factorial for #{self}"
end
end
@sharjeelsayed
sharjeelsayed / tmux_local_install.sh
Last active February 22, 2021 03:49 — forked from ryin/tmux_local_install.sh
bash script for installing tmux without root access.Updated to include latest Tmux version and some other minor changes
#!/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
@andyperlitch
andyperlitch / Makefile
Last active October 13, 2018 21:57
An example javascript test suite setup using Mocha, Chai, Sinon, Browserify, and PhantomJS.
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
@schickling
schickling / Rakefile
Last active January 31, 2024 23:00
Activerecord without Rails
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)