Skip to content

Instantly share code, notes, and snippets.

@ltfschoen
ltfschoen / find_min_sorted_array_rotated.js
Last active March 27, 2017 11:43
Find Min Value of Rotated Sorted Array
/**
* Given a sorted array as input (ascending order only
* and without duplicates) that may be rotated
* and return the minimum value.
*/
let getMin = (x, y) => { return x <= y ? x : y; }
let getMid = (l, h) => { return parseInt((l + h)/2, 10); }
/**
@ltfschoen
ltfschoen / gist:c4b4cb56cb6d547992d7ff181982141d
Created April 30, 2017 06:24
# Apollo-bot snippet of Python code showing how Bot server may reply to user with text message
def reply(user_id, msg):
resp = requests.post("https://graph.facebook.com/v2.6/me/messages",
params={"access_token": fb_AT},
data=json.dumps({
"recipient": {"id": user_id},
"message": {"text": msg}
}),
headers={'Content-type': 'application/json'})
@ltfschoen
ltfschoen / proportions_of_missing_data_in_dataframe_columns.py
Last active October 20, 2021 07:43
Calculate percentage of NaN values in a Pandas Dataframe for each column. Exclude columns that do not contain any NaN values
# Author: Luke Schoen 2017
import pandas as pd
import numpy as np
import functools
# Create DataFrame
# df = pd.DataFrame(np.random.randn(10,2))
# Populate with NaN values
df = pd.DataFrame({'col1': ['1.111', '2.111', '3.111', '4.111'], 'col2': ['4.111', '5.111', np.NaN, '7.111'], 'col3': ['8', '9', np.NaN, np.NaN], 'col4': ['12', '13', '14', '15']})
Write a routine that presents a random list of candidates in preferred order based on skills, communication and experience
with experience being half as important than the other two attributes.
* Do not use the built-in sort function
* Use the task1.php template provided
* You will be judged on coding style and also the algorithm that you use
#!/usr/bin/php
<?php
@ltfschoen
ltfschoen / clean-docker-for-mac.sh
Created June 1, 2017 22:20 — forked from MrTrustor/clean-docker-for-mac.sh
This script cleans the Docker.qcow2 file that takes a lot of disk space with Docker For Mac. You can specify some Docker images that you would like to keep.
#!/bin/bash
# Copyright 2017 Théo Chamley
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in the Software
# without restriction, including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
# to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or
@ltfschoen
ltfschoen / ballot.sol
Created June 4, 2017 22:25
ethereum_mist_ballot_contract_default
pragma solidity ^0.4.0;
contract Ballot {
struct Voter {
uint weight;
bool voted;
uint8 vote;
address delegate;
}
struct Proposal {
@ltfschoen
ltfschoen / rvm2rbenv.txt
Last active August 8, 2017 13:36 — forked from brentertz/rvm2rbenv.txt
Switch from RVM to RBENV
## Prepare ###################################################################
# Remove RVM
rvm implode
sudo rm -rf /Users/<your_username>/.rvm/
# Remove RVM from ~/.bash_profile and ~/.bash_rc
# Ensure your homebrew is working properly and up to date
brew doctor
@ltfschoen
ltfschoen / codewars.rb
Last active August 22, 2017 23:01
codewars solutions
def get_middle(s)
len = s.length
if len == 1
return s
elsif len.even?
return s[(len/2)-1] + s[(len/2)]
else
return s[len/2]
end
end
@ltfschoen
ltfschoen / kali_linux_setup.md
Last active September 5, 2017 23:14
Kali Linux Setup
  • Read about Kali Linux
  • Download Kali Linux 64 bit VM for Mac
  • Extract the downloaded compressed .7z file by double clicking it into a directory
  • Create a Virtual Machine (VM) and follow these instructions to load the .vmdk file from that directory
  • Start the VM and login with Username: root, and Password: toor
  • Identify the "Host Key" (i.e. Left CMD) for mouse and keyboard capture from the host machine (your Mac)
    • Note: If the screensaver appears then drag across the screen to exit the screensaver
  • Other aspects to install
    • Installing VirtualBox Guest Additions in Kali Linux to allow you to share folders between the virtual machine Kali Linux and the host machine (your Mac)
  • [Setup networking and databases (PostgreSQL) with Metasploit](https://docs.kali.org/gene
@ltfschoen
ltfschoen / git-flow.sh
Last active September 9, 2017 01:57
Git-Flow Workflow
* Install Git-Flow
```
brew install git-flow
```
* Git-Flow Help
```
git-flow help
usage: git flow <subcommand>