Skip to content

Instantly share code, notes, and snippets.

var Col = require('react-bootstrap/lib/Col')
var PageHeader = require('react-bootstrap/lib/PageHeader')
var React = require('react')
var Row = require('react-bootstrap/lib/Row')
var {connect} = require('react-redux')
var {reduxForm} = require('redux-form')
var DateInput = require('./DateInput')
var FormField = require('./FormField')
var LoadingButton = require('./LoadingButton')
@miohtama
miohtama / rollingwindow.py
Last active January 15, 2022 21:20
Rolling window rate limitation implementation for Pyramid
"""Rolling time window counter and rate limit using Redis.
Use Redis sorted sets to do a rolling time window counters and limiters. These are useful for preventing denial of service, flood and reputation attack against site elements which trigegr outgoing action (email, SMS).
Example how to do a Colander validator which checks that the form has not been submitted too many times within the time period::
import colander as s
@c.deferred
def throttle_invites_validator(node, kw):
@paulirish
paulirish / what-forces-layout.md
Last active May 8, 2025 05:49
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
@mbirtwell
mbirtwell / gist:aaccdb7972e1a7ed094b
Last active December 21, 2017 17:53
SQLAlchemy Enum recipe enhanced for use in postgresql arrays
# Based on http://techspot.zzzeek.org/2011/01/14/the-enum-recipe/
import six
from sqlalchemy.dialects import postgresql
from sqlalchemy.types import SchemaType, TypeDecorator, Enum
from sqlalchemy import __version__, text, cast
import re
if __version__ < '0.6.5':
raise NotImplementedError("Version 0.6.5 or higher of SQLAlchemy is required.")
@stami
stami / csv-to-xlsx.sh
Last active March 4, 2021 04:03
Bash Unoconv Libreoffice CSV-to-Excel converter
#!/bin/bash
# Huikee CSV-to-XLSX konvertteri by Samuli
# Versio 2.0, using unoconv
# Unicode now works
root_dir=$(pwd)
FOLDERS=$(find $root_dir -type d)
for fol in $FOLDERS
@glombard
glombard / reference-markdown-metadata-from-jinja-template.py
Last active March 28, 2025 20:52
How to use Markdown as a filter in a Jinja2 template, and then extract the Markdown Meta property directly from the template. Assuming you want to use the Meta-data value before rendering the converted Markdown content (e.g. in the html head), the trick is to render the markdown first, save it to a variable (html_content in this example) using a…
from pprint import pprint
import jinja2
import markdown
HTML_TEMPLATE = """{% macro get_html() %}
{{ content | markdown }}
{% endmacro %}
{% set html_content = get_html() %}
Title from Markdown meta-data: {{ get_title() }}
@kohyama
kohyama / README.md
Last active March 3, 2018 20:44
Example to operate DOM in ClojureScript via Browser REPL
@kohyama
kohyama / README.md
Last active February 6, 2021 12:41
A minimum setting to use browser REPL of ClojureScript

A minimum setting to use browser REPL of ClojureScript

Assumed that you have set leiningen up and can use it.

1. Prepare files

Copy project.clj, repl-test.cljs and brepl-test.html from this gist or git clone this gist and move or copy repl-test.cljs under src directory.

$ git clone https://gist.github.com/6183122.git
$ cd 6183122/
@jandudulski
jandudulski / .vimrc
Last active August 10, 2020 10:31
How to configure your editor to automatically strip trailing whitespaces and keep new line at the end of file?
if has("autocmd")
" remove trailing white spaces
autocmd BufWritePre * :%s/\s\+$//e
endif
@hrldcpr
hrldcpr / tree.md
Last active January 6, 2025 22:43
one-line tree in python

One-line Tree in Python

Using Python's built-in defaultdict we can easily define a tree data structure:

def tree(): return defaultdict(tree)

That's it!