Skip to content

Instantly share code, notes, and snippets.

View bDrwx's full-sized avatar

Andrew Bodosov bDrwx

View GitHub Profile
@bDrwx
bDrwx / solve.rs
Created October 21, 2019 20:42
14. Longest Common Prefix
impl Solution {
pub fn longest_common_prefix(strs: Vec<String>) -> String {
if strs.len() == 0 {
return "".to_string();
}
let mut prefix = strs[0].clone();
for n in 1..strs.len() {
while(!strs[n].contains(&prefix)){
prefix = prefix[..prefix.len()-1].to_string();
}
@bDrwx
bDrwx / ubuntu_agnoster_install.md
Created July 10, 2019 10:12 — forked from renshuki/ubuntu_agnoster_install.md
Ubuntu 16.04 + Terminator + Oh My ZSH with Agnoster Theme

Install Terminator (shell)

sudo add-apt-repository ppa:gnome-terminator
sudo apt-get update
sudo apt-get install terminator

Terminator should be setup as default now. Restart your terminal (shortcut: "Ctrl+Alt+T").

Install ZSH

@bDrwx
bDrwx / two-summ.rs
Created June 21, 2019 20:55
Two Sum with HashMap
use std::collections::HashMap;
impl Solution {
pub fn two_sum(nums: Vec<i32>, target: i32) -> Vec<i32> {
let mut index_hashmap = HashMap::with_capacity(nums.len());
for (idx, &n) in nums.iter().enumerate() {
let y = target - n;
if let Some(&i) = index_hashmap.get(&y) {
return vec![i as i32, idx as i32];
@bDrwx
bDrwx / huawei.py
Last active June 17, 2019 20:06
Simple example
import getpass
import sys
import re
from netmiko import ConnectHandler
pattern = re.compile(r'Huawei\s\w+\s\w+\suptime')
COMMAND = sys.argv[1]
USER = input('Username: ')
PASSWORD = getpass.getpass()
@bDrwx
bDrwx / pig-latin
Created February 16, 2019 19:51 — forked from DenialAdams/pig-latin
A small program that takes a word (String) as input and translates it into Pig Latin
use std::io;
fn main() {
let mut input = String::new();
loop {
io::stdin().read_line(&mut input)
.expect("Failed to read line");
input = input.trim().to_string();
piglatinize(&mut input);
println!("{}", input);
@bDrwx
bDrwx / playground.rs
Created February 16, 2019 15:25 — forked from rust-play/playground.rs
Code shared from the Rust Playground
#![allow(unused)]
use std::collections::HashMap;
fn main() {
let mut vec = vec![3, 5, 6, 3, 4, 7, 4];
println!("Averege ={}", averege(&vec));
assert_eq!(median(&mut vec), 4.0);
println!("Median ={}", median(&mut vec));
println!("Mode ={}", mode(&vec));
}
fn averege(v: &[i32]) -> f32 {
with open('SK-KN-USKARS-SW-CE-1.txt', 'r') as myfile:
data = myfile.read()
# Hostname
result = re.search(r'hostname (SK-\S+)\n', data)
print(result.group(1))
#Loopback interface
result = re.search(r'interface Loopback\d+\n.*ip address (\d+.\d+.\d+.\d+)', data)
print(result)
#SNMP RW and RO Access list
result = re.search(r'snmp-server community (.+) RO (.+)', data)
@bDrwx
bDrwx / mmf.c
Created January 14, 2019 18:27
memory-mapped files
#include <fcntl.h>
#include <sys/mman.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <stdarg.h>
#define MAXLINE 4096 /* max line length */
function getUrlVars() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
vars[key] = value;
});
return vars;
}
$(document).ready(function() {
$.ajax({
#include <stdio.h>
#include <inttypes.h>
#include <x86intrin.h>
int bcd2int(int bcd)
{
static __v2di output = {0,0};
output[0]=bcd;
asm volatile(
“\tmovq\t%0, %%xmm0;\n” // use 128 bit SSE xmm registers