Skip to content

Instantly share code, notes, and snippets.

View scottlawsonbc's full-sized avatar

Scott Lawson scottlawsonbc

  • Vancouver, Canada
View GitHub Profile
@himanshurawlani
himanshurawlani / simple_cnn.py
Created March 17, 2019 13:15
Building a simple CNN using tf.keras functional API
from tensorflow import keras
# Creating a simple CNN model in keras using functional API
def create_model():
img_inputs = keras.Input(shape=IMG_SHAPE)
conv_1 = keras.layers.Conv2D(32, (3, 3), activation='relu')(img_inputs)
maxpool_1 = keras.layers.MaxPooling2D((2, 2))(conv_1)
conv_2 = keras.layers.Conv2D(64, (3, 3), activation='relu')(maxpool_1)
maxpool_2 = keras.layers.MaxPooling2D((2, 2))(conv_2)
conv_3 = keras.layers.Conv2D(64, (3, 3), activation='relu')(maxpool_2)
@mayankcpdixit
mayankcpdixit / install-kafka-mac.md
Last active April 19, 2022 02:25
Install Kafka in local (mac)

Install kafka in your local mac machine

run following commands:

brew install kafka
sudo mkdir -p /usr/local/var/run/zookeeper/data
sudo chmod 777 /usr/local/var/run/zookeeper/data
zkServer start

mkdir -p /usr/local/var/lib/kafka-logs
@GameDragon2k
GameDragon2k / ESP32_BLE_Arcade.ino
Last active February 15, 2023 08:47
NodeMCU-32S Game Pad
/*
Video: https://www.youtube.com/watch?v=oCMOYS71NIU
Based on Neil Kolban example for IDF: https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLE%20Tests/SampleNotify.cpp
Ported to Arduino ESP32 by Evandro Copercini
Gamepad coding by Game Dragon
*/
#include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEUtils.h>
@schweigert
schweigert / Embedding GoLang into a Ruby application.md
Last active May 3, 2024 19:23
Embedding GoLang into a Ruby application - Blogpost to Magrathealabs

Go Title

I am passionate about Ruby, but its execution time compared to other languages is extremely high, especially when we want to use more complex algorithms. In general, data structures in interpreted languages become incredibly slow compared to compiled languages. Some algorithms such as ´n-body´ and ´fannkuch-redux´ can be up to 30 times slower in Ruby than Go. This is one of the reasons I was interested in embedding Go code in a Ruby environment.

For those who do not know how shared libraries operate, they work in a similar way as DLLs in Windows. However, they have a native code with a direct interface to the C compiler.

Note Windows uses the DLL system, and in this case, this does not necessarily have to be in native code.

One example is DLLs written in C#, which runs on a virtual machine. Because I do not use windows, I ended up not testing if it is poss

@gbaman
gbaman / graphql_example.py
Created November 1, 2017 00:18
An example on using the Github GraphQL API with Python 3
# An example to get the remaining rate limit using the Github GraphQL API.
import requests
headers = {"Authorization": "Bearer YOUR API KEY"}
def run_query(query): # A simple function to use requests.post to make the API call. Note the json= section.
request = requests.post('https://api.github.com/graphql', json={'query': query}, headers=headers)
if request.status_code == 200:
@jakebrinkmann
jakebrinkmann / connect_psycopg2_to_pandas.py
Created July 3, 2017 14:19
Read SQL query from psycopg2 into pandas dataframe
import pandas as pd
import pandas.io.sql as sqlio
import psycopg2
conn = psycopg2.connect("host='{}' port={} dbname='{}' user={} password={}".format(host, port, dbname, username, pwd))
sql = "select count(*) from table;"
dat = sqlio.read_sql_query(sql, conn)
conn = None
@kylehounslow
kylehounslow / client.py
Last active April 23, 2024 10:58
Send and receive images using Flask, Numpy and OpenCV
from __future__ import print_function
import requests
import json
import cv2
addr = 'http://localhost:5000'
test_url = addr + '/api/test'
# prepare headers for http request
content_type = 'image/jpeg'
@wrigby
wrigby / 24bitwav.py
Created December 22, 2016 06:11
Reading a 24-bit wave file in Python
def sign_extend(bits, value):
""" Sign-extend from http://stackoverflow.com/questions/32030412/twos-complement-sign-extension-python """
sign_bit = 1 << (bits - 1)
return (value & (sign_bit - 1)) - (value & sign_bit)
def get_samples(w):
w.rewind()
num_samples = w.getnframes()
sample_depth = w.getsampwidth()
@bradmontgomery
bradmontgomery / single_dispatch_example.py
Created August 23, 2016 17:08
Example of single dispatch in python. This is seriously cool stuff.
"""
Playing with python's single dispatch.
See: https://hynek.me/articles/serialization/
See also PEP 443: https://www.python.org/dev/peps/pep-0443/
"""
from datetime import datetime
from functools import singledispatch
@fson
fson / example.js
Created March 17, 2016 15:10
Recursive GraphQL demo
import { inspect } from 'util';
import {
graphql,
GraphQLEnumType,
GraphQLID,
GraphQLInterfaceType,
GraphQLObjectType,
GraphQLList,
GraphQLNonNull,
GraphQLSchema,