Skip to content

Instantly share code, notes, and snippets.

Avatar

Ricardo Cosme ricjcosme

View GitHub Profile
View Net backup and restore of Raspberry PI image with netcat and dd.md

Raspberry PI (cli):

  $ DST_HOST=nc_machine_addr
  $ SDSIZE=`sudo blockdev --getsize64 /dev/mmcblk0`;sudo pv -tpreb /dev/mmcblk0 -s $SDSIZE | nc $DST_HOST 19000

Netcat machine | "nc_machine_addr" (srv):

@ricjcosme
ricjcosme / Named Entity extraction in python.md
Last active September 10, 2016 00:20
Named Entity extraction in python
View Named Entity extraction in python.md

pip freeze:

  • nltk==3.2.1
  • numpy==1.11.1
# -*- coding: utf-8 -*-
'''
@author: Ricardo Cosme
'''
@ricjcosme
ricjcosme / linux swap usage by process (desc)
Last active September 9, 2016 15:58
linux swap usage by process (desc)
View linux swap usage by process (desc)
for file in /proc/*/status ; do awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file; done | sort -k 2 -n -r | less
View kafka_python.py
import confluent_kafka
#import json
#import msgpack
c = confluent_kafka.Consumer({'bootstrap.servers': 'kafka', 'group.id': 'PyCharm_consumer',
'default.topic.config': {'auto.offset.reset': 'latest'}})
c.subscribe(['ping'])
running = True
i = 0
View keybase.md

Keybase proof

I hereby claim:

  • I am ricjcosme on github.
  • I am ricjcosme (https://keybase.io/ricjcosme) on keybase.
  • I have a public key ASCznfQdhnrFDdZoDrWYG5hNSDZs7jQI_qqZg9F2mRnerQo

To claim this, I am signing this object:

@ricjcosme
ricjcosme / reflect.py
Created September 1, 2017 18:00
Reflection webserver - good for dev / debugging purposes
View reflect.py
#!/usr/bin/env python
# Reflects the requests from HTTP methods GET, POST, PUT, and DELETE
# Written by Nathan Hamiel (2010)
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
from optparse import OptionParser
class RequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
@ricjcosme
ricjcosme / dump-restore
Created September 13, 2017 17:33
DUMP / RESTORE PostgreSQL Kubernetes
View dump-restore
DUMP
// pod-name name of the postgres pod
// postgres-user database user that is able to access the database
// database-name name of the database
kubectl exec [pod-name] -- bash -c "pg_dump -U [postgres-user] [database-name]" > database.sql
RESTORE
// pod-name name of the postgres pod
// postgres-user database user that is able to access the database
// database-name name of the database
@ricjcosme
ricjcosme / udp_proxy.py
Created September 14, 2017 01:22
UDP proxy in python
View udp_proxy.py
import socket
from threading import Thread
class Proxy(Thread):
""" used to proxy single udp connection
"""
BUFFER_SIZE = 4096
def __init__(self, listening_address, forward_address):
print " Server started on", listening_address
Thread.__init__(self)
@ricjcosme
ricjcosme / gist:892e0e3f6f10120278962f3055df6212
Last active November 10, 2017 14:26
Generate kubectl delete commands for replica sets
View gist:892e0e3f6f10120278962f3055df6212
kubectl get --all-namespaces rs -o json|jq -r '.items[] | select(.spec.replicas | contains(0)) | "kubectl delete rs --namespace=\(.metadata.namespace) \(.metadata.name)"'
@ricjcosme
ricjcosme / main.go
Created April 4, 2018 10:19
Command line base58 enc/dec in golang
View main.go
package main
import (
"fmt"
"io/ioutil"
"os"
"strings"
"bufio"
b58 "github.com/jbenet/go-base58"