Skip to content

Instantly share code, notes, and snippets.

@xw19
xw19 / Balance.cpp
Created May 25, 2020 13:42
Balancing a binary tree
#include <iostream>
#include <vector>
struct Node {
int value;
struct Node *left;
struct Node *right;
};
#include <iostream>
using namespace std;
struct Node {
int data;
struct Node *left;
struct Node *right;
};
@xw19
xw19 / maxand.cpp
Created June 27, 2019 16:56
Calculating Maximum and value
#include <iostream>
using namespace std;
int maxAND(int[], int);
int main() {
int t;
@xw19
xw19 / Uf.py
Created June 9, 2019 02:03
Union Find
def __init__(self, n):
self.data = [i for i in range(1, n)]
def connected(self, p, q):
return self.data[q] == self.data[p]
def union(self, p, q):
pid = self.data[p]
qid = self.data[q]
@xw19
xw19 / main.go
Created May 27, 2018 13:43 — forked from walm/main.go
Simple Golang DNS Server
package main
import (
"fmt"
"log"
"strconv"
"github.com/miekg/dns"
)
@xw19
xw19 / add_public_key_to_ansible_hosts.sh
Last active February 11, 2018 08:04
This script adds my public key to the hosts listed in ansible hosts
#!/bin/bash
if [ "$UID" -ne 0 ];
then
echo "Run this script as root user only"
exit 100
fi
while getopts ":p:f:u:" o; do
case "${o}" in
#!/bin/bash
VBoxManage setproperty machinefolder /data/vbox
VM="centos7"
mkdir /data/vbox/$VM
VBoxManage createhd --filename /data/vbox/$VM/$VM.vdi --size 32768
#RedHat_64
VBoxManage createvm --name $VM --ostype "RedHat_64" --register
@xw19
xw19 / installvbox_centseven.sh
Last active February 10, 2018 04:12
Installing virtualbox on centos 7
#!/bin/bash
if [ "$UID" -ne 0 ]
then
echo "Must be root to run this script."
exit 100
fi
cd /etc/yum.repos.d
wget http://download.virtualbox.org/virtualbox/rpm/rhel/virtualbox.repo
class Loan < ActiveRecord::Base
has_many :short_messages, dependent: :destroy
belongs_to :shop
belongs_to :player
belongs_to :inventory_racket
validate :check_availabilty, on: :create
package main
import (
"fmt"
)
func main() {
var t int
fmt.Scan(&t)
numbers := make([]int, t)