Skip to content

Instantly share code, notes, and snippets.

View tebeka's full-sized avatar
💭
alive

Miki Tebeka tebeka

💭
alive
View GitHub Profile
filePerm := Read | Write // set permission (| is bitwise OR)
if filePerm&Write != 0 { // check permission (& is bitwise AND)
fmt.Println("can write")
}
func (p FilePerm) String() string {
switch p {
case Read:
return "read"
case Write:
return "write"
case Execute:
return "execute"
}
type FilePerm uint8
const (
Read FilePerm = 1 << iota
Write
Execute
)
func main() {
fmt.Println(Execute) // execute
In [5]: c._Client__address
Out[5]: 'https://httpbin.org:443'
@tebeka
tebeka / 4.py
Created January 31, 2022 07:42
class SocketClient(Client):
def __init__(self, host, port):
self.__address = (host, port)
In [4]: vars(c)
Out[4]: {'_Client__address': 'https://httpbin.org:443'}
$ ipython
In [1]: %run client.py
In [2]: c = Client('httpbin.org', 443)
In [3]: c.__address
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Input In [3], in <module>
----> 1 c.__address
AttributeError: 'Client' object has no attribute '__address'
@tebeka
tebeka / 1.py
Created January 31, 2022 07:42
from urllib.request import URLError, urlopen
from http import HTTPStatus
class Client:
def __init__(self, host, port):
self.__address = f'https://{host}:{port}'
def health(self):
url = f'{self.__address}/health'
@tebeka
tebeka / 7.go
Created January 11, 2022 14:29
type iface struct {
tab *itab
data unsafe.Pointer
}
@tebeka
tebeka / 6.go
Created January 11, 2022 14:29
package main
import (
"fmt"
)
type Error int
// Error implements the built-in error interface
func (e *Error) Error() string {