Skip to content

Instantly share code, notes, and snippets.

View creativ's full-sized avatar
😎

Dmitriy Tkalich creativ

😎
View GitHub Profile
@creativ
creativ / analytics.js
Created October 2, 2014 15:17
Google analytics event tracker
// Google analytics implementation
window.Analytics = (function(ga) {
function Analytics() { }
Analytics.prototype.trackEvent = function(category, action, label, value) {
ga.apply(this, ['send', 'event'].concat(Array.prototype.slice.call(arguments)));
};
Analytics.prototype.trackPage = function(options) {
ga.apply(this, ['send', 'pageview'].concat(Array.prototype.slice.call(arguments)));
@creativ
creativ / factory_v3
Last active January 3, 2016 13:49
Simple factories
def shape_factory(type, *args, **kwargs):
if type == "Circle": return Circle(*args, **kwargs)
elif type == "Square": return Square(*args, **kwargs)
else: None
class Shape(object):
def draw(self):
raise NotImplementedError()
def erase(self):
@creativ
creativ / sign-middleware.coffee
Created September 28, 2014 08:44
Signature middleware
class App.SignMiddleware
constructor: (@gameData, callback) ->
@name = 'requestSign'
@sessionKey = null
Psycho.ajax
url: "#{@gameData.endpointUrl}user/getSessionKey"
type: 'POST'
data: @_signRequestParams { userId: @gameData.userId }
class App.Button extends createjs.Container
constructor: (buttonOptions={}) ->
defaultButtonOptions =
text: null
outlineText: null
@buttonOptions = Psycho.merge defaultButtonOptions, buttonOptions
@initialize()
@drawButton()
@creativ
creativ / bot.py
Created August 17, 2014 14:03
Cleverbot usage example
import md5
import urllib
import urllib2
import uuid
import xml.dom.minidom
"""
chatterbotapi
Copyright (C) 2011 pierredavidbelanger@gmail.com
@creativ
creativ / Makefile
Created August 6, 2014 10:52
Simple Makefile for CoffeeScript projects
COFFEEC = ./node_modules/.bin/coffee
DIST = dist
CONF = src/conf
all: build_dev build_prod
build_dev:
@$(COFFEEC) --join $(DIST)/lib-dev.js --compile src/lib.coffee $(CONF)/conf-dev.coffee
@echo 'Lib(Dev) successfully builded'
#
# Slightly tighter CORS config for nginx
#
# A modification of https://gist.github.com/1064640/ to include a white-list of URLs
#
# Despite the W3C guidance suggesting that a list of origins can be passed as part of
# Access-Control-Allow-Origin headers, several browsers (well, at least Firefox)
# don't seem to play nicely with this.
#
# To avoid the use of 'Access-Control-Allow-Origin: *', use a simple-ish whitelisting