Skip to content

Instantly share code, notes, and snippets.

View mohammedri's full-sized avatar
:shipit:

Mohammed Ridwanul mohammedri

:shipit:
View GitHub Profile

Keybase proof

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:

@mohammedri
mohammedri / search-and-replace-file-regex.py
Created February 23, 2020 21:28
Small Python script to search and replace a set of Python files for any multiline regex
#!/usr/bin/env python3
import fileinput
import sys
import re
import os
rootdir = os.getcwd()
extensions = ('.py')
@mohammedri
mohammedri / split_dataset_into_training_testing.py
Created October 25, 2018 01:53
A python to split a pandas dataset into a test sample and a training sample given a ratio
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]
@mohammedri
mohammedri / functional-query-string-parser.ts
Created October 23, 2018 18:42 — forked from nayeemzen/functional-query-string-parser.ts
Functional programming approach to parsing query strings in Typescript/ES6
// 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 {};
}
@mohammedri
mohammedri / snake_to_camel.rb
Last active August 21, 2018 19:39
[Ruby] Convert from snake_case to camel_case
# 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)
@mohammedri
mohammedri / rails http status codes
Created April 14, 2018 22:46 — forked from mlanett/rails http status codes
HTTP status code symbols for Rails
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

Host to Host a Rails App on a Home Server

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.

Prerequisites

  • Ruby >=2.0
  • Rails >=4.0
  • Nginx
@mohammedri
mohammedri / how-to-squash-commits-in-git.md
Created October 27, 2017 17:32 — forked from patik/how-to-squash-commits-in-git.md
How to squash commits in git

Squashing Git Commits

The easy and flexible way

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:

@mohammedri
mohammedri / sound_recorder.py
Created June 24, 2016 04:17 — forked from mabdrabo/sound_recorder.py
Simple script to record sound from the microphone, dependencies: easy_install pyaudio
import pyaudio
import wave
FORMAT = pyaudio.paInt16
CHANNELS = 2
RATE = 44100
CHUNK = 1024
RECORD_SECONDS = 5
WAVE_OUTPUT_FILENAME = "file.wav"
@mohammedri
mohammedri / knapsack.js
Created May 16, 2016 14:27 — forked from danwoods/knapsack.js
Knapsack algorithm in JavaScript
//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**: