Skip to content

Instantly share code, notes, and snippets.

Avatar

Almog Melamed Radagaisus

View GitHub Profile
@Radagaisus
Radagaisus / captain.user.js
Last active Aug 29, 2015
How to get user information from Captain Up
View captain.user.js
// Used as a wrapper to make sure Captain Up has loaded on the page
captain.up(function() {
// `captain.player` holds all the information about the users, including anonymous users information
user_details = captain.player
// Do whatever you want with the data, maybe send it to your server side?
$.ajax({type: 'POST', url: 'http://mysite.com/users/', data: captain.player})
})
@Radagaisus
Radagaisus / customizing_points_names.js
Created Mar 19, 2014
How To Customize the Name of Points in Captain Up
View customizing_points_names.js
// Asynchronous wrapper around the function, to make sure Captain
// Up has loaded completely.
captain.up(function() {
// Set the points string
captain.l.points = "XP";
// Set the shorthand name
captain.l.shorthand_points = "XP";
});
@Radagaisus
Radagaisus / minimize_hud.js
Created Mar 19, 2014
How To Minimize the Captain Up HUD
View minimize_hud.js
// Asynchronous wrapper around the function, to make sure Captain
// Up has loaded completely.
captain.up(function() {
// Minimize the HUD
captain.hud.minimize();
});
@Radagaisus
Radagaisus / hud.js
Last active Aug 29, 2015
Hide and Show the Captain Up HUD
View hud.js
// Asynchronous wrapper, the code will only run after Captain Up has loaded
captain.up(function() {
// Maximize the HUD
captain.hud.maximize();
// Minimize the HUD
captain.hud.minimize();
});
@Radagaisus
Radagaisus / sign_up.js
Created May 18, 2014
Open the Captain Up Sign Up Modal
View sign_up.js
// Asynchronous wrapper to ensure Captain Up has loaded
captain.up(function() {
//open the sign up modal
captain.open_sign_up_modal();
});
@Radagaisus
Radagaisus / coffee_script_json.rb
Created Jul 16, 2014
A Sprockets Engine to write valid JSON in CoffeeScript
View coffee_script_json.rb
# The CoffeeScriptJSON module is a Sprockets engine that can be used to write
# JSON files in CoffeeScript.
#
# This CoffeeScript:
#
# # whatever.json.coffee_json
# hello: 'world!'
#
# Will be compiled down to:
#
@Radagaisus
Radagaisus / user_read.js
Last active Aug 29, 2015
Tracking a user page read action
View user_read.js
// Asynchronous wrapper around Captain Up, code will run once Captain Up has loaded.
captain.up(function() {
// Periodically test if the user has read the page
setInterval(function(){
// You need to implement `user_read_the_page` by yourself, maybe as a check
// that the user scrolled to the bottom? Or spent at least a minute on the page?
if (user_read_the_page()) {
// Track the action with Captain Up, remember to configure the action settings for it
// by creating a new 'read' action in your admin panel.
captain.action('read', {
@Radagaisus
Radagaisus / sign_user.php
Last active Aug 29, 2015
Captain Up User Integration - Signing a User Object in PHP
View sign_user.php
<?php
// Signs a user object with your API secret.
// See: https://captainup.com/help/javascript/user-integration
//
// @param secret - {String} Your Captain Up API secret
// @param user - {Associative Array} the user dictionary
// @return {String} the signed user string
function sign_user($secret, $user) {
// Remove all `null`, `undefined`, arrays and objects from the object
@Radagaisus
Radagaisus / nginx.conf
Created Dec 31, 2014
node.js proxy in nginx w/ https
View nginx.conf
http {
upstream node_server {
server 127.0.0.1:2222;
}
server {
listen 443 ssl;
server_name example.com;
ssl on;
@Radagaisus
Radagaisus / custom_daily_visit_action.coffee
Created Jan 1, 2015
Daily Visit Custom Captain Up Action
View custom_daily_visit_action.coffee
// Only run the code when Captain Up has loaded on the page
captain.up(function() {
// Track a new 'daily_visit' custom action
captain.action('daily_visit', {
// Pass extra data about the action
entity: {
// The current page name
name: captain.get_page_title()
// The referrer URL
referrer: captain.player_info.referrer