Skip to content

Instantly share code, notes, and snippets.

View troex's full-sized avatar

Sergey B (Troex Nevelin) troex

View GitHub Profile
<script type="text/javascript">
!function(){var Attribution=window.Attribution=window.Attribution||[];if(!Attribution.initialize)if(Attribution.invoked)window.console&&console.error&&console.error("Attribution snippet included twice.");else{Attribution.invoked=!0,Attribution.methods=["setAnonymousId","trackSubmit","trackClick","initialize","trackLink","trackForm","pageview","identify","reset","group","track","ready","alias","debug","page","once","off","on"],Attribution.factory=function(e){return function(){var t=Array.prototype.slice.call(arguments);return t.unshift(e),Attribution.push(t),Attribution}};for(var t=0;t<Attribution.methods.length;t++){var e=Attribution.methods[t];Attribution[e]=Attribution.factory(e)}Attribution.load=function(t,e){var i=document.createElement("script");i.type="text/javascript",i.async=!0,i.src="https://scripts.attributionapp.com/v2/attribution.js";var r=document.getElementsByTagName("script")[0];r.parentNode.insertBefore(i,r),e=e||{},e.projectId=t,Attribution._loadOptions=e},At
@troex
troex / attribution-unbounce-legacy.html
Last active May 10, 2021 17:38
Attribution snippet for Unbounce pages (legacy, using jQuery)
<script type="text/javascript">
window.Attribution=window.Attribution||[];window.Attribution.methods=["trackSubmit","trackClick","trackLink","trackForm","pageview","identify","group","track","ready","alias","page","once","off","on"];window.Attribution.factory=function(e){return function(){var t=Array.prototype.slice.call(arguments);t.unshift(e);window.Attribution.push(t);return window.Attribution}};for(var i=0;i<window.Attribution.methods.length;i++){var key=window.Attribution.methods[i];window.Attribution[key]=window.Attribution.factory(key)}window.Attribution.load=function(e){if(document.getElementById("attribution-js"))return;var t=document.createElement("script");t.type="text/javascript";t.id="attribution-js";t.async=true;t.src="//scripts.attributionapp.com/attribution.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(t,n)};window.Attribution.load();
window.Attribution.projectId="YOUR_PROJECT_ID";
window.Attribution.page(window.ub && window.ub.page && window.ub.page.nam
INSERT
INTO
"staging_visits_2039"
SELECT
"events_stage_2039"."id",
"events_stage_2039"."visitor_id",
"events_stage_2039"."time" AS "visit_time",
(CASE "value"
WHEN '6154970940111' THEN 177765
WHEN '6154852349911' THEN 177740
@troex
troex / attribution-crossdomain-tracking.js
Last active May 22, 2019 19:07
AttributionApp Cross-domain Tracking Snippet
// Attribution snippet code
window.Attribution=window.Attribution||[];window.Attribution.methods=["trackSubmit","trackClick","trackLink","trackForm","pageview","identify","group","track","ready","alias","page","once","off","on"];window.Attribution.factory=function(e){return function(){var t=Array.prototype.slice.call(arguments);t.unshift(e);window.Attribution.push(t);return window.Attribution}};for(var i=0;i<window.Attribution.methods.length;i++){var key=window.Attribution.methods[i];window.Attribution[key]=window.Attribution.factory(key)}window.Attribution.load=function(e){if(document.getElementById("attribution-js"))return;var t=document.createElement("script");t.type="text/javascript";t.id="attribution-js";t.async=true;t.src="//scripts.attributionapp.com/attribution.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(t,n)};window.Attribution.load();
// set your project key
window.Attribution.projectId="YOUR_APP_KEY";
// cross-domain hook
Attribution.ready(function() {
// list
@troex
troex / app.js
Created September 1, 2017 16:30
AngularJS Attribution Page tracking
angular.module('AttributionApp').run(['$rootScope', 'AnalyticsTracker', '$state', function($rootScope, AnalyticsTracker, $state) {
$rootScope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams) {
var toStateFragment = $state.href(toState, toParams);
var fromStateFragment = $state.href(fromState, fromParams);
var origin = window.location.origin;
var path = window.location.pathname;
// strip hash-bang from url
var pathWithParams = path + toStateFragment.replace(/^#!\//, '')
@troex
troex / my_controller.rb
Last active October 7, 2021 09:41
Sinatra + EventMachine + Puma – Heroku workaround for 30 seconds timeout
module Application
module Controllers
class MyController < Sinatra::Base
helpers Sinatra::Streaming
class << self
def stream(method, path, opts = {}, &block)
send(method, path, opts) do
stream do |out|
timer = EventMachine::PeriodicTimer.new(10) { out << "\0" }
# automatically spin off additional services in dev mode when `rails s` started
if Rails.env.development? && defined?(Rails::Server)
puts '=> Development mode server detected, spin off additional services'
Thread.new do
puts '=> Starting Delayed::Worker'
Delayed::Worker.new(:quiet => true).start
end
@troex
troex / update-from-git.sh
Created December 2, 2011 08:55
Update rails from git on commits
#!/bin/sh
#
# Update rails from git on commits
# Author: Troex Nevelin <troex@fury.scancode.ru>
cd /home/alex/smartspace_development
if [ -f .update_in_progress ]; then
exit 0 # exit if in progress or error happend
fi
@troex
troex / gist:1404284
Created November 29, 2011 10:12
Hack ActiveResource::Base to support per instance site option
class Runner
@@nodes = {}
def self.node(site)
@@nodes[site] || = self.new_ar(site).new if !@@nodes.has_key?(site)
end
def self.new_ar(site)
Class.new(ActiveResource::Base) do
self.site = site
@troex
troex / backup-sql.sh
Created September 27, 2011 15:20
Backup all mysql databases to separate files
#!/bin/sh
# echo "11 5 * * * root /etc/backup-sql.sh | logger -t backup-sql" >> /etc/cron.d/backup
P="/var/www/sql_dump/"
MO="--skip-lock-tables"
MO="$MO --single-transaction" # for InnoDB
GZIP="gzip --rsyncable"
GZIP_ON_THE_FLY=true
SCOPE=`date +%u` # weekly rotation