Skip to content

Instantly share code, notes, and snippets.

@remy
remy / gist:350433
Created March 31, 2010 14:58
Storage polyfill
if (typeof window.localStorage == 'undefined' || typeof window.sessionStorage == 'undefined') (function () {
var Storage = function (type) {
function createCookie(name, value, days) {
var date, expires;
if (days) {
date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
expires = "; expires="+date.toGMTString();
@sleekslush
sleekslush / gist:1667396
Created January 24, 2012 02:23
Adding request user to a form save
class MyView(CreateView):
model = Team
def form_valid(self, form):
self.object = form.save(commit=False)
self.object.user = self.request.user
self.object.save()
return FormMixin.form_valid(self, form)
@kevin-smets
kevin-smets / iterm2-solarized.md
Last active May 3, 2024 12:59
iTerm2 + Oh My Zsh + Solarized color scheme + Source Code Pro Powerline + Font Awesome + [Powerlevel10k] - (macOS)

Default

Default

Powerlevel10k

Powerlevel10k

@s4553711
s4553711 / gist:9488399
Created March 11, 2014 15:41
Some example for subprocess.Popen exception example
#!/usr/bin/python
import subprocess
import os
import sys
#res = subprocess.Popen(['ls','-al','/ahome'],stdout=subprocess.PIPE,stderr=subprocess.PIPE);
#output,error = res.communicate()
#if res.returncode:
# #raise Exception(error)
@staltz
staltz / introrx.md
Last active May 3, 2024 13:00
The introduction to Reactive Programming you've been missing
@jhusain
jhusain / gist:4b14f5069f3a254cfa0a
Created April 19, 2015 16:27
Converting event to Observable
function fromEvent(dom, eventName) {
return {
forEach: function(observer) {
var handler = (e) => {
observer.onNext(e);
};
dom.addEventListener(eventName, handler);
// Subscription
return {
@kwmiebach
kwmiebach / pytest.md
Last active April 28, 2024 22:34 — forked from amatellanes/pytest.sh
pytest cheat sheet

Usage

(Create a symlink pytest for py.test)

pytest [options] [file_or_dir] [file_or_dir] ...

Help:

@mjsisley
mjsisley / *.html
Last active July 24, 2019 05:49
Webpack Config for Cookiecutter Django
...
{% block css %}
...
{% if not debug %}
<!-- Currently, the css is included as part of javascript in development-->
<!-- This includes the built css for production (I am currently using Grunt for this) -->
<!-- If ExtractTextPlugin is configured properly, Webpack can handle separate css in development and production -->
@ursuad
ursuad / kafka-cheat-sheet.md
Last active March 14, 2024 10:32
Quick command reference for Apache Kafka

Kafka Topics

List existing topics

bin/kafka-topics.sh --zookeeper localhost:2181 --list

Describe a topic

bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic mytopic

Purge a topic

bin/kafka-topics.sh --zookeeper localhost:2181 --alter --topic mytopic --config retention.ms=1000

... wait a minute ...

@evansde77
evansde77 / mock_requests.py
Last active January 31, 2024 08:49
Example of mocking requests calls
#!/usr/bin/env python
"""
mocking requests calls
"""
import mock
import unittest
import requests
from requests.exceptions import HTTPError