Skip to content

Instantly share code, notes, and snippets.

@acatejr
acatejr / pyloops.py
Last active February 19, 2020 00:35
Replacing For Loops in Python with Map, Filter and Reduce
"""
numbers = [1,2,3,4,5,6]
odd_numbers = []
squared_odd_numbers = []
total = 0
# filter for odd numbers
for number in numbers:
if number % 2 == 1:
odd_numbers.append(number)

Keybase proof

I hereby claim:

  • I am acatejr on github.
  • I am acatejr (https://keybase.io/acatejr) on keybase.
  • I have a public key ASB_4A-FIoSiL9-X5yXwT6MZdz7zYX9p6xRUxmhhh6cixwo

To claim this, I am signing this object:

@acatejr
acatejr / renaming_git_branch.md
Last active April 18, 2017 18:17
Renaming a Git Branch

Steps for renaming a git branch

  1. Rename the local branch
    If on local branch: git branch -m new name
    If on a different branch: git branch -m old name new name

  2. Delete the old-name remote branch and push the new-name local branch
    git push origin : old name new name

  3. Reset the upstream branch for the new-name local branch

@acatejr
acatejr / samb.example.conf
Last active December 17, 2016 20:06
samba share example
;; This creates a samba share that can be used to map a drive on windows to
;; a resources in a Unix/Linux based virtual machine.
[ubuntu]
path = /home/ubuntu
writeable = yes
read only = no
browseable = yes
guest ok = yes
create mask = 0755
directory mask = 0755
@acatejr
acatejr / docker.notes.md
Last active July 12, 2017 19:11
Docker Notes

Create a docker volume for persisting postgresql data.

docker create -v /var/lib/postgresql/data --name postgres9.5-data busybox

Run a postgresql instance using the created volume.

docker run --name local-postgres9.5 -p 5432:5432 -e POSTGRES_PASSWORD=sql -d --volumes-from postgres9.5-data postgres:9.5

Run Update With Fixes

RUN apt update -y --fix-missing

@acatejr
acatejr / django_example.urls.py
Last active August 18, 2016 22:05
Django URL Patterns
# An example of a url with three parameters separated by forward slash.
url(r'^addresspermits/(?P<param1>.+)/(?P<param2>.+)/(?P<param3>.+)/$','views.method_name', name='method_name'),
# Single value parameter that allows a combination of upper and lower case characters.
url(r'^detail/(?P<param>[\w|\W]+)$', 'views.detail', name='detail'),
@acatejr
acatejr / d3.js
Last active April 21, 2016 21:48
D3.js Code Snippets
// How to group data
var map = d3.nest()
.key(function(d) { return d.attribute; })
.rollup(function(v) {
return {
count: v.length
};
})
.map(data);
@acatejr
acatejr / visual_studio_code_tips.md
Created April 14, 2016 14:46
Visual Studio Code Tips

To hide file in the explorer pane File -> Preferences -> User Settings This opens the settings.json file Create like the following entry:

"files.exclude": { "**/*.pyc": true, }

This would prevent all .pyc files from being listed in the Explorer pane tree-veiw.

@acatejr
acatejr / enable_svg.py
Last active January 21, 2019 12:31
Rendering svg static files while running Django development server
# The django development server (1.9) does not seem to render svg files. In order to render them these lines
# can be added to the project's settings.py file. This may require restarting the django server and clearing the browser cache.
import mimetypes
mimetypes.add_type("image/svg+xml", ".svg", True)
mimetypes.add_type("image/svg+xml", ".svgz", True)
@acatejr
acatejr / angular_brackets.js
Last active August 29, 2015 14:25
Angular Brackets and CSRF Tokens for Django
// Change the Angular brackets to [[ and ]]
$interpolateProvider.startSymbol('[[').endSymbol(']]');
// Tells the app to use csrf token in views
$httpProvider.defaults.xsrfCookieName = 'csrftoken';
$httpProvider.defaults.xsrfHeaderName = ' X-CSRFToken';
// Stop Angular strip trailing slashes. Angular loves to strip trailing slashes.
// Newer in Angular 3
$resourceProvider.defaults.stripTrailingSlashes = false;