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 / 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:
@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 / 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 / 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 / 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 / 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 / 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 / postgres-cold-reboot-fix-osx.md
Last active September 1, 2018 12:45
Postgres Cold Reboot fix on OSX

I use brew's postgresql service and after cold reboot on the mac I was using, I got the following when I tried to access psql on the command line:

psql: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

I got my fix from here. In a nutshell, the postmaster.pid file already exists and has to be removed. Removing file that file fixed it for me i.e.

rm -f /usr/local/var/postgres/postmaster.pid

You might also want to to checkout the postgres log file (tail -n 10 /usr/local/var/log/postgres.log) for any errors and bugs.

@ivermac
ivermac / clojure-type-reflection.md
Created September 1, 2018 12:55
Clojure Type Reflection

Found clojure type reflection useful when using java objects in clojure. Especially in the repl

(use 'clojure.pprint 'clojure.reflect)
(def object-members (:members (reflect <object>)))
(print-table [:name :type :flags] (sort-by :name object-members))

The official documentation is here

@ivermac
ivermac / hash-map-to-query-param-string.md
Created September 7, 2018 03:15
Convert clojure hash-map to query param string
(defn get-query-params-str [query-params-map & [query-param-str]]
  "Converts a hash-map to a query param string containing the keys and values
   in the hash-map
   Note: this function assumes the values have already been url-encoded"
  (let [query-param-str (str query-param-str)
        query-param-str-blank? (string/blank? query-param-str)
        key (first (keys query-params-map))
        query-param-key (name (or key ""))
        query-param-val (and key (key query-params-map))]