Skip to content

Instantly share code, notes, and snippets.

🙌
🙌

Loisaida Sam loisaidasam

🙌
🙌
Block or report user

Report or block loisaidasam

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@loisaidasam
loisaidasam / 1_problem.py
Last active Oct 5, 2018
Python help! How to make a static, yet dynamic, property in a base class?
View 1_problem.py
SERVICE_ID_TACO_BELL = 1
SERVICE_ID_T_MOBILE = 2
SERVICE_NAMES = {
SERVICE_ID_TACO_BELL: "Taco Bell",
SERVICE_ID_T_MOBILE: "T-Mobile",
}
class BaseService(object):
@loisaidasam
loisaidasam / required_subclass_property.py
Created Oct 1, 2018
Requiring a Python class property to be explicitly set in its subclasses
View required_subclass_property.py
# Base class
In [1]: class Foo(object):
...: @property
...: def bar(self):
...: raise NotImplementedError
...:
# Subclass 1, with property explicitly set
In [2]: class Foof(Foo):
...: bar = "taco"
@loisaidasam
loisaidasam / boolean_ordering.txt
Last active Sep 24, 2018
The truth about boolean ordering in Postgres
View boolean_ordering.txt
master=> SELECT * FROM (VALUES (1, true), (2, false), (3, null)) AS t (id,value);
id | value
----+-------
1 | t
2 | f
3 |
(3 rows)
master=> SELECT * FROM (VALUES (1, true), (2, false), (3, null)) AS t (id,value) order by value;
id | value
@loisaidasam
loisaidasam / get-all-the-emojis.sh
Created Aug 13, 2018
Get a list of ALL THE EMOJIS!
View get-all-the-emojis.sh
#!/bin/bash
# Via https://github.com/iamcal/emoji-data
# Requires jq
# https://stedolan.github.io/jq/
curl -Ss "https://raw.githubusercontent.com/iamcal/emoji-data/master/emoji.json" | jq '[.[] | .short_name]'
@loisaidasam
loisaidasam / fix.txt
Created Jul 16, 2018
Bash $PS1 dynamic hostname fix
View fix.txt
# Question:
# https://twitter.com/LoisaidaSam/status/1018897916293984256
# Answer:
# https://apple.stackexchange.com/questions/40734/why-is-my-host-name-wrong-at-the-terminal-prompt-when-connected-to-a-public-wifi/127405#127405
:) Michaels-iPhone:~$ scutil --get HostName
HostName: not set
:( 1 Michaels-iPhone:~$ sudo scutil --set HostName 'chewbacca'
Password:
@loisaidasam
loisaidasam / util_db.py
Created May 4, 2018
Neat Django admin html decorators
View util_db.py
def admin_html_link(short_description=None):
"""Neat Django admin html link decorator
Example model usage:
@util_db.admin_html_link("URL playlist")
def url_playlist_html(self):
return self.url_playlist
@loisaidasam
loisaidasam / eastern_time.py
Created Apr 25, 2018
Python: Eastern Standard Time vs. Eastern Daylight Time
View eastern_time.py
"""
https://en.wikipedia.org/wiki/Eastern_Time_Zone
"""
>>> import datetime, pytz
# 5 hour difference during Eastern Standard Time
>>> datetime.datetime(2018, 1, 25, 16, 26, tzinfo=pytz.timezone('US/Eastern')).hour
>>> 16
@loisaidasam
loisaidasam / postactivate_template
Created Apr 24, 2018
setupvirtualenv - move user into project directory upon virtualenv activation
View postactivate_template
#!/bin/bash
# This hook is sourced after this virtualenv is activated.
cd "{project_dir}"
# Helpful django aliases
alias djr='./manage.py runserver {djr_port}'
alias djt='./manage.py test'
@loisaidasam
loisaidasam / Default (OSX).sublime-keymap
Last active Mar 5, 2018
My `Key Bindings` for the `Macally MKEYE` keyboard
View Default (OSX).sublime-keymap
// ~/Library/Application Support/Sublime Text 3/Packages/User/Default (OSX).sublime-keymap
[
// Some specific shit for Macally MKEYE keyboard
// http://macally-europe.com/mkeye-0
// Command logging via:
// https://forum.sublimetext.com/t/shortcuts-not-working-ctrl-u-ctrl-etc/5929/2
// Regular find-context shift + enter:
// {
@loisaidasam
loisaidasam / USAGE.txt
Last active Feb 15, 2018
Get a dose of what those silly folks at asciiartfarts.com are up to ...
View USAGE.txt
$ ./ascii-art-farts.sh
# 2204 : DON'T FORGET AHMET AND DIVA
_ ____ ____ ___ ___ _ _ _____ _
/ \ / ___| / ___|_ _|_ _| / \ _ __| |_ | ___|_ _ _ __| |_ ___
/ _ \ \___ \| | | | | | / _ \ | '__| __| | |_ / _` | '__| __/ __|
/ ___ \ ___) | |___ | | | | / ___ \| | | |_ | _| (_| | | | |_\__ \
/_/ \_\____/ \____|___|___| /_/ \_\_| \__| |_| \__,_|_| \__|___/
,@@@@@@@@@, REPEAT:
@@@@@@@@@@@@@@@ WHAT KIND OF ASSHOLE NAMES
You can’t perform that action at this time.