Skip to content

Instantly share code, notes, and snippets.

View rob-blackbourn's full-sized avatar
💭
Trying to do a proper "Hello, World!" with wasm

Rob Blackbourn rob-blackbourn

💭
Trying to do a proper "Hello, World!" with wasm
View GitHub Profile
@rob-blackbourn
rob-blackbourn / BufferExtension.md
Last active July 4, 2024 00:27
A C# linq extension to buffer an enumerable into an enumerable of enumerable blocks

Bufering in linq

static void Main()
{
    foreach (var block in "The quick brown fox jumped over the lazy dog".Split(' ').Buffer(4))
        Console.WriteLine(string.Join(" ", block));
}

The code takes the sentence "The quick brown fox jumped over the lazy dog", splits it into words, buffers it into blocks of four words, then writes each block of words joined by spaces.

@rob-blackbourn
rob-blackbourn / README.md
Last active August 29, 2015 14:22
JavaScript Property Getters and Setters

JavaScript Property Getters and Setters

The attached code shows how to create getters and setters for a JavaScript object against the object prototype.

The example shows a situation where I want to store the underlying data (an RGBA colour) as an array, but wish to allow access throough getters and setters: i.e. colour.red = 255.

Running the example produces the following result:

@rob-blackbourn
rob-blackbourn / README.md
Created June 10, 2015 15:19
Build ImageData from text art in Javascript

Overview

This code provides a simple example of how to build an ImageData object from text art that can be used in a canvas.

@rob-blackbourn
rob-blackbourn / Documents.py
Last active August 30, 2018 06:37
Create documents from meta classes
class Field:
def __init__(self, name=None, db_name=None, default=None, required=None, unique=None):
self.name = name
self.db_name = db_name
self.default = default
self.required = required
self.unique = unique
def to_mongo(self, value):
@rob-blackbourn
rob-blackbourn / graphql_json_type.py
Created September 20, 2019 07:19
A Python GraphQL JSON type for graphqlql-core-next v1.1.1
"""GraphQL JSON type"""
import json
from typing import List, Mapping, Union, Any
from graphql.type import GraphQLScalarType
from graphql.language.ast import StringValueNode
from graphql.error import INVALID
JSONType = Union[List[Mapping[str, Any]], Mapping[str, Any]]
@rob-blackbourn
rob-blackbourn / jetblack-tweeter-graphene-ex1.py
Created October 8, 2020 07:05
The twitter calls using jetblack-tweeter
import asyncio
import os
from jetblack_tweeter import Tweeter
from jetblack_tweeter.clients.bareclient import BareTweeterSession
async def main():
# Create the twitter client.
tweeter = Tweeter(
BareTweeterSession(),
@rob-blackbourn
rob-blackbourn / graphene3-demo-types.py
Created October 8, 2020 07:24
Graphhene 3 types for twitter demo
import graphene
class UserType(graphene.ObjectType):
id = graphene.types.scalars.BigInt(required=True)
id_str = graphene.String(required=True)
name = graphene.String(required=True)
screen_name = graphene.String(required=True)
location = graphene.String(required=False)
url = graphene.String(required=False)
description = graphene.String(required=False)
@rob-blackbourn
rob-blackbourn / graphene3-demo-query.py
Created October 8, 2020 07:47
Graphene 3 example query
import typing
import graphene
from jetblack_tweeter import Tweeter
from .types import SearchResultType
class Query(graphene.ObjectType):
search_tweets = graphene.Field(
SearchResultType,
@rob-blackbourn
rob-blackbourn / graphene3-demo-mutation.py
Created October 8, 2020 07:56
Graphene 3 example mutation
import typing
import graphene
from jetblack_tweeter import Tweeter
from ..types import TweetType
class UpdateStatus(graphene.Mutation):
class Arguments:
status = graphene.String()
@rob-blackbourn
rob-blackbourn / graphene3-demo-subscription.py
Last active October 8, 2020 10:19
Graphene 3 example subscription
import typing
import graphene
from jetblack_tweeter import Tweeter
from .types import TweetType
class Subscription(graphene.ObjectType):
filter = graphene.Field(
TweetType,