Skip to content

Instantly share code, notes, and snippets.

View tristansokol's full-sized avatar

Tristan Sokol tristansokol

View GitHub Profile
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
await page.screenshot({path: 'example.png'});
await browser.close();
})();
@tristansokol
tristansokol / fashion-mnist-to-array.js
Created July 12, 2018 02:25
Created more easily accessible json objects from the fashion MINST data set.
const fs = require('fs');
/**
* Adapted from https://github.com/ApelSYN/mnist_dl/blob/master/lib/digitsLoader.js
* Reads a file and resolves an array of data
* @param {string} labelFileName
* @return {promise}
*/
function digitsLoader(labelFileName) {
return new Promise(function(resolve, reject) {
var SquareConnect = require('square-connect');
SquareConnect.ApiClient.instance.authentications['oauth2'].accessToken = 'sq0atp-XXXX';
var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database('./database.db');
var apiInstance = new SquareConnect.CustomersApi();
var today = new Date();
body = {
'limit': 1000,
'query': {
'filter': {
'updated_at': {
'start_at': yesterday.toISOString(),
'end_at': today.toISOString(),
},
},
},
var apiInstance = new SquareConnect.CustomersApi();
db.each("SELECT * FROM Customers WHERE ...", function (err, row) {
apiInstance.createCustomer({
given_name:row.given_name,
family_name:row.family_name,
email_address:row.email_address
}).then(function (data) {
console.log('API called successfully. Returned data: ' + data);
}, function (error) {
var apiInstance = new SquareConnect.CustomersApi();
var opts = {};
apiInstance.listCustomers(opts).then(function(data) {
var now = new Date();
data.customers.forEach(function(element) {
db.run('INSERT into Customers (id , created_at , updated_at , synced_at ,given_name , family_name , email_address , creation_source ) VALUES( $id, $created_at, $updated_at, $synced_at, $given_name, $family_name , $email_address , $creation_source )', {
$id: element.id, $created_at: element.created_at, $updated_at: element.updated_at, $synced_at: now.toISOString(), $given_name: element.given_name, $family_name: element.family_name, $email_address: element.email_address, $creation_source: 'Square:'+element.creation_source,
});
var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database('./database.db');
db.run("CREATE TABLE customers (id TEXT, created_at TEXT, updated_at TEXT, synced_at TEXT,given_name TEXT, family_name TEXT, email_address TEXT, creation_source TEXT)");
{
"projectName": "square-connect",
"projectVersion": "2.8.0",
"projectDescription": "JavaScript client library for the Square Connect v2 API",
"projectLicenseName": "Apache-2.0",
"moduleName": "SquareConnect",
"usePromises": true,
"licenseName": "Apache 2.0"
}
<?php
{{#models}}
{{#model}}
/**
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen
* Do not edit the class manually.
*/
namespace {{modelPackage}};
@tristansokol
tristansokol / linear-regression-tensorflow.html
Created June 30, 2018 03:53
linear regression with tensorflow
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@0.11.7"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.bundle.min.js"></script>
<div style="width:400px;">
<canvas id="myChart" width="400" height="400"></canvas>
</div>
<button onclick="train()">Train the model 1 step</button>
<script>
const trainX = [
3.3,