Skip to content

Instantly share code, notes, and snippets.

View bananu7's full-sized avatar
🏍️

Bartek Banachewicz bananu7

🏍️
View GitHub Profile
@bananu7
bananu7 / blackwidow.py
Created January 31, 2021 13:17
The fixed blackwidow.py script
#!/usr/bin/python
"""This is a patched version of Sergey's code form
https://superuser.com/a/474595/8647
It worked for my Razer BlackWidow 2013 Mechanical Gaming Keyboard
(Model Number: RZ03-0039).
"""
import usb

When presented with such a problem, it helps to break it down into smaller sub-problems first to solve individually, before composing together into the solution. While it's technically quite possible to write it as one function, it can help in understanding the issue and implementation and ultimately yield cleaner code.

We know that we have to write a program that:

  • Reads the data for two rectangles,
  • Computes the common area,
  • Prints it out.

Reading the data is actually often more complex than writing it in programming. This is because the data is often coming in a different format than what we need it for our purposes. In this case, the rectangle data is gonna arrive as characters on standard input (presumably separated by whitespace), and those characters will encode the x,y, w and h of two rectangles. For our purposes, it's best to have them stored as numbers in memory, so we need to parse the input, converting into our format.

@bananu7
bananu7 / help.xml
Last active September 2, 2020 13:20
Routing.xml file for OsmAnd for adventure bike purposes
<!-- HELP INFORMATION ABOUT FILE -->
<!--
If you want to tweak the routing engine, read this carefully.
Deploying your own routing.xml
==============================
When you finish editing this document (or want to test on your Android device), copy this file over to your device.
@bananu7
bananu7 / button.c++
Created March 21, 2019 17:53
A simple snippet for button press filtering
template<int pin>
class Button {
bool state = false;
int presses;
public:
int poll() {
int result = presses > 0;
presses = 0;
return result;
}
function love.load()
snake = {}
snake.segments = { {x = 10, y = 10 } }
snake.len = 1
snake.dx = 1
snake.dy = 0
apple = { x = 5, y = 5 }
gridsize = { x = 20, y = 20 }
data Tree =
NodeLeaf Int |
NodeA Tree |
NodeB Tree
processTree :: Tree -> IO ()
processTree (NodeLeaf a) = putStr . show $ a
processTree (NodeA t) = putStr "a-" >> processTree t
processTree (NodeB t) = putStr "b-" >> processTree t
#pragma once
template<int P0, int P1, int P2>
struct MultiplexLatcherPins {
static constexpr auto p0 = P0;
static constexpr auto p1 = P1;
static constexpr auto p2 = P2;
};
template<int deviceNumber, MultiplexLatcherPins pins>

Meta-Programming

  • Towards a fully-reflective meta-programming language (G. Neverov, P. Roe)
  • D-Expressions: Lisp Power, Dylan Style (J. Bachrach, K. Playford)
  • The Java Syntactic Extender (J. Bachrach, K. Playford)
  • Template Meta-Programming for Haskell (T. Sheard, S.P. Jones)
  • First-class macros have types (A. Bawden)
  • Macros that work (W. Clinger, J. Rees)
  • Macros as multi-stage computations: type-safe, generative, binding macros in MacroML (S.E. Ganz, A. Sabry, W. Taha)
  • Hygienic macro expansion (E. Kohlbecker, D. Friedman, M. felleisen, B. Duba)
  • Compile-time meta-programming in a dynamically typed OO language (L. Tratt)
package com.company;
abstract class A {
public abstract void hello();
}
abstract class B extends A {
}
class C extends B {
@bananu7
bananu7 / log.txt
Created January 7, 2016 19:24
Build log for a problematic CircleCI container
Using a sandbox located at /home/ubuntu/Hate/.cabal-sandbox
/opt/alex/3.1.3/bin/alex --version
/usr/bin/gcc -dumpversion
/opt/ghc/7.10.2/bin/haddock --version
/opt/happy/1.19.3/bin/happy --version
/opt/ghc/7.10.2/bin/hpc version
looking for tool hsc2hs near compiler in /opt/ghc/7.10.2/bin
found hsc2hs in /opt/ghc/7.10.2/bin/hsc2hs
/opt/ghc/7.10.2/bin/hsc2hs --version
/opt/ghc/7.10.2/bin/ghc -c /tmp/1804289383846930886.c -o /tmp/16816927771714636915.o