Skip to content

Instantly share code, notes, and snippets.

View codeadict's full-sized avatar
🕸️
λ: f(f(state)) = f(state)

Dairon M. codeadict

🕸️
λ: f(f(state)) = f(state)
View GitHub Profile
@codeadict
codeadict / env
Created January 7, 2018 21:39
Loading .env
$ cat .env
API_KEY=supersecretstuff
$ pipenv run python
Loading .env environment variables…
Python 3.6.3 (default, Oct 4 2017, 06:09:15)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.37)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.getenv['API_KEY']
@codeadict
codeadict / pipenv_check.sh
Last active January 7, 2018 21:25
Pipenv security check
$ pipenv check
Checking PEP 508 requirements…
Passed!
Checking installed package safety…
33300: django >=1.10,<1.10.7 resolved (1.10.1 installed)!
CVE-2017-7233: Open redirect and possible XSS attack via user-supplied numeric redirect URLs
============================================================================================
Django relies on user input in some cases (e.g.
@codeadict
codeadict / cookiecutter_requirements.txt
Last active December 29, 2017 21:42
Common packages needed for Cookecutter with Hooks
python-jenkins==0.4.15
PyGithub==1.35
cookiecutter==1.6.0
@codeadict
codeadict / Pipfile.toml
Last active January 7, 2018 21:58
Example Python's Pipfile
[[source]]
url = 'https://pypi.python.org/simple'
verify_ssl = true
[requires]
python_version = '3.6'
[packages]
flask = "*"
boto3 = ">=1.4"
@codeadict
codeadict / lower_case_json.py
Created August 31, 2017 15:49
Lower case Json decoder in Python3
class LowerCaseJSONDecoder(JSONDecoder):
def _lower_keys(self, obj):
new = {}
for k, v in obj.items():
if isinstance(v, dict):
v = self._lower_keys(v)
new[k.lower()] = v
return new
@codeadict
codeadict / currify.py
Created October 6, 2015 05:13
My modest Python currying implementation using a decorator. Currying is a kind of incremental binding of function arguments.
def currify(func):
"""
Decorator to curry a function, use it like this:
>>> @currify
... def sum(a, b, c):
... return a + b + c
It works on normal way:
>>> sum(1, 2, 3)
6
And also binding the params:
@codeadict
codeadict / gen_primes.py
Created September 29, 2015 17:29
Generates a list of prime numbers from 2 to N. Done for a friend homework of MIT edx.
def primesList(N):
"""
Generates a list of prime numbers from 2 to N.
N: an integer
"""
return [a for a in range(2, N) if not [b for b in range(2,a) if not a%b]]
def __main__():
print primesList(100)
@codeadict
codeadict / 20150928213406_add_us_states.rb
Created September 29, 2015 17:08
Rails migration that creates a table with all United States states and associated territories
class AddUsStates < ActiveRecord::Migration
def up
create_table :states do |t|
t.string :iso_abbr, unique: true
t.string :name
t.timestamps
end
#: insert states here
states_data = [
@codeadict
codeadict / 20150806152332_property_status_history.rb
Created August 6, 2015 15:46
Migration for property status history
class PropertyStatusHistory < ActiveRecord::Migration
def change
create_table :property_history do |t|
t.references :property, index: true, null: false
t.references :user, null: false, index: true
t.string :status, null: false
t.datetime :datetime, null: false
end
end
end
@codeadict
codeadict / import_models.rb
Created July 21, 2015 15:07
Importer Data structure
class DataImportTables < ActiveRecord::Migration
def change
create_table :imports do |t|
t.string :for_model, null: false, default: 'Properties'
t.string :name, null: false
t.attachment :file, null: false
t.references :company, null: false
t.timestamps null: false
end