I hereby claim:
- I am mohammedri on github.
- I am mohammedri (https://keybase.io/mohammedri) on keybase.
- I have a public key whose fingerprint is 4324 9942 2C67 5395 05D7 A261 5ACC 6941 89EB 512B
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
#!/usr/bin/env python3 | |
import fileinput | |
import sys | |
import re | |
import os | |
rootdir = os.getcwd() | |
extensions = ('.py') |
import numpy as np | |
import pandas as pd | |
def load_data(path): | |
return pd.read_csv(csv_path) | |
def split_dataset_into_train_test(data, test_ratio): | |
shuffler = np.random.permutation(len(data)) | |
test_set_size = int(len(data)*test_ratio) | |
test_indices = shuffler[:test_set_size] |
// Functional programming approach to parsing query strings in Typescript/ES6. | |
function parseQueryString(search: string) { | |
return (search.startsWith('?') ? search.substring(1) : search) | |
.split('&') | |
.map(str => { | |
const eqIdx = str.indexOf('='); | |
if (eqIdx <= 0 || eqIdx >= str.length - 1) { | |
return {}; | |
} |
# Using gsub (least performant) | |
"test_string".capitalize.gsub(/_(\w)/){$1.upcase} # => TestString | |
# Using split & map with capitalize | |
"test_string".split('_').map(&:capitalize).join | |
# Using split & map (most performant) |
HTTP status code symbols for Rails | |
Thanks to Cody Fauser for this list of HTTP responce codes and their Ruby on Rails symbol mappings. | |
Status Code Symbol | |
1xx Informational | |
100 :continue | |
101 :switching_protocols | |
102 :processing |
Hosting services like Heroku and Amazon EC2 are nice. That is, until they cost money. Some things are worth running on your own hardware, especially when the cost and Terms of Service requirements outweigh the expense of rolling your own hosting.
I am writing this because I recently had to figure all this out in order to host a personal blog off a Raspberry Pi, and I thought I'd share what I learned. This guide assumes that you already know how to install Ruby and you know how to use Rails. If you don't, look those up first before coming back to this guide.
This method avoids merge conflicts if you have periodically pulled master into your branch. It also gives you the opportunity to squash into more than 1 commit, or to re-arrange your code into completely different commits (e.g. if you ended up working on three different features but the commits were not consecutive).
Note: You cannot use this method if you intend to open a pull request to merge your feature branch. This method requires committing directly to master.
Switch to the master branch and make sure you are up to date:
import pyaudio | |
import wave | |
FORMAT = pyaudio.paInt16 | |
CHANNELS = 2 | |
RATE = 44100 | |
CHUNK = 1024 | |
RECORD_SECONDS = 5 | |
WAVE_OUTPUT_FILENAME = "file.wav" | |
//Knapsack algorithm | |
//================== | |
// wikipedia: [Knapsack (0/1)](http://en.wikipedia.org/wiki/Knapsack_problem#0.2F1_Knapsack_Problem) | |
// Given a set `[{weight:Number, benefit:Number}]` and a capacity, | |
// find the maximum value possible while keeping the weight below | |
// or equal to the capacity | |
// **params**: | |
// `capacity` : Number, | |
// `items` : [{w:Number, b:Number}] | |
// **returns**: |