Skip to content

Instantly share code, notes, and snippets.

@Napear
Napear / GolangMode.go
Last active November 28, 2022 16:22
A function for returning the mode of a slice in Golang
func getMode(testArray []int) (mode int) {
// Create a map and populated it with each value in the slice
// mapped to the number of times it occurs
countMap := make(map[int]int)
for _, value := range testArray {
countMap[value] += 1
}
// Find the smallest item with greatest number of occurance in
// the input slice
@Napear
Napear / simple_tcp_server.rb
Created April 6, 2016 12:05
Simple Server Example in Ruby
require 'socket'
server_port = 1337
server = TCPServer.open(server_port) #create TCP socket
puts "[*] Listening on port #{server_port}"
# create loop to deal with incoming connections
loop do
while client = server.accept
fork do # create new process for each connection
puts "[*] Connection from: #{client.peeraddr}"
@Napear
Napear / gist:1b828915673f5fa77e0df437c66353a8
Created August 7, 2017 23:54
install docker/docker compose
#!/bin/bash
# Setup docker-ce and docker compose
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi
dockerComposeVersion=1.15.0 # latest version of compose as of 8/2/17
@Napear
Napear / nmap_scan_script.rb
Last active December 25, 2017 19:20
An automation script for initial nmap recon of an unknown subnet space.
require 'ipaddr'
require 'nokogiri'
# Helper functions
def debug_message(output)
puts "[##] Debug: #{output}"
end
def pluralize(subject)
's' if subject.size > 1
@Napear
Napear / bc_homework1.jl
Last active August 10, 2018 06:43
BookClub Homework #1
function prompt_user_input(message, defualt_value)
print(message)
input = readline()
value_entered =(input.len > 0) && (input.len < 128)
return value_entered ? input : defualt_value
end
function prompt_user_cont()
return contains(==, lowercase(prompt_user_input("We still doin' dis? [Y/n]: ", "y")), 'y')
end
#!/bin/bash
if [[ $EUID -ne 0 ]]; then
echo "[!!] This script must be run as root"
exit 1
fi
wget -nv https://download.opensuse.org/repositories/shells:fish:release:2/Debian_9.0/Release.key -O Release.key
apt-key add - < Release.key
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
// Protractor configuration file, see link for more information
// https://github.com/angular/protractor/blob/master/lib/config.ts
const { SpecReporter } = require('jasmine-spec-reporter');
exports.config = {
allScriptsTimeout: 11000,
specs: [
'./e2e/**/*.e2e-spec.ts'
],
#!/bin/bash
if pgrep flite > /dev/null
then
killall flite
else
xsel | flite -voice /usr/share/tts-voices/cmu_us_ljm.flitevox
fi
from tensorflow.compat.v1 import ConfigProto
from tensorflow.compat.v1 import InteractiveSession
config = ConfigProto()
config.gpu_options.per_process_gpu_memory_fraction = 0.6
config.gpu_options.allow_growth = True
session = InteractiveSession(config=config)