Skip to content

Instantly share code, notes, and snippets.

View drem-darios's full-sized avatar

Drēm Darios drem-darios

View GitHub Profile
@drem-darios
drem-darios / SaltSignatureGenerator.java
Created March 9, 2017 18:04
Salt and Signature Java example. This is an example of how someone can do simple one way encryption so they don't have to store passwords in plaintext files. This is still vulnerable in other ways(such as dictionary attacks) but it better than nothing. To test this code, run 'mvn clean install' then run 'java -cp target/salt-signature-security-j…
package com.drem.security.util;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.security.GeneralSecurityException;
import java.security.SecureRandom;
import java.util.Properties;
import java.util.Random;
@drem-darios
drem-darios / salt_signature.py
Created March 9, 2017 18:06
Python example of how to create a salt and use a secret key to generate a signature using the salt
import hmac
import os
import hashlib
import base64
import unittest
__author__ = 'drem'
class SecurityUtil(object):
@drem-darios
drem-darios / ethereum-startup.sh
Created November 27, 2017 18:08
Bash script to install Ethereum on a Mac OS machine
# Install Go-Ethereum (geth)
brew tap ethereum/ethereum
brew install ethereum
# Install node modules to support Ethereum front end
npm install ethereumjs-testrpc web3@0.20.1
npm install solc
npm install -g truffle
npm install -g webpack
# Run an in-memory test Ethereum blockchain
@drem-darios
drem-darios / new-service
Last active September 15, 2018 22:10
This is a template for creating a new service on a linux box using init.d. Place this file in /etc/init.d Reference: https://unix.stackexchange.com/questions/20357/how-can-i-make-a-script-in-etc-init-d-start-at-boot
#!/bin/bash
# chkconfig: 2345 20 80
# description: Description comes here....
### BEGIN INIT INFO
### END INIT INFO
# Source function library.
#. /etc/init.d/functions
start() {
# code to start app comes here
@drem-darios
drem-darios / node.service
Created September 15, 2018 22:09
This starts a node service located in the /app directory using systemd. Put this file in /etc/systemd/system
[Unit]
Description=Node server
Documentation=https://google.com
After=network.target
[Service]
Environment=HOST=0.0.0.0
Environment=PORT=3000
Type=simple
User=ubuntu
@drem-darios
drem-darios / SortedSearch.java
Last active January 7, 2020 07:50
Counts the number of array elements that are less than the parameter lessThan
import java.util.*;
public class SortedSearch {
public static int countNumbers(int[] sortedArray, int lessThan) {
int left = 0;
int right = sortedArray.length - 1;
int count = 0;
while (left <= right)
{
@drem-darios
drem-darios / UserInput.java
Created January 7, 2020 07:50
User interface contains two types of user input controls: TextInput, which accepts all characters and NumericInput, which accepts only digits.
import java.lang.StringBuilder;
public class UserInput {
public static class TextInput{
StringBuilder input = new StringBuilder();
public void add(char c) {
input.append(c);
}
@drem-darios
drem-darios / LinkedList.java
Created January 8, 2020 05:11
Simple Doubly Linked List Implementation
public class LinkedList {
private Node head;
private Node tail;
public LinkedList() {
}
private class Node {
@drem-darios
drem-darios / max_sub_array_of_size_k.py
Last active February 6, 2020 06:39
Given an array of positive numbers and a positive number ‘k’, find the maximum sum of any contiguous subarray of size ‘k’.
# By Drem
def max_sub_array_of_size_k(k, arr):
maximumSum = 0
currentMaximumSum = 0
subArrayStart = 0
for subArrayEnd in range(len(arr)):
maximumSum += arr[subArrayEnd]
if subArrayEnd >= k - 1:
if maximumSum > currentMaximumSum:
@drem-darios
drem-darios / smallest_subarray_with_given_sum.py
Last active February 9, 2020 06:30
Given an array of positive numbers and a positive number ‘S’, find the length of the smallest contiguous subarray whose sum is greater than or equal to ‘S’. Return 0, if no such subarray exists.
import math
def smallest_subarray_with_given_sum(s, arr):
subArrayStart = 0
resultArraySize = math.inf
subArraySum = 0
for subArrayEnd in range(0, len(arr)):
subArraySum += arr[subArrayEnd]
while subArraySum >= s: