Skip to content

Instantly share code, notes, and snippets.

View mock-slack-post-message_test.go
package service
import (
"testing"
"github.com/proclaim/mock-slack-api/server"
"github.com/slack-go/slack"
"github.com/stretchr/testify/assert"
)
View mock-slack-post-message.go
package service
import (
"github.com/slack-go/slack"
)
func (s *SlackService) PostMessage(channel string, attachment slack.Attachment) (string, string, error) {
// ... your implementation here
return s.api.PostMessage(
channel,
View mock-slack-server.go
package server
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
"net/url"
"strings"
@proclaim
proclaim / typeorm-delete-multiple.js
Last active Apr 28, 2021
typeorm delete multiple records
View typeorm-delete-multiple.js
// assume entityIds is an array
connection.createQueryBuilder()
.delete()
.from(entity)
.where('entity.id IN (:...ids)', { ids: entityIds })
.execute()
@proclaim
proclaim / pull-files.sh
Created Feb 21, 2019
Pull Files Out From Subdirectories
View pull-files.sh
num=1
find . -mindepth 2 -type f -print | while read x; do
y=$(basename "$x")
if [ -f "$y" ]; then
mv "$y" "$num"."$y"
num=$(( $num + 1 ))
fi
mv "$x" "$y"
done
@proclaim
proclaim / deploy.yml
Created Nov 14, 2018
ansible for deploying to aws lambda
View deploy.yml
---
- hosts: localhost
connection: local
gather_facts: false
tasks:
- name: Create Lambda function
lambda:
name: hello-Taiwan
region: us-east-1
zip_file: "main.zip"
@proclaim
proclaim / main.go
Created Nov 14, 2018
very very simple go program for lambda
View main.go
package main
import (
"fmt"
"github.com/aws/aws-lambda-go/lambda"
)
func main() {
lambda.Start(handler)
}
@proclaim
proclaim / sftp.go
Created Sep 9, 2018
helper for creating a sftpclient
View sftp.go
package sftpclient
import (
"fmt"
"github.com/pkg/sftp"
"golang.org/x/crypto/ssh"
"net"
"time"
)
View pre-handling-request-in-go-3.go
func handle(f func(*gin.Context) (interface{}, int, error)) func(*gin.Context) {
return func(gc *gin.Context) {
// very complex code
}
View pre-handling-request-in-go-2.go
package main
import (
"encoding/json"
"github.com/gorilla/mux"
"log"
"net/http"
)
type Response struct {