Skip to content

Instantly share code, notes, and snippets.

View mxmzb's full-sized avatar
🍜
Probably eating

Maxim mxmzb

🍜
Probably eating
View GitHub Profile
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :recoverable, :rememberable, :trackable, #:validatable,
:omniauthable, :omniauth_providers => [:steam]
#:database_authenticatable, :registerable,
def self.from_omniauth(auth)
where(steam_id: auth.uid).first_or_create do |user|
user.steam_id = auth.uid
@mxmzb
mxmzb / bookshelftest.js
Last active August 29, 2015 14:13
Bookshelf fetchAll()
var _ = require("underscore"),
steam = require("steam"),
util = require("util"),
fs = require("fs"),
dota2 = require("dota2"),
bot = new steam.SteamClient(),
Dota2 = new dota2.Dota2Client(bot, true);
var models = require("./models");
var addPendingFriends = function() {
console.log("searching for pending friend requests...");
console.log(bot.steamID);
var bot_db = models.Bot.where({ steam_id: bot.steamID }).fetch(); // i need the model here, not a promise
new models.User().botStatusPending().fetchAll().then(function(users){
users.forEach(function(user){
console.log(bot_db.get('id'));
if(bot.friends[user.get('steam_id')] && bot.friends[user.get('steam_id')] == 2) {
console.log(bot_db);
@mxmzb
mxmzb / gist:da0e8d4bec91c9b48be3
Created April 23, 2015 17:20
Faraday exception handling
# lib/faraday/steam_api_exceptions.rb
class SteamApiExceptions < Faraday::Middleware
def call(env)
begin
@app.call(env)
raise "this will be actually entered if everything is correct"
rescue => e
raise "this should be called, shouldn't it?"
end
end
events.js:85
throw er; // Unhandled 'error' event
^
Error: Logon fail: 65
at SteamClient.handlers.(anonymous function) (/Users/dotwired/Projects/dotanaut/lib/node/dota2_bot/node_modules/steam/lib/handlers/user.js:182:11)
at SteamClient._netMsgReceived (/Users/dotwired/Projects/dotanaut/lib/node/dota2_bot/node_modules/steam/lib/steam_client.js:123:26)
at SteamClient.handlers.(anonymous function) (/Users/dotwired/Projects/dotanaut/lib/node/dota2_bot/node_modules/steam/lib/steam_client.js:209:10)
at SteamClient._netMsgReceived (/Users/dotwired/Projects/dotanaut/lib/node/dota2_bot/node_modules/steam/lib/steam_client.js:123:26)
at Connection.emit (events.js:107:17)
at Connection._readPacket (/Users/dotwired/Projects/dotanaut/lib/node/dota2_bot/node_modules/steam/lib/connection.js:50:8)
new models.User().botStatusAccepted(bot_db.get('id')).fetchAll().then(function(users){
callibration_loop(users.toArray());
}).catch(function(e) { console.error(e); });
var userCounter = 0,
callibration_loop = function(users) {
var user = users[userCounter++];
if(bot.friends[user.get('steam_id')] && bot.friends[user.get('steam_id')] == 3) {
process_user_mmr(user);
@mxmzb
mxmzb / lograge.rb
Created June 14, 2015 11:24
lograge initializer
Rails.application.configure do
config.lograge.enabled = true
# add time to lograge
config.lograge.custom_options = lambda do |event|
{ :time => event.time, :user => (user_signed_in? ? "User##{current_user.id}" : "Guest") }
end
end
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module Artspiracy
class Application < Rails::Application
@mxmzb
mxmzb / app.js
Created November 22, 2015 03:33
myapp ion-nav-view issue
// Ionic Starter App
// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
angular.module('myapp', ['ionic', 'myapp.controllers'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
@mxmzb
mxmzb / directives.js
Created December 17, 2015 12:11
slick directive
angular.module('myapp.directives', [])
.directive('slick-carousel', '$eval', function($eval) {
return {
restrict: 'A',
link: function(scope, element, attrs) {
angular.element(element).slick(scope.$eval(attrs.directiveName));
}
};
});