Skip to content

Instantly share code, notes, and snippets.

View sveetch's full-sized avatar
🥝
I'm a kiwi

David THENON sveetch

🥝
I'm a kiwi
View GitHub Profile
@sveetch
sveetch / smart_image_format.py
Last active February 27, 2020 01:58
Class mixin and template tags samples to implement naive image smart format detection
class SmartFormatMixin(object):
"""
A mixin to inherit from a model so it will have a common helper
methods to manage image formats.
"""
def media_format(self, mediafile):
"""
Common method to perform a naive check about image format using file
extension.
@sveetch
sveetch / parsing-foundation-breakpoint.py
Created June 30, 2019 00:16
Attempt to parse foundation breakpoints to compare them in pixels
"""
Attempt to parse breakpoints to compare them in pixels
"""
from collections import OrderedDict
base_font_size = 16
base_font_unit = "px"
@sveetch
sveetch / i18n.py
Last active June 30, 2019 00:11
Smart templatetag with translation and context driven from settings (save from an attempt on Richie)
"""
i18n utilities for our search app
"""
from django.conf import settings
def get_best_field_language(multilingual_field, best_language):
"""
Pick the best available language from a multilingual field.
@sveetch
sveetch / sass-inclusion.css
Last active June 30, 2019 00:14
Some demo with placeholder, extend and mixins
/*
* Placeholder is not able to reference parent selector name like
* '&__something' but does not write anything if no selector extends it
*/
.bar, .foo {
color: red;
font-size: 1rem;
}
.title.bar, .title.foo {
content: ">";
@sveetch
sveetch / app.js
Created February 13, 2018 11:05
Hack on Foundation 6.4.x responsive navigation drilldown to open item for current page
$(function($) {
/*
* Initialize Foundation
*/
$(document).foundation();
/*
* Trick to automatically open drilldown menu directly on the current page panel.
* This is recursive, due to drilldown mechanics, it needs to open all sub menu
* to reach item.
@sveetch
sveetch / colors.py
Last active February 1, 2018 00:20
Given a string of Sass color variables, output Sass variables for palette, color scheme models for Sveetoy and a Python list of available color names
# -*- coding: utf-8 -*-
"""
Given a string of Sass color variables, output Sass variables for palette,
color scheme models and Python list
"""
import io
COLORS_STRING = u"""
$black: #000000;
$white: #ffffff;
@sveetch
sveetch / check.py
Created January 26, 2018 13:34
Simple backup process with tar
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
A simple script to check about sources paths contained in a
listing file.
Listing file contains a path on each line, path should be absolute and will
be checked with os.path.exists.
Once finished, script will output first the validated file path list then
@sveetch
sveetch / _content-revealer.scss
Created August 25, 2017 23:38
Content reveal jQuery plugin
/*
* Content to reveal on click with 'content-revealer' plugin
*/
.content-to-reveal{
display: none;
}
@sveetch
sveetch / html_listing.py
Created August 23, 2017 14:23
Batch image optimisation, resizing for thumb and html listing
# -*- coding: utf-8 -*-
import os, io
# Some HTML template to produce for Django to list images
ALBUM_TPL = u"""<div class="item">
<img src="{{% static 'images/album/{thumb}' %}}"
alt="{name}">
</div>
"""
@sveetch
sveetch / _spinner.scss
Created August 23, 2017 09:53
Sass spinner mixin sample
/*
* Pure CSS spinner, taken from:
* https://stephanwagner.me/only-css-loading-spinner
*
* You may also see:
* https://github.com/loadingio/loading.css
*/
@keyframes spinner {
to {transform: rotate(360deg);}
}