Skip to content

Instantly share code, notes, and snippets.

Avatar

Philip Nuzhnyi callmephilip

View GitHub Profile
@callmephilip
callmephilip / gist:3626669
Created Sep 4, 2012
[JavaScript] Lock site in portrait mode in mobile Safari
View gist:3626669
// 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);
View network.json
{"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
@callmephilip
callmephilip / gist:3626823
Created Sep 4, 2012
[JavaScript] Poor man's jQuery
View gist:3626823
function $(selector){
return document.querySelector(selector);
}
@callmephilip
callmephilip / visualize_data_bunch.py
Created May 7, 2020
Helper for debugging FastAI image data bunches
View visualize_data_bunch.py
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)
@callmephilip
callmephilip / gist:3517765
Created Aug 29, 2012
[JavaScript] Dispatching mouse move event
View gist:3517765
// 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
@callmephilip
callmephilip / passport-meteor-accounts-server.js
Last active Mar 28, 2020
Passport.js + Meteor accounts
View passport-meteor-accounts-server.js
// 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({
View meteor-accounts-passport-step4.js
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) => {
View meteor-accounts-passport-step3.js
app.use('/api', passport.authenticate('basic', { session: false }));
app.post('/api/ping', (req, res) => {
res.send(`pong ${req.user.emails[0].address}`);
});
View meteor-accounts-passport-step1.js
function deserializeUserPassport(id, done) {
User.findOne({ _id: id }, (err, userModel) => {
if (err) {
done(err);
} else {
if (!userModel) {
done();
return;
}
done(null, userModel.toJSON());
View meteor-accounts-passport-step1.js
function comparePasswords(password, hash, callback) {
bcrypt.compare(crypto.createHash('sha256').update(password).digest('hex'), hash, callback);
}
new LocalStrategy(function getUserPassport(username, password, done) {
User.findOne({
'emails.address': username,
}, (findError, userModel) => {
if (findError) {
return done(findError);