Skip to content

Instantly share code, notes, and snippets.

View dockimbel's full-sized avatar

Nenad Rakocevic dockimbel

View GitHub Profile
@dockimbel
dockimbel / comprehensions.md
Created March 27, 2016 17:43 — forked from bearfrieze/comprehensions.md
Comprehensions in Python the Jedi way

Comprehensions in Python the Jedi way

Beautiful is better than ugly. Explicit is better than implicit.

-- The Zen of Python

I frequently deal with collections of things in the programs I write. Collections of droids, jedis, planets, lightsabers, starfighters, etc. When programming in Python, these collections of things are usually represented as lists, sets and dictionaries. Oftentimes, what I want to do with collections is to transform them in various ways. Comprehensions is a powerful syntax for doing just that. I use them extensively, and it's one of the things that keep me coming back to Python. Let me show you a few examples of the incredible usefulness of comprehensions.

All of the tasks presented in the examples can be accomplished with the extensive standard library available in Python. These solutions would arguably be more terse and efficient in some cases. I don't have anything against the standard library. To me there is a certain

@dockimbel
dockimbel / red-updater.r
Last active September 28, 2016 04:05
Red-Updater-Script: This Script updates your Red Installation with the latest master-branch binaries.
Rebol [
Title: "Red-Updater-Script"
File: %red-updater.r
Author: "Neelesh Chandola, @nc-x"
Description: {
This Script updates your Red Installation with the latest master-branch binaries.
}
Instructions: {
Please update the variable `path-to-red-executable` with appropriate
location of the Red executable on your system before running the script.
@dockimbel
dockimbel / tile-game.red
Last active November 24, 2015 14:03 — forked from meijeru/tile-game.red
Red [Needs: 'view]
view/tight [
title "Tile game, by meijeru"
style piece: button 60x60 [
unless find [0x60 60x0 0x-60 -60x0] face/offset - empty/offset [exit]
temp: face/offset face/offset: empty/offset empty/offset: temp
]
piece "1" piece "2" piece "3" piece "4" return
piece "5" piece "6" piece "7" piece "8" return
@dockimbel
dockimbel / JSON-mini.red
Last active September 29, 2020 04:13 — forked from Skrylar/JSON.red
JSON minminal parser for Red
Red []
digit-nz: charset "123456789"
digit: append copy digit-nz #"0"
hex: append copy digit "abcdefABCDEF"
sign: charset "+-"
exponent-e: charset "eE"
dquot: #"^""
exponent: [ exponent-e opt sign some digit ]
@dockimbel
dockimbel / unicode.reds
Last active August 29, 2015 13:56 — forked from meijeru/unicode.reds
FIX: typo in 66536 (should be 65536)
Red/System []
utf8-to-codepoint: func [ ; yields an integer >= 0 and < 1114112, or -1
u [c-string!] ; should have length 1 to 4
/local b1 b2 b3 b4
][
either 1 = length? u
[
b1: as-integer u/1
either b1 < 128 [