Skip to content

Instantly share code, notes, and snippets.

Working from home

ayman ayman

Working from home
View GitHub Profile
ayman /
Last active Jan 25, 2022
Scan BLE packets from an Adafruit CLUE for a certain MAC address, get the advertisement data, repeat.
from adafruit_ble import BLERadio
# from adafruit_ble.advertising import Advertisement
# from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
found = set()
scan_responses = set()
running = True
count = 0
ayman /
Last active Apr 8, 2021
How to push firmware to MeloAudio MidiCommander using a Mac.
# Install brew from then install dfu-util
brew install dfu-util
# OR install dfu-util from
# then plug in and power on your device holding the D and Down buttons
# now find your device
dfu-util -l
# Verify that alt=0 is name="@Internal Flash..."
dfu-util -a 0 -D Midicommander_line6HX3x_V5.dfu
# Wait for it to should be good...
ayman / covid19-state-ratio.R
Last active Mar 31, 2020
A simple R ggplot of percent positive of covid cases by USA State.
View covid19-state-ratio.R
dataUrl <- ""
c <- read.csv(dataUrl)
c$date <- as.Date(as.character(c$date), format = "%Y%m%d")
c_tmp <- c[order(c[c$date == max(c$date), ]$total, decreasing = TRUE), ]
states <- c_tmp[c_tmp$date == max(c_tmp$date), ]$state[1:10]
c[$pending), ]$pending <- 0
c$ratio <- (c$positive / (c$total - c$pending))
c <- c[c$state %in% states, ]
g <- ggplot(c, aes(x = date, y = ratio))
ayman /
Last active Jun 8, 2021
Control a LumeCubeAir from Python via BLE + bluepy.
from bluepy import btle
import struct
class LumeCube:
def __init__(self, mac):
self.mac = mac
self.SERVICE_UUID = "33826A4C-486A-11E4-A545-022807469BF0"
self.LIGHT_CHARACTERISTIC = "33826A4D-486A-11E4-A545-022807469BF0"
self.LIGHT_ON = struct.pack('>L', 0xFCA16400)
ayman / keras-mnist.R
Last active Jun 5, 2018
An example of training MNIST in R using Keras.
View keras-mnist.R
## From:
mnist <- dataset_mnist()
x_train <- mnist$train$x
y_train <- mnist$train$y
x_test <- mnist$test$x
y_test <- mnist$test$y
## reshape
ayman / .hadoop_alias
Last active Aug 12, 2017
My friend Jake hates typing `hdfs dfs -` so he made these aliases. Enjoy!
View .hadoop_alias
alias happendToFile='hdfs dfs -appendToFile'
alias hcat='hdfs dfs -cat'
alias hchecksum='hdfs dfs -checksum'
alias hchgrp='hdfs dfs -chgrp'
alias hchmod='hdfs dfs -chmod'
alias hchown='hdfs dfs -chown'
alias hcopyFromLocal='hdfs dfs -copyFromLocal'
alias hcopyToLocal='hdfs dfs -copyToLocal'
alias hcount='hdfs dfs -count'
alias hcp='hdfs dfs -cp'
ayman /
Last active Apr 24, 2017
This is an extra annotated, commented illustration example from a Keras tutorial.
# Tutorial from:
import numpy
from keras.datasets import cifar10
from matplotlib import pyplot
from scipy.misc import toimage
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import Dropout
from keras.layers import Flatten
from keras.constraints import maxnorm
ayman /
Last active Jun 24, 2016
Simple wget script to slurp down a website for preservation.
if [[ $# -lt 2 ]] ; then
echo 'USAGE: ./'
exit 1
wget \
--recursive \
--no-clobber \
--page-requisites \
--html-extension \
ayman /
Last active Jun 9, 2016
Display a pretty status on a Raspberry Pi. I forget where I found the base script, but this has a few modifications.
## zip=94114
if [ -n "$1" ]; then
ip=`ip addr show scope global | grep inet | cut -d' ' -f6 | cut -d/ -f1 | tr "\n" " "`
oip=`wget -q -O - | tail`
ayman / ziplen.R
Last active Feb 3, 2022
Compute the distances between all US Zipcodes in R.
View ziplen.R
## Compute the distances between all US Zipcodes.
## To save time we just compute the diagonal and use multiple cores.
## Uncode for testing
## zipcode <- zipcode[1:10,]
zips.num = dim(zipcode)[1]