Skip to content

Instantly share code, notes, and snippets.

@ralfstx
ralfstx / react-context.js
Last active February 21, 2021 13:49
Example of a React app with complex state.
/* eslint-disable no-console */
import React, { createContext, useContext, useMemo, useReducer } from 'react';
import ReactDOM from 'react-dom';
// Example of a React app with complex state.
// Use separate context to avoid unnecessary renders.
// ## ContextProvider
const FooContext = createContext();
@ralfstx
ralfstx / asciitable
Created December 18, 2020 10:50
Python script to print an ASCII table to the console
#!/usr/bin/python3
header="DEC HEX CHR"
spacer=" " * 5
def row(i):
return f"{i:3} {i:02x} {chr(i)} "
if __name__ == "__main__":
print(spacer.join((header for _ in range(6))))
@ralfstx
ralfstx / README.md
Created October 8, 2020 07:19
Python cProfile to CSV function
@ralfstx
ralfstx / README.md
Created May 10, 2020 10:48
Cross-compiling for ARM with musl

Cross-compiling for ARM with musl

I'm using the target arm-linux-musleabihf for ARM v6 (Raspberry Zero is v6) with musl and hard float.

Build a cross compiler

Following instructions from Rust (and C) Cross Compilation for the Raspberry Pi.

Create an output directory:

@ralfstx
ralfstx / CollectionView_1.js
Created May 3, 2017 11:03
Tabris 1.x compatible CollectionView
const tabris = require('tabris');
/**
* Tabris 1.x compatible CollectionView
* Does not include compatibility for events
*/
class CollectionView_1 extends tabris.CollectionView {
constructor(properties) {
super(properties);
@ralfstx
ralfstx / Picker_1.js
Created May 3, 2017 11:02
Tabris 1.x compatible Picker
const tabris = require('tabris');
/**
* Tabris 1.x compatible Picker
* Does not include compatibility for events
*/
class Picker_1 extends tabris.Picker {
constructor(properties) {
super(Object.assign({
@ralfstx
ralfstx / ArrayVsListBenchmark
Created April 14, 2014 12:07
ArrayVsListBenchmark
/*******************************************************************************
* Copyright (c) 2014 EclipseSource.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Ralf Sternberg - initial implementation and API
******************************************************************************/
@ralfstx
ralfstx / UITestPhaseListener.java
Created June 16, 2013 11:41
A phase listener for RAP to create additional DOM attributes for UI tests.
/*******************************************************************************
* Copyright (c) 2013 EclipseSource.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Ralf Sternberg - initial API and implementation
******************************************************************************/
@ralfstx
ralfstx / bless.sh
Created June 18, 2012 20:42
Tool to turn eclipse directories into p2 repositories
#!/bin/bash
#
# Tool to turn eclipse directories into p2 repositories
USAGE="Usage:
`basename "$0"` <repo-dir> [options]
Options:
--name <repo name>
the repository name
--eclipse <eclipse install dir>
@ralfstx
ralfstx / fullscreen
Created June 8, 2012 13:32
A shell script to set windows to fullscreen
#!/bin/bash
mode=
window=
usage() {
echo "Usage: $0 [on|off|toggle] [window]"
echo " default is to toggle fullscreen mode"
echo " window is a string contained in the window's title"
exit