Skip to content

Instantly share code, notes, and snippets.

@eirnym
eirnym / GitHub Flavored Asciidoc (GFA).adoc
Created Mar 14, 2021 — forked from dcode/GitHub Flavored Asciidoc (GFA).adoc
Demo of some useful tips for using Asciidoc on GitHub
View GitHub Flavored Asciidoc (GFA).adoc

GitHub Flavored Asciidoc (GFA)

@eirnym
eirnym / AsciidocCheatsheet.adoc
Created Mar 14, 2021 — forked from powerman/AsciidocCheatsheet.adoc
Asciidoc cheatsheet for GitHub
View AsciidocCheatsheet.adoc

Asciidoc cheatsheet for GitHub

@eirnym
eirnym / RandomDateGenerator.m
Created Apr 26, 2016
Random Date generator for Objective C.
View RandomDateGenerator.m
/**
Generate a random date sometime between now and n days before day.
Also, generate a random time to go with the day while we are at it.
@param days date range between today and minimum date to generate
@return random date
@see http://stackoverflow.com/questions/10092468/how-do-you-generate-a-random-date-in-objective-c
*/
@eirnym
eirnym / sqlalchemy_exists_patch.py
Last active Mar 23, 2021
SQLAlchemy 'if exists' patch
View sqlalchemy_exists_patch.py
import re
from sqlalchemy.ext.compiler import compiles
from sqlalchemy.schema import CreateTable, DropTable, \
CreateSequence, DropSequence, CreateIndex, DropIndex
from sqlalchemy.dialects.postgresql import DropEnumType
patches = (
(CreateTable, 'visit_create_table', "^\s*CREATE TABLE", "CREATE TABLE IF NOT EXISTS"),
(CreateIndex, 'visit_create_index', "^\s*CREATE INDEX", "CREATE INDEX IF NOT EXISTS"),
@eirnym
eirnym / metadata.py
Created Apr 11, 2015
SQLAlchemy dump SQL and metadata create_all and drop_all usage example. This is highly usable with aiopg and similar library where synchronised version of engine is not applicable.
View metadata.py
from sqlalchemy_dump import dump_sql
def create_all_sql(metadata):
return dump_sql(metadata.create_all, bind=True)()
def drop_all_sql(metadata):
return dumpsql(metadata.drop_all, bind=True)()
@eirnym
eirnym / representable_base.py
Last active Aug 29, 2015 — forked from exhuma/representable_base.py
this representable base adds generatable __str__ and __repr__
View representable_base.py
# based on: https://gist.github.com/exhuma/5935162#file-representable_base-py
class RepresentableBase(object):
""" Add automatic __repr__ and __str__ to SQLAlchemy ORM models
"""
def _repr_worker(self, attribute):
mapper = object_mapper(self)
items = [(p.key, getattr(self, p.key))
for p in (
mapper.get_property_by_column(c)
@eirnym
eirnym / PreferencesManager.java
Created Apr 2, 2015
Wrapper class around SharedPreferences
View PreferencesManager.java
/*
* Copyright (c) 2015, Arseny Nasokin
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.