Skip to content

Instantly share code, notes, and snippets.

@AbdouSeck
AbdouSeck / too_many_open_files.py
Created July 14, 2021 00:08
Using mp.Pool instead of mp.Process
import multiprocessing as mp
def RunPrice(items, price):
print("There is %s items, price is: %s" % (items, price))
def GetTargetItemsAndPrice(cursor):
res = cursor.execute("SELECT DISTINCT items, price FROM SELLS")
results = dict()
with mp.Pool() as pool:
@AbdouSeck
AbdouSeck / .gcloudignore
Last active May 18, 2020 18:29
GCP Cloud Function to Load Data to BQ
env.yaml
@AbdouSeck
AbdouSeck / playground.rs
Created April 24, 2020 03:40 — forked from rust-play/playground.rs
Code shared from the Rust Playground
fn main() {
let mut arr = [12, 8, 10, 3, 5, 10, 45];
if let Some(elem) = arr.get(10) {
println!("Element requested: {}.", elem);
} else {
println!(
"Element at index {} could not be found in an array of size {}.",
10,
arr.len()
);
@AbdouSeck
AbdouSeck / expand_ballrooms.R
Last active February 26, 2020 12:04
Reaction to the provided answer for Stackoverflow question at https://stackoverflow.com/q/35712196
# There is really not a dynamic way of doing what you want.
# You will need to expand the dash and generate a sequence from it.
# I wrote an example function that converts something like 2-4 into seq(2, 4)
expand.dash <- function(dashed) {
limits <- unlist(strsplit(dashed, '-'))
seq(limits[1], limits[2])
}
# We can use the above function inside another function which expands ballrooms

Keybase proof

I hereby claim:

  • I am abdouseck on github.
  • I am aseck (https://keybase.io/aseck) on keybase.
  • I have a public key ASDjVkM0h3zHkVUrkbaofaafZujw0FeGtxaYSAKgS4YnRQo

To claim this, I am signing this object:

# The arbitrary and opinionated conversion of strings to datetime in Series comparisons
# When comparing two values where the left side values is a pandas datetime object,
# Pandas casts the left side values to pd.DatetimeIndex
# Once the casting is successfully, Pandas then calls the __eq__ method on the result of the cast operation.
# In this case, you want to take a look at pd.DatetimeIndex.__eq__ to figure out how the comparison is being handled
# The following is how pd.DatetimeIndex.__eq__ is defined (it's a decorated function, so the function name doesn't come up):
def wrapper(self, other):
#!/usr/bin/env python3
"""
Script to test or run commands on given servers.
./this_script.py test # To test all servers
./this_script.py run --id 127.0.0.1 --command "echo hello world"
"""
from argparse import ArgumentParser, RawDescriptionHelpFormatter as RDHF
def test_servers(servers):
# persons.txt
# Person 1
# Class Grade
# Math A
# Science C
# English A
# Person 2
# Class Grade
# Math D
# English A
@AbdouSeck
AbdouSeck / group_until.R
Created October 3, 2018 00:03
R code to provide an answer to stackoverflow question at https://stackoverflow.com/q/52613778/3135417
# https://stackoverflow.com/q/52613778/3135417
# Function to keep track of diff changes along the V1 column
get_ids <- function(x) {
vrle <- rle(cummin(x))$lengths
rep(1:length(vrle), vrle)
}
# Thesis data
thesis <- data.frame(V1=c(8628, 8626, 8624, 8622, 8620, 8618,
@AbdouSeck
AbdouSeck / flask_unittesting.py
Last active July 10, 2018 22:38
Flask dummy app with unittest to provide a response to the stackoverflow question at https://stackoverflow.com/q/51252936/3135417
# application.py
from flask import Flask, render_template_string
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
class User(db.Model):
"""