Skip to content

Instantly share code, notes, and snippets.

View mekarpeles's full-sized avatar
📚
Universal Access to All Knowledge

Mek mekarpeles

📚
Universal Access to All Knowledge
View GitHub Profile
// see: https://stackoverflow.com/questions/3597116/insert-html-after-a-selection
// see: https://stackoverflow.com/questions/16662393/insert-html-into-text-node-with-javascript
var s = window.getSelection();
//insert start span at selection.anchorOffset within selection.anchorNode + closing tag at selection.focusOffset within selection.focusNode
// inserts a new node containing selection and returns reference to this node
var wrapSelectionInElement = function(s, e) {
var start = s.getRangeAt(s.anchorNode);
var startOffset = s.anchorOffset;
@mekarpeles
mekarpeles / foo.py
Created April 21, 2018 23:19
Preventing bidirectional links in table
question_questions = \
Table('question_to_questions', core.Base.metadata,
Column('question_parent_id', BigInteger, ForeignKey('questions.id'),
primary_key=True, nullable=False),
Column('question_child_id', BigInteger, ForeignKey('questions.id'),
primary_key=True, nullable=False),
created = Column(DateTime(timezone=False), default=datetime.utcnow,
nullable=False),
UniqueConstraint('question_parent_id', 'question_child_id',
name='question_parent_child_uix')
@mekarpeles
mekarpeles / contributing
Created January 2, 2018 22:52
Open Library Contributor's Guide
# Getting Started
**Installing Open Library**
For instructions on setting up a local developer's instance of Open Library, please refer to https://github.com/internetarchive/openlibrary#installation. Also, refer to the Quickstart Guide: https://github.com/internetarchive/openlibrary/blob/master/Quickstart.md
**Resources for Contributors**
Look through our issues related to `contributing`:
https://github.com/internetarchive/openlibrary/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+label%3Acontributing
**Want to Participate in the Community?**
[
{
"author": "Aeschines",
"language": "Wrote in Greek",
"years": ["390 B.C.E", "314 B.C.E."]
},
{
"author": "Aeschylus",
"language": "Wrote in Greek",
"years": ["525 B.C.E", "456 B.C.E."]
@mekarpeles
mekarpeles / app.py
Created July 28, 2014 23:09
Flask application hangs on VM (results in broken pipe).
----------------------------------------
127.0.0.1 - - [29/Jul/2014 01:05:43] "GET / HTTP/1.1" 200 -
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 59305)
Traceback (most recent call last):
File "/usr/lib/python2.7/SocketServer.py", line 295, in _handle_request_noblock
self.process_request(request, client_address)
File "/usr/lib/python2.7/SocketServer.py", line 321, in process_request
self.finish_request(request, client_address)
File "/usr/lib/python2.7/SocketServer.py", line 334, in finish_request
import datetime
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, scoped_session
from sqlalchemy import Column, String, BigInteger, DateTime
# DB = {'dbn' ... } assume DB is defined with correct engine (k,v)'s
engine = create_engine('%(dbn)s://%(user)s:%(pw)s@%(host)s/%(db)s' % DB, echo=True)
DBSession = scoped_session(sessionmaker(bind=engine))
class Bar(object):
@classmethod
def b(cls, _Foo):
print(_Foo.TBL)
@mekarpeles
mekarpeles / gist:7074562
Created October 20, 2013 20:03
choosing a first distro
+--------------------+--------+--------+--------+
| Distro | Ubuntu | Debian | Mint |
+--------------------+--------+--------+--------+
| Low Learning Curve | 4 | 3 | 4 |
| Ease of Install | 5 | 3 | ? |
| Driver Support | 4 | 3 | ? |
| Package Mngmt | 4 | 4 | 3 | -- apt=4, dpkg=3, portage=5
| Def. Graphical Env | 2 | 3 | 4 | -- gnome+unity=2, xfce=3
| Bloat-free? | 1 | 3 | 2 | -- 5 being LFS (linux from scratch)
| Performance | 2 | 3 | 2 | -- compared to gentoo, damn small linux, et al
import time
class profile(object):
__history = []
__synopsis = {}
__total = 0
def __init__(self, f):
self.__f = f