Skip to content

Instantly share code, notes, and snippets.

View juneym's full-sized avatar

Raul Martinez Jr juneym

  • Carparts.com Inc
  • Torrance, CA
  • 07:47 (UTC -07:00)
View GitHub Profile
@rushilgupta
rushilgupta / GoConcurrency.md
Last active July 11, 2024 12:52
Concurrency in golang and a mini Load-balancer

INTRO

Concurrency is a domain I have wanted to explore for a long time because the locks and the race conditions have always intimidated me. I recall somebody suggesting concurrency patterns in golang because they said "you share the data and not the variables".

Amused by that, I searched for "concurrency in golang" and bumped into this awesome slide by Rob Pike: https://talks.golang.org/2012/waza.slide#1 which does a great job of explaining channels, concurrency patterns and a mini-architecture of load-balancer (also explains the above one-liner).

Let's dig in:

Goroutines

Go vs. Scala (Akka) Concurrency

A comparison from 2 weeks using Go.

Actors vs. Functions

Akka's central principle is that there you have an ActorSystem which runs Actors. An Actor is defined as a class and it has a method to receive messages.

@juneym
juneym / http_serv.go
Last active October 22, 2015 05:19 — forked from gotnix/http_serv.go
Share you directory via http server by golang.
package main
import (
"flag"
"fmt"
"log"
"net/http"
"strconv"
)
@juneym
juneym / gist:88c8286e68d0088eb444
Last active September 2, 2015 10:22 — forked from justincase/gist:5492212
Enable mgo debug log
mgo.SetDebug(true)
var aLogger *log.Logger
aLogger = log.New(os.Stderr, "", log.LstdFlags)
mgo.SetLogger(aLogger)
Example: https://denpa.moe/~syrup/himawari8.png
@pwm
pwm / openresty
Last active March 3, 2023 22:39
openresty init script
#!/bin/bash
#
# chkconfig: 2345 55 25
# description: Openresty
# processname: nginx
# config: /usr/local/openresty/nginx/conf/nginx.conf
# pidfile: /usr/local/openresty/nginx/logs/nginx.pid
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $local_fs $remote_fs $network $named $syslog $time
@gdamjan
gdamjan / client.py
Last active November 10, 2019 20:22
Python 3.5 async/await with aiohttp, parallel or sequential
import aiohttp
import asyncio
async def get_body(url):
response = await aiohttp.request('GET', url)
raw_html = await response.read()
return raw_html
async def main():
# run them sequentially (but the loop can do other stuff in the meanwhile)
@cristianp6
cristianp6 / Fetch email in a file.md
Last active April 29, 2020 10:26
Write retrieved emails on a log file (Ubuntu/Debian)

Write retrieved emails in a file

As root, install fetchmail

$ apt-get install fetchmail

Check if fetchmail has SSL support: if you see something like "libssl.so.0" then yours has it

$ ldd /usr/bin/fetchmail
@momer
momer / grpc_with_reconnect.go
Last active February 7, 2024 00:44
A pattern I created to maintain connections to an RPC server in Go. Since net/rpc does not provide any methods for automatically reconnecting to an RPC server, I needed a work-around. Additionally, rpc.Client does not export any state variables (rpc.Client.shutdown and rpc.Client.closing) nor does it export the Client's Mutex. So, we wrap the rp…
package main
import (
"myapp/webserver/app/common"
"github.com/golang/glog"
"github.com/gorilla/mux"
"encoding/json"
"strconv"
"flag"
"fmt"
"require": {
[...]
"besimple/soap": "0.2.*"
}