Skip to content

Instantly share code, notes, and snippets.

Tomasz Wesołowski Kos

Block or report user

Report or block Kos

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@Kos
Kos / life.py
Created Nov 28, 2018
Game of Life
View life.py
import numpy as np
from scipy.signal import convolve2d
def get_neighbour_counts(array):
kernel = np.array([[1, 1, 1], [1, 0, 1], [1, 1, 1]], dtype=int)
return convolve2d(array, kernel, mode="same", boundary="wrap")
def get_next_state(state, neighbours):
@Kos
Kos / Django Rest Framework serializer tips.ipynb
Created Apr 23, 2018
Django Rest Framework serializer tips
View Django Rest Framework serializer tips.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Kos
Kos / 01_backend.py
Created Nov 22, 2014
Dajaxice replacement idea
View 01_backend.py
from rest_framework.decorators import api_view
from rest_framework.response import Response
import ajaxmelt
@ajaxmelt.register('POST')
@api_view
@login_required
def edit_name(request):
campaign = get_object_or_404(Campaign.objects.visible_to(request.user), id=campaign_id)
View How do I represent a world and dynamic objects in a C++ console game?
1) First thing I'd do would be to disconnect all the graphics rendering code from your World and Entity; it's going to be complicated enough without them :-)
2) I don't like that an Entity remember its index into the world. Let's revisit a typical roguelike data model:
> a World or a Level has a tilemap (floor, walls, or generally - a tight "grid" of walkable and non walkable scenery) and in addition - a number of entities, where every entity stays on one place in the grid.
You can have zero or more entities in the same slot - a goblin can stand over a pile of items, for instance.
3) Now let's think about the processes that happen. There are processes like movement, attack or picking things up. Let's take movement.
@Kos
Kos / UglifyJSCompressor.py
Created Feb 28, 2014
Source maps with Django Compressor
View UglifyJSCompressor.py
import os
import shutil
import subprocess
import tempfile
import uuid
from compressor import base
from compressor.conf import settings as compressor_settings
from compressor.js import JsCompressor
from django.conf import settings
from django.core.files import File
@Kos
Kos / formats.txt
Last active Jun 25, 2019
OpenGL image formats along with their unsized variants and preferred formats for pixel transfer (Written by hand, needs verification) Pixel store for compressed textures not provided because there are glCompressedTexImage and family for them. EXT_texture_compression_s3tc formats not included.
View formats.txt
| Image format (sized) | Unsized | Compr | Pixel format | Pixel type |
|---------------------------------------|--------------------|-------|--------------------|-----------------------------------|
| GL_R8 | GL_RED | False | GL_RED | GL_UNSIGNED_BYTE |
| GL_R8_SNORM | GL_RED | False | GL_RED | GL_BYTE |
| GL_R16 | GL_RED | False | GL_RED | GL_UNSIGNED_SHORT |
| GL_R16_SNORM | GL_RED | False | GL_RED | GL_SHORT |
| GL_R32F | GL_RED | False | GL_RED | GL_FLOAT |
| GL_R8I | GL_RED | False | GL_RED_INTEGER | GL_INT |
@Kos
Kos / closures.js
Created Jan 18, 2013
This snippet is a piece of trivia that illustrates some behaviour of closures in JS. Remember: With great power comes great responsibility! For details, see my blog post: http://kos.gd/2013/01/closures-the-cute-pets-that-bite/
View closures.js
// This snippet is a piece of trivia that illustrates some behaviour of closures in JS.
// Remember: With great power comes great responsibility!
// For details, see my blog post:
// http://kos.gd/2013/01/closures-the-cute-pets-that-bite/
// Setup
if (typeof(print) === 'undefined') print = console.log.bind(console);
// For starters:
// Here's a function that calculates a sum of every N-th element of a given array.
@Kos
Kos / shaderlines.py
Created Jan 15, 2013
This module shows... a) how GLSL error locations are presented depending on how the shader source is passed (one string vs array of strings), b) whether a single token can spread across several source strings.
View shaderlines.py
'''
This module shows...
a) how GLSL error locations are presented depending on how the shader source is passed
(one string vs array of strings),
b) whether a single token can spread across several source strings.
'''
import ctypes
from OpenGL import GL
@Kos
Kos / slicing.py
Created Jan 6, 2013
Slicing gotchas in Python 2
View slicing.py
# Some setup...
import sys
def throws(msg, f):
try:
f()
except Exception, e:
return msg in str(e)
else:
@Kos
Kos / gist:4442668
Created Jan 3, 2013
How to make your coworkers angry: Decorators. (Who likes nested functions?)
View gist:4442668
import operator
commands = {}
@operator.attrgetter('__get__')
def command(name, func):
commands[name] = func
return func
You can’t perform that action at this time.