Skip to content

Instantly share code, notes, and snippets.

@sthzg
sthzg / dev.js
Last active August 10, 2016 22:06
Config w/ activated Browser Sync Plugin
'use strict';
let path = require('path');
let webpack = require('webpack');
let baseConfig = require('./base');
let defaultSettings = require('./defaults');
let BrowserSyncPlugin = require('browser-sync-webpack-plugin');
// Add needed plugins here
let BowerWebpackPlugin = require('bower-webpack-plugin');
trait ShoutoutEntityTable {
import shoutouts.utils.PgSlickDriver.api._
class Shoutouts(tag: Tag) extends Table[ShoutoutEntity](tag, "shoutouts") {
def content = column[JsValue]("content") // <- instance of MyType in the case class
// ... all the other column members
def * = (id, url, title, content, tags, created, updated) <> (create, extract)
@sthzg
sthzg / foobar.sh
Created May 17, 2015 11:12
Copy all files recursively matching -iname to directory dest.
# Copy all files recursively matching -iname to directory dest.
find ./filer_public -iname "*.jpg" -exec cp -t dest {} +
@sthzg
sthzg / templatetag.py
Last active August 29, 2015 14:19
Resolving views from other views and template tags
# e.g. in myapp/templatetags/myapp_extras.py
from __future__ import absolute_import, unicode_literals
from django import template
from patterntests.views import SomePartial
register = template.Library()
def somepartial(context):
someview = SomePartial()
res = someview.get(context.get('request'))
class MyModelTest(SimpleTestCase):
def test_something_with_some_file(self):
my_model = MyModel()
my_model.save()
# We change the storage location to save into our test directory.
my_model._meta.get_field('some_file').storage.location = '/somewhere/else'
a_file = '/whatever/is/tosave.txt'
my_model.some_file.save(
@sthzg
sthzg / MyModel.py
Last active August 29, 2015 14:18
Dynamically change storage location for Django's FileField and ImageField.
from django.core.files.storage import FileSystemStorage
def MyModel(models.Model):
# ... model stuff ...
some_file = models.FileField(
storage=FileSystemStorage(
location='/my/private/path/'
),
upload_to='downloads'
@sthzg
sthzg / MyComponent.jsx
Last active January 31, 2017 21:24
This gist shows an idea on how to expose a public api for a ReactJS component to a Non-ReactJS host page.
'use strict';
/**
* This is the actual root component that we want to either use in
* the context of a bigger ReactJS app or as a top level component used on a
* traditional Non-ReactJS host page. In the second case we want the component
* to expose a public API.
*/
var React = require('React');
@sthzg
sthzg / mptts_tree_node_multiselect_for_treebeard.py
Created October 11, 2014 12:40
Quick adaption of django-mptt's TreeNode fields for use w/ django-treebeard.
class TreeNodeChoiceFieldMixin(object):
def __init__(self, queryset, *args, **kwargs):
self.level_indicator = kwargs.pop('level_indicator', '----')
super(TreeNodeChoiceFieldMixin, self).__init__(queryset, *args, **kwargs)
def _get_level_indicator(self, obj):
level = len(obj.get_ancestors())
return mark_safe(conditional_escape(self.level_indicator) * level)
def label_from_instance(self, obj):
@sthzg
sthzg / zotonic_render_template
Last active August 29, 2015 14:05
Zotonic: Render template from controller
-module(controller_example).
-export([event/2]).
-include_lib("controller_html_helper.hrl").
html(Context) ->
Html = z_template:render("index.tpl", [{foo, 'bar'}, {bam, 1234}], Context),
z_context:output(Html, Context).