Skip to content

Instantly share code, notes, and snippets.

@mangalaman93
mangalaman93 / gorm_example.go
Created April 25, 2020 10:59
Use gorm with schema in postgres database
package main
import (
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/postgres"
)
type User struct {
ID int
Username string
# Install docker
sudo apt update
sudo apt install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt update
sudo apt -y install docker-ce
sudo usermod -aG docker $USER
# logout and login now
package main
import (
"encoding/json"
"flag"
"io/ioutil"
"log"
"sort"
)
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <condition_variable>
#include <mutex>
#include <thread>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <iostream>
#include <cassert>
#include <vector>
using namespace std;
typedef struct qsnap {
int first;
int last;
qsnap(int f, int l) : first(f), last(l) {}
} qsnap;
@mangalaman93
mangalaman93 / circular_printer.cpp
Created August 25, 2017 23:30
Threads printing string in circular fashion
#include <condition_variable>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <mutex>
#include <thread>
using namespace std;
mutex mut;
condition_variable* cond;
@mangalaman93
mangalaman93 / netfilter.py
Created April 24, 2016 18:35
Netfilter example in python
## Installation
# sudo apt-get install build-essential python-dev libnetfilter-queue-dev
# sudp pip install NetfilterQueue scapy
## References
# https://www.digitalocean.com/community/tutorials/how-to-list-and-delete-iptables-firewall-rules
# https://github.com/phaethon/scapy
# https://5d4a.wordpress.com/2011/08/25/having-fun-with-nfqueue-and-scapy/
# https://pypi.python.org/pypi/NetfilterQueue/0.3
# http://www.netfilter.org/documentation/HOWTO/netfilter-hacking-HOWTO-3.html
@mangalaman93
mangalaman93 / venv
Last active November 2, 2015 04:30
virtual enviornment for golang
#!/bin/bash
if [[ $0 != "/bin/bash" ]]; then
echo "Error: source the script!"
exit 1
fi
if [[ ! -d $(pwd)/go/bin ]]; then
echo "Error: go installtion not found in the current directory!"
return
@mangalaman93
mangalaman93 / sysclient.go
Last active October 29, 2015 15:54
setting low level socket options in golang (SO_PRIORITY, SO_REUSEADDR)
package main
import (
"bufio"
"fmt"
"net"
"os"
"syscall"
)
@mangalaman93
mangalaman93 / sysserver.go
Last active May 14, 2024 02:39
setting low level socket options in golang (SO_PRIORITY, SO_REUSEADDR)
package main
import (
"bufio"
"fmt"
"net"
"os"
"syscall"
)