This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// gecko and webkit | |
// details here https://developer.mozilla.org/en-US/docs/DOM/event.initKeyEvent | |
var keyboardEvent = document.createEvent("KeyboardEvent"); | |
var initMethod = typeof keyboardEvent.initKeyboardEvent !== 'undefined' ? "initKeyboardEvent" : "initKeyEvent"; | |
keyboardEvent[initMethod]( | |
"keydown", // event type : keydown, keyup, keypress | |
true, // bubbles |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// look here for more details : https://developer.mozilla.org/en-US/docs/DOM/event.initMouseEvent | |
var mouseMoveEvent = document.createEvent("MouseEvents"); | |
mouseMoveEvent.initMouseEvent( | |
"mousemove", //event type : click, mousedown, mouseup, mouseover, mousemove, mouseout. | |
true, //canBubble | |
false, //cancelable | |
window, //event's AbstractView : should be window | |
1, // detail : Event's mouse click count |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Kudos to Grumdrig | |
// http://stackoverflow.com/questions/1207008/how-do-i-lock-the-orientation-to-portrait-mode-in-a-iphone-web-application | |
$(document).ready(function () { | |
function reorient(e) { | |
var portrait = (window.orientation % 180 == 0); | |
$("body > div").css("-webkit-transform", !portrait ? "rotate(-90deg)" : ""); | |
} | |
window.onorientationchange = reorient; | |
window.setTimeout(reorient, 0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"layer1": {"weights": [[-0.07274463772773743, -0.05483248457312584, -0.03770652413368225, -0.03742086514830589, -0.050161924213171005, -0.06178945675492287, -0.05419166386127472, -0.022179512307047844, -0.029363859444856644, -0.042349692434072495, -0.008726662024855614, 0.007980101741850376, 0.05518602579832077, 0.04311336204409599, 0.01887792907655239, -0.025796234607696533, -0.026308175176382065, -0.06663032621145248, -0.11316043138504028, -0.06160087138414383, -0.050536155700683594, -0.045753899961709976, -0.010632967576384544, 0.011841720901429653, -0.007426648400723934, -0.010910416021943092, -0.03271804749965668, -0.004095158539712429, -0.042311426252126694, -0.06080005317926407, -0.019534414634108543, 0.017563525587320328, -0.010229254141449928, -0.009893407113850117, -0.025845041498541832, -0.062347691506147385, -0.011849354021251202, -0.029188185930252075, -0.012888552621006966, 0.04048076272010803, 0.01928851194679737, 0.024348542094230652, 0.027422353625297546, 0.05658775940537453, 0.0403093323111 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function $(selector){ | |
return document.querySelector(selector); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from fastai.vision import * | |
import pandas as pd | |
import matplotlib | |
from matplotlib.gridspec import GridSpec | |
def visualize_data_bunch(db, figsize=(16,16), layoutRows=3, layoutCols=5): | |
graphRows = 4 | |
layout = { "rows": layoutRows + graphRows, "cols": layoutCols } | |
graphCols = int(layoutCols * 0.75) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://blog.thebakery.io/meteor-accounts-auth-with-passportjs/ | |
import bcrypt from 'bcrypt'; | |
import crypto from 'crypto'; | |
import express from 'express'; | |
import mongoose from 'mongoose'; | |
import passport from 'passport'; | |
import { Strategy as LocalStrategy } from 'passport-local'; | |
import { BasicStrategy } from 'passport-http'; | |
const User = mongoose.model('users', new mongoose.Schema({ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.get('/', (req, res) => { | |
// When logged in user object is attached to the request | |
if (!req.user) { | |
res.redirect('/login'); | |
return; | |
} | |
res.send(`Hello ${req.user.emails[0].address}`); | |
}); | |
app.get('/login', (req, res) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.use('/api', passport.authenticate('basic', { session: false })); | |
app.post('/api/ping', (req, res) => { | |
res.send(`pong ${req.user.emails[0].address}`); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function deserializeUserPassport(id, done) { | |
User.findOne({ _id: id }, (err, userModel) => { | |
if (err) { | |
done(err); | |
} else { | |
if (!userModel) { | |
done(); | |
return; | |
} | |
done(null, userModel.toJSON()); |
NewerOlder