Skip to content

Instantly share code, notes, and snippets.

@nephthys
nephthys / README.md
Created July 1, 2019 23:07
Mount SMB shares at the beginning of the session on macOS

nano ~/Library/LaunchAgents/com.user.loginscript.automount.plist

launchctl load ~/Library/LaunchAgents/com.user.loginscript.automount.plist

@nephthys
nephthys / fields.py
Created November 26, 2014 09:57
Disable validation on forms.MultipleChoiceField
from django.forms import MultipleChoiceField
class MultipleChoiceAnyField(MultipleChoiceField):
"""A MultipleChoiceField with no validation."""
def valid_value(self, *args, **kwargs):
return True
@nephthys
nephthys / base.html
Last active February 27, 2018 13:05
Highlight current page / app in Django
<ul class="nav navbar-nav">
<li{% if app_name == 'pages' %} class="active"{% endif %}>
<a href="{% url "page_list" %}">{% trans "Pages" %}</a>
</li>
</ul>
obj = News(is_short=form.cleaned_data['is_short'])
obj.save()
post_type = form.save(commit=False)
post_type.content_object = obj
post_type.ip = request.META['REMOTE_ADDR']
post_type.save()
version = Version(news=obj, author=request.user, ip=request.META['REMOTE_ADDR'], \
content=form.cleaned_data['content_news'], is_minor=form.cleaned_data['is_minor'], \
@nephthys
nephthys / gist:1339594
Created November 4, 2011 15:31
Truncate paragraphs in PHP
<?php
function truncate_paragraphs($text, $limit) {
preg_match_all('/<p>(.*)<\/p>/', $text, $matches);
$paragraphs = $matches[0];
if (count($paragraphs) > $limit) {
$paragraphs = array_slice($paragraphs, 0, $limit);
return implode("\n", $paragraphs);
} else {
return $text;
}