Skip to content

Instantly share code, notes, and snippets.

@deevis
deevis / gist:0ade0f184f9ad528c66a56482728419f
Created September 27, 2017 21:27
Home/End keys on Mac OSX with Sublime
{ "keys": ["home"], "command": "move_to", "args": {"to": "bol"} },
{ "keys": ["end"], "command": "move_to", "args": {"to": "eol"} },
{ "keys": ["shift+end"], "command": "move_to", "args": {"to": "eol", "extend": true} },
{ "keys": ["shift+home"], "command": "move_to", "args": {"to": "bol", "extend": true } },
{ "keys": ["ctrl+home"], "command": "move_to", "args": {"to": "bof"} },
{ "keys": ["ctrl+end"], "command": "move_to", "args": {"to": "eof"} },
{ "keys": ["ctrl+shift+home"], "command": "move_to", "args": {"to": "bof", "extend": true} },
{ "keys": ["ctrl+shift+end"], "command": "move_to", "args": {"to": "eof", "extend": true} }
@deevis
deevis / gist:f798f8f4583214ccab18f17f584604f2
Last active August 28, 2017 17:29
Ruby File.combine_relative_paths
# Note: there is also URI::join(base_path, relative_path) for URI paths
#
File.class_eval do
# combines "some/path/here" and "../there/something?asdf=qwerty" to be:
# "/some/path/there/something?asdf=qwerty"
#
# usage: File.combine_relative_path(base_path, relative_path)
#
def self.combine_relative_paths(base_path, relative_path)
@deevis
deevis / keras_and.py
Last active August 17, 2017 03:19
Small Neural Net to perform a logical AND (can also satisfy logical OR)
from tensorflow.contrib.keras.api.keras.models import Sequential, Model
from tensorflow.contrib.keras.api.keras.layers import Dense
from tensorflow.contrib.keras.api.keras.optimizers import SGD
import numpy as np
X = np.array([[0,0],[0,1],[1,0],[1,1]])
y = np.array([[0],[0],[0],[1]])
# y = np.array([[0],[1],[1],[1]]) # The same size Network can train a logical OR
model = Sequential()
@deevis
deevis / keras_xor.py
Last active August 16, 2017 07:12
Using Tensorflow and Keras to approximate an XOR
import numpy as np
from tensorflow.contrib.keras.api.keras.models import Sequential, Model
from tensorflow.contrib.keras.api.keras.layers import Dense, Activation, Dropout
from tensorflow.contrib.keras.api.keras.optimizers import SGD
model = Sequential()
# tanh activation allows [-1,1]
model.add(Dense(6, input_dim=2, activation='tanh'))
# hard_sigmoid will converge much faster than sigmoid with this example
model.add(Dense(1, activation='hard_sigmoid'))
@deevis
deevis / gist:359741f1e498da14f9e3
Created October 26, 2015 21:00
Choose multiple files from current branch as the 'merge conflict winner'
# All the files that match with 'coverage' and tell git to use the branch we're on currenthl (ours, opposed to theirs)
git status | grep coverage | sed 's/.*: \(.*\)/\1/g' | xargs git checkout --ours
@deevis
deevis / gist:1778de206c067f8c2042
Created October 26, 2015 18:14
Remove color codes from txt file using sed
sed 's/\x1B\[[0-9;]*[JKmsu]//g' file_to_process > new_file
@deevis
deevis / ruby_in_memory_benchmark.rb
Last active September 29, 2015 16:28
Benchmark Ruby mechanisms for storage and retrieval of values
# Gist that compares different types of in-memory ruby data access
require 'benchmark-ips'
# The local variables
asdf = "wookie"
h = {asdf: "wookie"}
# The Constants
ASDF = "wookie"
# Must be root
sudo su -
vi /etc/hostname
# To prevent reboot (also as root)
cat /etc/hostname > /proc/sys/kernel/hostname
sudo lsof -p $MYSQL_PID | grep localhost | for x in `sed 's/.*mysql->localhost:\(.*\) .*/\1/g'`; do sudo netstat -tapen | grep "0 127.0.0.1:$x"; done | sed 's/.* \(.*\)/\1/g' | sort | uniq -c | sort -n
@deevis
deevis / gist:61113a95429e219fd108
Last active October 26, 2015 21:01
Parse Vibe logs for slowest showing time to render, user, path, and time of request
zgrep "END: current_user" production.log.2.gz | sed 's/\(.*\) \[.*INFO.*current_user\[\(.*\)\] (\(.*\)) \(.*\)/\3\t\4\t\2\t\1/g' | sort -n | tail -n 20
# with process:request
grep "END: current_user" production.log | sed 's/\(.*\) \[.*INFO.*\[\(.*\)\].*current_user\[\(.*\)\] (\(.*\)) \(.*\)/\4\t\2\t\1\t\3\t\5/g' | sort -n | tail -n 100
# find with process:request, then loop back and find problems for each...
# Part 1
grep "END: current_user" production.log | sed 's/\(.*\) \[.*INFO.*\[\(.*\)\].*current_user\[\(.*\)\] (\(.*\)) \(.*\)/\4\t\2\t\1\t\3\t\5/g' | sort -n | tail -n 100 > slow_requests_10_26_2015.txt
# Part 2
for rqid in `cat slow_requests_10_26_2015.txt | sed 's/.*seconds\t\(.*\)\s.*2015.*/\1/g'`;do echo -e "API Calls for [$rqid]\n---------------------------\n"; grep $rqid production.log | grep "request to api.exigo.com" -A 1; echo -e "\n\n";done > exigo_slow_calls_report_10_26_2015.txt