Skip to content

Instantly share code, notes, and snippets.

View notnil's full-sized avatar

Logan Spears notnil

  • Plainsight
  • Seattle
View GitHub Profile
'use strict';
const ImageSearchAPIClient = require('azure-cognitiveservices-imagesearch');
const CognitiveServicesCredentials = require('ms-rest-azure').CognitiveServicesCredentials;
//replace this value with your valid subscription key.
let serviceKey = "ENTER YOUR KEY HERE";
//the search term for the request
let searchTerm = "sixgill shark";
class DataGenerator(tf.keras.utils.Sequence):
'Generates data for Keras'
def __init__(self, labels, batch_size=BATCH_SIZE, shuffle=True, arch=MODEL_MOBILENET_V2):
'Initialization'
self.batch_size = batch_size
self.labels = labels
self.shuffle = shuffle
self.arch = arch
self.on_epoch_end()
IMAGE_SHAPE = (224, 224, 3)
feature_extractor_url = "https://tfhub.dev/google/tf2-preview/mobilenet_v2/feature_vector/4"
image_input = tf.keras.Input(shape=IMAGE_SHAPE, name='img')
nn = hub.KerasLayer(feature_extractor_url,input_shape=IMAGE_SHAPE,trainable=True)(image_input)
outputs = []
for i in range(64):
out = layers.Dense(13, activation='softmax')(nn)
outputs.append(out)
model = tf.keras.models.Model(inputs=image_input, outputs=outputs)
model.compile(optimizer='adam', loss=["categorical_crossentropy"] * 64, loss_weights=[1.0] * 64)
IMAGE_SHAPE = (224, 224, 3)
feature_extractor_url = "https://tfhub.dev/google/tf2-preview/mobilenet_v2/feature_vector/4"
model = tf.keras.Sequential([
hub.KerasLayer(feature_extractor_url, input_shape=IMAGE_SHAPE, trainable=True),
tf.keras.layers.Dense(13, activation='softmax')
])
model.compile(optimizer='adam', loss="categorical_crossentropy")
private const int resWidth = 1600;
private const int resHeight = 1000;
public static byte[] TakeScreenshot(Camera camera)
{
RenderTexture rt = new RenderTexture(resWidth, resHeight, 24);
camera.targetTexture = rt;
Texture2D screenShot = new Texture2D(resWidth, resHeight, TextureFormat.RGB24, false);
camera.Render();
RenderTexture.active = rt;
screenShot.ReadPixels(new Rect(0, 0, resWidth, resHeight), 0, 0);
private static readonly Vector3 PositionA1 = new Vector3(-9.0f, 1.1f, 9.0f);
private static readonly Vector3 PositionH8 = new Vector3(9.0f, 1.1f, -9.0f);
private Vector3 positionForSquare(Square sq)
{
int row = (int)sq / 8;
float dx = Math.Abs(PositionA1.x - PositionH8.x);
float x = PositionA1.x + (((float)row * dx) / 7f);
int file = (int)sq % 8;
@notnil
notnil / Chess.cs
Last active July 29, 2019 03:05
Chess C#
public class Board
{
public Dictionary<Square, Piece> pieceMap;
public Board(Dictionary<Square, Piece> pieceMap)
{
this.pieceMap = new Dictionary<Square, Piece>(pieceMap);
}
public static Board Random()
{
package main
import (
"bytes"
"encoding/json"
"io"
"log"
"net/http"
"net/url"
)
require 'active_record'
class Note < ActiveRecord::Base
attr_accessible :body, :title
end
require 'sinatra'
require 'activerecord'
require './model'
set :content_type, :json
configure do
db = URI.parse(ENV['HEROKU_POSTGRESQL_COBALT_URL'] || 'postgres://localhost/mydb')
ActiveRecord::Base.establish_connection(
:adapter => db.scheme == 'postgres' ? 'postgresql' : db.scheme,