Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Working from 🛰

Harry Moreno morenoh149

💭
Working from 🛰
View GitHub Profile
@morenoh149
morenoh149 / mysql.sql
Last active Aug 14, 2021
role based access control schemas in mysql, postgres and sqlite
View mysql.sql
/*
* Create Tables
*/
CREATE TABLE IF NOT EXISTS `PREFIX_permissions` (
`ID` int(11) NOT NULL auto_increment,
`Lft` int(11) NOT NULL,
`Rght` int(11) NOT NULL,
`Title` char(64) NOT NULL,
`Description` text NOT NULL,
@morenoh149
morenoh149 / models.py
Last active Jun 21, 2021
Django model method mocking
View models.py
class Blog(django.model):
name = models.CharField(null=False, max_length=64)
def list_articles(self):
return [
{'body': 'abcdefg'},
{'body': 'abcdefg'},
{'body': 'abcdefg'},
]
@morenoh149
morenoh149 / migrate_error.sh
Last active Aug 12, 2020
django postgis install
View migrate_error.sh
/Users/harrymoreno/.local/share/virtualenvs/litt-api-HgI9cQzm/lib/python3.6/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.
""")
Traceback (most recent call last):
File "/Users/harrymoreno/.local/share/virtualenvs/litt-api-HgI9cQzm/lib/python3.6/site-packages/django/db/backends/utils.py", line 83, in _execute
return self.cursor.execute(sql)
psycopg2.ProgrammingError: permission denied to create extension "postgis"
HINT: Must be superuser to create this extension.
The above exception was the direct cause of the following exception:
@morenoh149
morenoh149 / gmail_imap_python3.py
Last active Jun 20, 2020 — forked from robulouski/gmail_imap_example.py
Basic example of using Python3 and IMAP to read emails in a gmail folder/label. Remove legacy email.header api use
View gmail_imap_python3.py
#!/usr/bin/env python
#
# Basic example of using Python3 and IMAP to read emails in a gmail folder/label.
# Remove legacy email.header api use.
import sys
import imaplib
import getpass
import email
import datetime
@morenoh149
morenoh149 / django-update-half.py
Last active Feb 27, 2020
Django update alternate model instances in shell
View django-update-half.py
"""
Update alternate instances of a model in the database.
"""
from app.models import Post
ids_to_update = list(Post.objects.all().values_list('id', flat=True))[1::2]
Post.objects.filter(id__in=ids_to_update).update(some_field='some value')
View shakti.docs
$ ./k
2020.02.25 (c) shakti
/
/
\
$k a.k
Verb Adverb Noun Type System
: set ' each char " a" c \l a.k
+ plus flip / over/right i enc name ``ab n *\d [d]
@morenoh149
morenoh149 / smart-contracts.md
Last active Feb 1, 2020
Intro to smart contract programming in solidity Oct 2019
View smart-contracts.md
@morenoh149
morenoh149 / intro-blockchain-programming.md
Last active Jan 27, 2020
Intro to blockchain programming in js
View intro-blockchain-programming.md

Introduction to Blockchain Programming, Jan 2020

Explain blockchain

Chain of blocks

View solidity-workshop.md

Soldity Workshop

Prerequisites

Attendees should do the following before the event to get the most out of it. There will be a 20 minute lecture-overview at the beginning. You can do the prerequisites during the overview if you have not done so by then.

  1. install node.js (lts version is recommended)
  2. install git (use brew if on osx)
  3. install a code editor (vscode or atom.io)
@morenoh149
morenoh149 / dp01.js
Created Feb 26, 2019
Dynamic programming example
View dp01.js
// The following was translated from python.
// See https://codility.com/media/train/15-DynamicProgramming.pdf
const dynamicCoinChanging = (coins, target) => {
let n = coins.length;
let dp = [0];
for (let i=0; i < target; i++) {
dp.push(Number.POSITIVE_INFINITY);
}
for (let i=0; i <= n; i++) {