Skip to content

Instantly share code, notes, and snippets.

View bmihelac's full-sized avatar

Bojan Mihelac bmihelac

View GitHub Profile
@bmihelac
bmihelac / wagtail_struct_block_validation.py
Created January 5, 2017 15:28
Example validating wagtail StructBlock
from django.core.exceptions import ValidationError
from django.forms.utils import ErrorList
from wagtail.wagtailcore import blocks
class MyLinkBlock(blocks.StructBlock):
"""
Example validating StructBlock.
"""
@sebmarkbage
sebmarkbage / Enhance.js
Last active January 31, 2024 18:33
Higher-order Components
import { Component } from "React";
export var Enhance = ComposedComponent => class extends Component {
constructor() {
this.state = { data: null };
}
componentDidMount() {
this.setState({ data: 'Hello' });
}
render() {
@nicolasembleton
nicolasembleton / restart_bluetooth.sh
Last active October 21, 2022 20:10
Restart Bluetooth Daemon on Mac OS X without restarting
#!/bin/bash
sudo kextunload -b com.apple.iokit.BroadcomBluetoothHostControllerUSBTransport
sudo kextload -b com.apple.iokit.BroadcomBluetoothHostControllerUSBTransport
@bmihelac
bmihelac / html_components-panel.html
Created September 17, 2014 13:15
Inclusion template tag with block.
<div class="panel {{ class_name }}">
<div class="panel-heading">
<h3 class="panel-title">{{ title }}</h3>
</div>
<div class="panel-body">
{{ content }}
</div>
</div>
@sebmarkbage
sebmarkbage / JSXSpreadAttributes.md
Last active August 13, 2020 15:18
JSX Spread Attributes

JSX Spread Attributes

If you know all the properties that you want to place on a component a head of time, it is easy to use JSX:

  var component = <Component foo={x} bar={y} />;

Mutating Props is Bad, mkay

@mlouro
mlouro / gulpfile.js
Last active June 21, 2022 23:20
gulpfile.js with browserify, jshint, libsass, browserSync for livereload, image optimization and system notifications on errors
'use strict';
var gulp = require('gulp');
var gutil = require('gulp-util');
var del = require('del');
var uglify = require('gulp-uglify');
var gulpif = require('gulp-if');
var exec = require('child_process').exec;
var notify = require('gulp-notify');
@petehunt
petehunt / React sortable
Created December 9, 2013 22:30
Here's an example of React + jQuery UI sortable. The key thing to note is that we have the render() method do absolutely nothing and use componentDidUpdate() + React.renderComponent() to proxy updates through to the children. This lets us manage the DOM manually but still be able to use all the React goodies you know and love.
<html>
<head>
<title>Test</title>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://fb.me/react-0.5.1.js"></script>
<script src="http://fb.me/JSXTransformer-0.5.1.js"></script>
</head>
@bmihelac
bmihelac / gist:6193333
Created August 9, 2013 12:43
Alias to watch and recompile less files on change, printing errors. Requires watchr.
alias watchless='watchr -e '\''require "date"; watch("(.*)\.less$") { |f| cmd = "lessc #{f[0]} --source-map #{f[1]}.css"; puts "#{DateTime.now}: #{cmd}"; output = `#{cmd}`; if $? != 0 then puts output end }'\'''
@bmihelac
bmihelac / processors.py
Last active December 15, 2015 19:18
easy-thumbnails watermark to right bottom corner of the image
# custom/processors.py
from django.conf import settings
from django.core.files.storage import default_storage
try:
from PIL import Image
except ImportError:
import Image
@nmariz
nmariz / singleton.py
Created October 15, 2012 11:20
Python Singleton Metaclass
class Singleton(type):
instance = None
def __call__(cls, *args, **kwargs):
if cls.instance is None:
cls.instance = super(Singleton, cls).__call__(*args, **kwargs)
return cls.instance
if __name__ == '__main__':