Skip to content

Instantly share code, notes, and snippets.

View bieli's full-sized avatar

Marcin Bielak bieli

View GitHub Profile
@sroebuck
sroebuck / ScalaWebFrameworkReview.md
Created January 15, 2011 22:15
Scala Web Framework Review

Scala suited web frameworks

Overview

In general these frameworks provide functionality that covers one or more of the following:

  • Routing: A mechanism for taking HTTP requests and routing them to some code that handles them and returns a response.
@zeffii
zeffii / pygments deal with escape.py
Created September 29, 2012 13:48
dirty string literal escape in pygments
"""
BEGIN GPL LICENSE BLOCK
(c) Dealga McArdle 2012 / blenderscripting.blogspot / digitalaphasia.com
This program is free software; you may redistribute it, and/or
modify it, under the terms of the GNU General Public License
as published by the Free Software Foundation - either version 2
of the License, or (at your option) any later version.
@karlseguin
karlseguin / fakeresponse.go
Created March 10, 2013 12:51
A fake http.ResponseWriter class, used for testing. See http://openmymind.net/Testing-In-Go/
package fakeresponse
import (
"testing"
"net/http"
)
type FakeResponse struct {
t *testing.T
headers http.Header
@neilalbrock
neilalbrock / couchbase_sessions.py
Last active December 11, 2018 10:39
Flask Server-side Sessions with Couchbase. Adapted from http://flask.pocoo.org/snippets/75/
# -*- coding: utf-8 -*-
from uuid import uuid4
from datetime import timedelta
from couchbase import Couchbase
from couchbase import FMT_PICKLE
from couchbase.exceptions import NotFoundError
@delimitry
delimitry / compiled_file_python_version.py
Last active May 20, 2024 04:22
Get the version of Python by which the file was compiled
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
A script to get the version of Python by which the file was compiled
"""
from __future__ import print_function
import binascii
import os
@pathikrit
pathikrit / SudokuSolver.scala
Last active April 12, 2024 15:00
Sudoku Solver in Scala
val n = 9
val s = Math.sqrt(n).toInt
type Board = IndexedSeq[IndexedSeq[Int]]
def solve(board: Board, cell: Int = 0): Option[Board] = (cell%n, cell/n) match {
case (r, `n`) => Some(board)
case (r, c) if board(r)(c) > 0 => solve(board, cell + 1)
case (r, c) =>
def guess(x: Int) = solve(board.updated(r, board(r).updated(c, x)), cell + 1)
val used = board.indices.flatMap(i => Seq(board(r)(i), board(i)(c), board(s*(r/s) + i/s)(s*(c/s) + i%s)))
@WayneSan
WayneSan / authentication.py
Last active January 7, 2024 20:34
PyJWT + Django REST framework 2
import jwt
from django.conf import settings
from django.contrib.auth.models import User
from rest_framework import exceptions
from rest_framework.authentication import TokenAuthentication
class JSONWebTokenAuthentication(TokenAuthentication):
@sgillies
sgillies / benchmark.py
Last active February 7, 2019 01:02
GeoJSON: json vs msgpack vs shapely.wkb vs geobuf
# Comparing serialization of complex GeoJSON geometries using:
#
# - standard lib json, marshal, pickle, cPickle
# - umsgpack
# - shapely.wkb
# - geobuf (protobuf)
#
# The test case is a nearly circular polygon with 128 vertices.
#
# Python 2.7 because geobuf isn't possible on Python 3 (because
@nimasmi
nimasmi / import_export_views.py
Last active November 4, 2022 16:28
Django Import Export admin functionality in a Class Based View
from django.views.generic import FormView
from django.utils.translation import ugettext_lazy as _
from django.contrib import messages
from import_export.formats import base_formats
from import_export.forms import ImportForm, ConfirmImportForm
from import_export.resources import modelresource_factory
from django.http import HttpResponseRedirect
from import_export.tmp_storages import TempFolderStorage
try:
#include "thsq.h"
#include "ti-lib.h"
/*---------------------------------------------------------------------------*/
/*
* Thingsquare lighting switch with slider.
*
* This client uses a linear potentiometer to set the dim level of the lights
* in the network. To save power, we only power the potentiometer when we will
* sample it, and we only send light control if it has moved enough.
*