Skip to content

Instantly share code, notes, and snippets.

View yanmhlv's full-sized avatar

Ian Mikhailov yanmhlv

View GitHub Profile
<html>
<head>
<title></title>
<style>
/* CSS Document */
body {
font:12px arial;
color: #222;
text-align:center;
padding:35px; }
require 'active_record'
ActiveRecord::Base.establish_connection({
adapter: 'postgres', # or mysql2
host: 'localhost',
username: 'username',
password: 'password',
database: 'dbname',
})
# ActiveRecord::Base.establish_connection("postgres://username:password@host/dbname")
@yanmhlv
yanmhlv / mergesort.lhs
Created October 5, 2016 12:23 — forked from callistabee/mergesort.lhs
Haskell Implementation of Mergesort
- Haskell Mergesort
- Copyright (C) 2014 by Kendall Stewart
First we define a couple of helper functions that
will be useful in splitting the list in half:
> fsthalf :: [a] -> [a]
> fsthalf xs = take (length xs `div` 2) xs
@yanmhlv
yanmhlv / kormen_sorts.go
Last active November 14, 2016 16:46
implement algorithms on golang
package main
import "fmt"
func merge(left []int, right []int) []int {
var result []int
for len(left) != 0 && len(right) != 0 {
if left[0] < right[0] {
result = append(result, left[0])
left = left[1:]

What is sync.Pool in golang and How to use it

sync.Pool (1/2)

Many Go libraries include custom thread-safe free lists, like this:

var objPool = make(chan *Object, 10)

func obj() *Object {

select {

func yield(count int) chan int {
ch := make(chan int)
go func() {
for i := 0; i < count; i++ {
ch <- i
}
close(ch)
}()
return ch
}
@yanmhlv
yanmhlv / example.go
Last active October 24, 2022 18:40
logging body middleware for labstack/echo
package main
import (
"bytes"
"io/ioutil"
"github.com/labstack/echo"
"github.com/labstack/echo/engine/standard"
mw "github.com/labstack/echo/middleware"
)
package main
import (
"fmt"
"math/rand"
)
func main() {
doneCh := make(chan bool)
package main
import "fmt"
func main() {
mydict := map[string]int{
"1": 1,
"2": 2,
"3": 3,
}
package main
import (
"fmt"
"html/template"
"os"
"time"
)
func buildTemplate(name string, leftDelim string, rightDelim string) *template.Template {