Skip to content

Instantly share code, notes, and snippets.

# Consider a rectangular chess board of a × b squares.
# For each of the squares imagine a lone queen standing on that square and
# compute the number of squares under the queen's attack. Add all the numbers
# you got for each of the a × b possible queen's positions.
# Example
# For a = 2 and b = 3, the output should be
# chessBoardSquaresUnderQueenAttack(a, b) = 26.
import pandas as pd
d = {
'col1': [True, True, False, False, True, False],
'col2': [False, True, False, True, True, False],
'col3': [True, False, False, False, True, False],
'col4': [True, False, True, False, True, True],
'col5': ['T', 'T', 'L', 'L', 'T', 'L']
}
df = pd.DataFrame(data=d)
# List unique values in a DataFrame column
# h/t @makmanalp for the updated syntax!
df['Column Name'].unique()
# Convert Series datatype to numeric (will error if column has non-numeric values)
# h/t @makmanalp
pd.to_numeric(df['Column Name'])
# Convert Series datatype to numeric, changing non-numeric values to NaN
# h/t @makmanalp for the updated syntax!
@arthuralvim
arthuralvim / bootstrap_homeshick.sh
Created June 29, 2018 17:43 — forked from andsens/bootstrap_homeshick.sh
Script that can set up an entire user account with homeshick automatically
#!/bin/bash -ex
# Paste this into ssh
# curl -sL https://gist.github.com/andsens/2913223/raw/bootstrap_homeshick.sh | tar -xzO | /bin/bash -ex
# When forking, you can get the URL from the raw (<>) button.
### Set some command variables depending on whether we are root or not ###
# This assumes you use a debian derivate, replace with yum, pacman etc.
aptget='sudo apt-get'
chsh='sudo chsh'
@arthuralvim
arthuralvim / boto3_iam_access_key_rotation.py
Created June 4, 2018 20:37 — forked from andymotta/boto3_iam_access_key_rotation.py
Rotate AWS IAM access keys for every Boto profile on host (Compliance)
## Meant to be scheudled on a cron/timer of 90 days (CIS Benchmark)
## The target keys need permissions to rotate themselves
import boto3
from botocore.exceptions import ClientError
import os
from datetime import datetime
import shutil
from ConfigParser import SafeConfigParser
@arthuralvim
arthuralvim / permissions.sql
Created January 22, 2018 20:05
Working with permissions on PostgreSQL.
CREATE ROLE [user_read_only] WITH LOGIN PASSWORD 'mysuperstrongpassword' NOSUPERUSER INHERIT NOCREATEDB NOCREATEROLE NOREPLICATION VALID UNTIL 'infinity';
GRANT CONNECT ON DATABASE [database_name] TO [user_read_only];
GRANT USAGE ON SCHEMA public TO [user_read_only];
GRANT SELECT ON [table_name] TO [user_read_only];
REVOKE ALL ON DATABASE [database_name] FROM [user_read_only];
REVOKE ALL ON SCHEMA public FROM [user_read_only];
REVOKE ALL ON [table_name] FROM [user_read_only];
DROP USER [user_read_only];
@arthuralvim
arthuralvim / jsonschema_example.py
Created November 21, 2017 13:42
Testing jsonschema.
# pip install jsonschema
import json
from jsonschema import Draft4Validator
lista_exemplo = [
{'attr1': 'A', 'attr2': 2, 'attr3': 3, 'attr4': 4},
{'attr1': 1, 'attr2': 2, 'attr3': 3, 'attr4': 4, 'attr5': 5},
{'attr1': 1, 'attr2': 2, 'attr3': 3, 'attr4': 4},
{'attr1': 1, 'attr2': 2, 'attr3': 3, 'attr4': 4},
@arthuralvim
arthuralvim / mongodb_snippets.md
Last active November 21, 2017 13:44
MongoDB Snippets

basic search

db.getCollection('collection_1').find({});

projection

db.getCollection('collection_1').find({}, {'_id': 1});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@arthuralvim
arthuralvim / NLTK and Named Entity Recognition (Person).ipynb
Created October 19, 2017 19:11
LTK and Named Entity Recognition (Person) in Brazilian Portuguese
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.