Skip to content

Instantly share code, notes, and snippets.

View ivermac's full-sized avatar
πŸ‘‹
Hi there!

Mark Ekisa ivermac

πŸ‘‹
Hi there!
View GitHub Profile
@ivermac
ivermac / flatten-list-of-lists-in-python.md
Created August 16, 2018 15:43
Flatten list of lists in python

This worked in both python 2.7 and 3.6.4

sum([[1, 2, 3], [4, 5, 6]], [])
@ivermac
ivermac / url-encoding-and-decoding-python.md
Last active August 14, 2018 12:30
Url encoding and decoding in python

python 2.7

Use urlencode from urllib for encoding and parse_qs from urlparse for decoding. urlencode takes a dict while parse_qs takes a string. I learned from this awesome link.

python 3.6

Use urlencode from urllib.parse for encoding and parse_qs from urllib.parse for decoding. urlencode takes a dict while parse_qs takes a string.

compatibility in both python 2.7 and 3.6 com

Install future package version 0.16.0. Import urlencode and parse_qs from future.moves.urllib.parse.

@ivermac
ivermac / fetch-basic-auth.md
Created August 1, 2018 14:45
Using fetch with basic auth
let username = 'john';
let password = 'doe';
let url = `https://httpbin.org/basic-auth/${username}/${password}`
let authString = `${username}:${password}`
let headers = new Headers();
headers.set('Authorization', 'Basic ' + btoa(authString))
fetch(url,{method: 'GET', headers: headers})
    .then(function (response) {
 console.log (response)
@ivermac
ivermac / create-test-request-object-in-django.md
Last active March 21, 2019 13:22
Create django request object for testing

The following is a life-saver if you test request objects in django frequently and you don't necessarily need to hit a specific endpoint

from django.test import RequestFactory
request_factory = RequestFactory()
request = request_factory.get('/path', data={'name': u'test'})
@ivermac
ivermac / nvm-compatiblity-issue.md
Last active March 7, 2018 09:41
nvm compatible issue

I noticed the following warning being triggered when launching the terminal in my Visual Studio app a couple of times but I had ignored it:

➜ nvm is not compatible with the npm config "prefix" option: currently set to "/usr/local" 
  Run `npm config delete prefix` or `nvm use --delete-prefix v8.0.0 --silent` to unset it.

I got the exact same warning when launching tmux locally and that caught my attention. I use nvm locally to manage node versions so initially I thought that was the problem. A quick search on google and I found out that a couple of people had experienced the same problem. I found my solution here in a github

@ivermac
ivermac / multi-line-chained-python-functions.md
Last active March 3, 2018 09:21
Multi-line chained python functions

From a stack overflow link

Before line break

subkeyword = Session.query(
    Subkeyword.subkeyword_id, Subkeyword.subkeyword_word
).filter_by(
    subkeyword_company_id=self.e_company_id
).filter_by(
 subkeyword_word=subkeyword_word
@ivermac
ivermac / gist:a895b28f3546686386f3ed41f61ca2f0
Created February 24, 2018 17:26 — forked from rxaviers/gist:7360908
Complete list of github markdown emoji markup

People

:bowtie: :bowtie: πŸ˜„ :smile: πŸ˜† :laughing:
😊 :blush: πŸ˜ƒ :smiley: ☺️ :relaxed:
😏 :smirk: 😍 :heart_eyes: 😘 :kissing_heart:
😚 :kissing_closed_eyes: 😳 :flushed: 😌 :relieved:
πŸ˜† :satisfied: 😁 :grin: πŸ˜‰ :wink:
😜 :stuck_out_tongue_winking_eye: 😝 :stuck_out_tongue_closed_eyes: πŸ˜€ :grinning:
πŸ˜— :kissing: πŸ˜™ :kissing_smiling_eyes: πŸ˜› :stuck_out_tongue: