Skip to content

Instantly share code, notes, and snippets.

View satyrius's full-sized avatar

Anton Egorov satyrius

  • Tallinn, Estonia
View GitHub Profile
@satyrius
satyrius / exercise-56.go
Created October 23, 2013 06:33
A Tour of Go. Exercise: Errors. Copy your Sqrt function from the earlier exercises and modify it to return an error value. Sqrt should return a non-nil error value when given a negative number, as it doesn't support complex numbers. Create a new type type ErrNegativeSqrt float64 and make it an error by giving it a func (e ErrNegativeSqrt) Error(…
package main
import (
"fmt"
)
type ErrNegativeSqrt float64
func (e ErrNegativeSqrt) Error() string {
return fmt.Sprintf("cannot Sqrt negative number: %v", float64(e))
@satyrius
satyrius / intercom_export.js
Last active September 24, 2023 13:45
Export Intercom conversations/chats entire history
require("dotenv").config();
const H = require("highland");
const axios = require("axios");
const fs = require("fs").promises;
const exportDirectory = "./export";
const apiUrl = "https://api.intercom.io";
// config axios for the authorized API request
const apiClient = axios.create({
@satyrius
satyrius / exercise-60.go
Created October 24, 2013 20:11
A Tour of Go. Exercise: Images. Remember the picture generator you wrote earlier? Let's write another one, but this time it will return an implementation of image.Image instead of a slice of data. Define your own Image type, implement the necessary methods, and call pic.ShowImage. Bounds should return a image.Rectangle, like image.Rect(0, 0, w, …
package main
import (
"code.google.com/p/go-tour/pic"
"image"
"image/color"
)
type Image struct{
Width, Height int
@satyrius
satyrius / exercise-36.go
Created October 23, 2013 06:18
A Tour of Go. Exercise: Slices. Implement Pic. It should return a slice of length dy, each element of which is a slice of dx 8-bit unsigned integers. When you run the program, it will display your picture, interpreting the integers as grayscale (well, bluescale) values. The choice of image is up to you. Interesting functions include x^y, (x+y)/2…
package main
import "code.google.com/p/go-tour/pic"
func Pic(dx, dy int) [][]uint8 {
res := make([][]uint8, dy)
for y := range res {
res[y] = make([]uint8, dx)
for x := range res[y] {
res[y][x] = uint8((x + y) /2)

Keybase proof

I hereby claim:

  • I am satyrius on github.
  • I am satyrius (https://keybase.io/satyrius) on keybase.
  • I have a public key ASCqBYyDDIvy2Yj556khOSWkpKP3Gr-T1r71iu7RW3_9xQo

To claim this, I am signing this object:

@satyrius
satyrius / exercise-41.go
Created October 23, 2013 06:23
A Tour of Go. Exercise: Maps. Implement WordCount. It should return a map of the counts of each “word” in the string s. The wc.Test function runs a test suite against the provided function and prints success or failure. You might find strings.Fields helpful.
package main
import (
"code.google.com/p/go-tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
res := make(map[string]int)
for _, w := range strings.Fields(s) {
@satyrius
satyrius / exercise-44.go
Created October 23, 2013 06:25
A Tour of Go. Exercise: Fibonacci closure. Let's have some fun with functions. Implement a fibonacci function that returns a function (a closure) that returns successive fibonacci numbers.
package main
import "fmt"
// fibonacci is a function that returns
// a function that returns an int.
func fibonacci() func() int {
var a, b int
return func() int {
a, b = b, a + b
0x65BAC2D81034ac52523fB88EfB62C2a888A756c4
@satyrius
satyrius / Dockerfile
Created March 28, 2016 16:41
Python 2.7 minimal Docker image (with psycopg2, nginx and supervisor)
FROM debian:jessie
ENV PYENV_ROOT=/opt/pyenv PATH=/opt/pyenv/shims:/opt/pyenv/bin:$PATH LANG=en_US.UTF-8
RUN set -x \
&& echo "LANG=$LANG" > /etc/default/locale \
&& echo "$LANG UTF-8" > /etc/locale.gen \
&& export DEBIAN_FRONTEND=noninteractive \
&& apt-get update -qq \
&& apt-get install -y locales \
&& apt-get install -y \
libpq5 \
@satyrius
satyrius / .tmux.conf
Last active June 20, 2016 09:39
My Tmux configuration
set-window-option -g mode-keys vi
set-option -g status-keys vi
# Start windows and panes at 1, not 0
set -g base-index 1
setw -g pane-base-index 1
# title
set -g set-titles on
set -g set-titles-string "#T"