Skip to content

Instantly share code, notes, and snippets.

View jrjames83's full-sized avatar

Jeff James jrjames83

View GitHub Profile
@jrjames83
jrjames83 / aoc_day2_17.py
Created January 4, 2018 22:43
Advent of Code 2017: Day 2: Python (1 liner, list comprehension)
data = """86 440 233 83 393 420 228 491 159 13 110 135 97 238 92 396
3646 3952 3430 145 1574 2722 3565 125 3303 843 152 1095 3805 134 3873 3024
2150 257 237 2155 1115 150 502 255 1531 894 2309 1982 2418 206 307 2370
1224 343 1039 126 1221 937 136 1185 1194 1312 1217 929 124 1394 1337 168
1695 2288 224 2667 2483 3528 809 263 2364 514 3457 3180 2916 239 212 3017
827 3521 127 92 2328 3315 1179 3240 695 3144 3139 533 132 82 108 854
1522 2136 1252 1049 207 2821 2484 413 2166 1779 162 2154 158 2811 164 2632
95 579 1586 1700 79 1745 1105 89 1896 798 1511 1308 1674 701 60 2066
1210 325 98 56 1486 1668 64 1601 1934 1384 69 1725 992 619 84 167
4620 2358 2195 4312 168 1606 4050 102 2502 138 135 4175 1477 2277 2226 1286
@jrjames83
jrjames83 / bal_train_obs.ipynb
Created December 1, 2017 17:32
Audioset by Google - Balanced Train Class Labels and Frequencies
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
index mid display_name
0 /m/09x0r Speech
1 /m/05zppz Male speech, man speaking
2 /m/02zsn Female speech, woman speaking
3 /m/0ytgt Child speech, kid speaking
4 /m/01h8n0 Conversation
5 /m/02qldy Narration, monologue
6 /m/0261r1 Babbling
7 /m/0brhx Speech synthesizer
8 /m/07p6fty Shout
@jrjames83
jrjames83 / word2vec_python_gensim.md
Created August 22, 2017 21:11
Word2Vec Python Quickstart - Word Similarity
import gensim

# Load Google's pre-trained Word2Vec model.
# dl link https://github.com/mmihaltz/word2vec-GoogleNews-vectors
model = gensim.models.Word2Vec.load_word2vec_format('~/Documents/GoogleNews-vectors-negative300.bin', binary=True)
@jrjames83
jrjames83 / python_knapsack_dynamic.md
Created July 21, 2017 23:31
Python Knapsack Problem Dynamic Programming
vals = [1,4,5,7]
wts = [1,3,4,5]
capacity = 5

# Make the table (list comprehension)

w, h = capacity + 1, len(vals)
@jrjames83
jrjames83 / python_knapsack_01.py
Created July 20, 2017 20:16
Python Solution for Max Value of a Backpack (no partial items)
vals = [1,4,5,7] # the subjective values of the items
wts = [1,3,4,5] # the weights of the items
capacity = 7 # the max that the backpack can hold
# set-up the empty table
w, h = capacity+1, len(vals); # adding 1 to capacity since we start at zero
table = [[0 for x in range(w)] for y in range(h)]
# The outer loop is indexing against [0,1,2,3] which index
# into the vals and wts array

https://projecteuler.net/problem=41

We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly once.

For example, 2143 is a 4-digit pandigital and is also prime.

What is the largest n-digit pandigital prime that exists? 765 2413

The decimal number, 585 = 1001001001 base2 (binary), is palindromic in both bases.

Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2.

(Please note that the palindromic number, in either base, may not include leading zeros.)

format(585, 'b')
jeff=# SELECT * FROM sample_data sd;
string_data
----------------
en-src-m2m sim
en-src-m2m dog
en-src-m2m cat
(3 rows)
jeff=# select sd.string_data, split_part(sd.string_data, ' ', 1),split_part(sd.string_data, ' ', 2) FROM sample_data sd;
string_data | split_part | split_part
@jrjames83
jrjames83 / command_line.md
Last active November 20, 2017 17:50
Handy Bash / Command Line Commands

Count Files Matching A Certain Pattern

Option 1 - recursive

ls -1f | grep wav | wc -l

Option 2 - only current dir

find . -maxdepth 1 -name "*wav" | wc -l