Skip to content

Instantly share code, notes, and snippets.

@seanavery
seanavery / ch340.c
Created April 1, 2022 07:24 — forked from z4yx/ch340.c
//libusb+ch340 data transfer demo
//gcc usb.c `pkg-config libusb-1.0 --libs --cflags` -o usb
#include <errno.h>
#include <signal.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <sys/select.h>
@seanavery
seanavery / clear_notebook.sh
Last active September 4, 2020 00:57
clear all output from ipynb notebook
# https://stackoverflow.com/questions/28908319/how-to-clear-an-ipython-notebooks-output-in-all-cells-from-the-linux-terminal
jupyter nbconvert --ClearOutputPreprocessor.enabled=True --clear-output *.ipynb
@seanavery
seanavery / google_colab_keep_alive.js
Created July 21, 2020 20:51
push connect button in loop to prevent google colab session from dying
// source: https://stackoverflow.com/questions/57113226/how-to-prevent-google-colab-from-disconnecting
// author: Tanay Karve
function ConnectButton(){
console.log("Connect pushed");
document.querySelector("#top-toolbar > colab-connect-button").shadowRoot.querySelector("#connect").click()
}
setInterval(ConnectButton,60000);
@seanavery
seanavery / arm_mouse.sh
Created June 15, 2020 18:30
Slow pointer speed on ubuntu
xinput --set-prop $MOUSE_ID "Coordinate Transformation Matrix" 0.1 0 0 0 0.1 0 0 0 1
import subprocess
# grab subnet address
ps = subprocess.Popen('ifconfig', stdout=subprocess.PIPE, shell=True)
output = subprocess.check_output(('grep', 'inet'), stdin=ps.stdout)
ps.wait()
elements = output.decode('utf8').split()
broadcast_ip = elements[elements.index('broadcast') + 1]
print('broadcast_ip: {}'.format(broadcast_ip))
subnet = broadcast_ip[:-4]
import random
import time
class Simulation():
def __init__(self):
self.sigma = 2;
self.score = random.randint(1, 100)
print('### network score', self.score)
def simulate(self):
function contractExists(address adrs) internal returns (bool) {
uint length;
assembly {
length := extcodesize(adrs)
}
if (length > 0) {
return true;
} else {
return false;
}
@seanavery
seanavery / Settlement.sol
Created August 4, 2017 15:12
Atomic Swap Utility in Solidity
pragma solidity ^0.4.11;
import "./Token.sol";
contract Settlement {
bytes32 public permutationID;
address public tokenA;
address public tokenB;
mapping(address => mapping(bytes32 => uint)) public orders;
@seanavery
seanavery / ExchangeTX.sol
Created October 30, 2016 20:12
Exchange Algorithm
contract Exchange {
struct Bid {
address owner;
uint price;
uint amount;
uint date;
}
struct Ask {
function submitBid(uint _price, uint _amount) bidInMarket(_price) external returns (bool) {
Bid memory b;
b.price = _price;
b.amount = _amount;
for(uint i = 0; i < Bids.length; i++) {
if(Bids[i].price > _price) {
Bid[] memory tempBids = new Bid[](Bids.length - i);
for(uint j = i; j < Bids.length; j++) {
tempBids[j-i] = Bids[j];
}