Skip to content

Instantly share code, notes, and snippets.

View shivpkumar's full-sized avatar

Shiv Kumar shivpkumar

  • New Relic
  • San Francisco
View GitHub Profile
@shivpkumar
shivpkumar / new_user_hipchat_notification_job.rb
Last active August 29, 2015 14:21
Send a notification to Hipchat when new users join the forum
class NewUserHipchatNotification < ::Jobs::Scheduled
every 5.minutes
def execute(args)
new_users = User.where("created_at >= ?", 5.minutes.ago)
if new_users.any?
message = format_message(new_users)
client = HipChat::Client.new(ENV['YOUR_HIPCHAT_API_TOKEN'], :api_version => 'v2')
client[ENV['YOUR_HIPCHAT_ROOM_NUMBER']].send('Forum Bot', message, { :color => 'green', :notify => true })
@shivpkumar
shivpkumar / bringg.rb
Created March 3, 2015 21:08
Bringg API example
module Bringg
class Customer
def self.create(params)
params.merge!(timestamp: Time.now.to_i)
params.merge!(access_token: "MY_ACCESS_TOKEN")
params = params.sort.to_h
query_params = params.to_query
params.merge!(signature: OpenSSL::HMAC.hexdigest("sha1", "MY_SECRET_KEY", query_params))
Discourse.ZendeskButton = Discourse.ButtonView.extend({
classNames: ['zendesk'],
title: 'zendeskTicket.title',
text: function() {
return this.get('controller.zendeskTicket.status');
}.property(),
click: function() {
alert(this.get("controller.content.title"));
Discourse.TopicRoute.on("setupTopicController", function(event) {
Discourse.ajax("/zendesk/find_ticket", {
dataType: 'json',
data: { external_id: event.currentModel.slug + event.currentModel.id },
type: 'GET'
}).then(function (ticket) {
event.controller.setProperties({ zendeskTicket: ticket });
});
});
Discourse.TopicController = Discourse.TopicController.extend({
zendeskTicket: null,
actions: {
sendToZendesk: function(posts, user) {
Discourse.ajax("/zendesk/create_ticket", {
dataType: 'json',
data: { post_title: title,
html_comment: bodyAsHtml,
created_at: createdAt,
{{#if currentUser.staff}}
{{#if zendeskTicket}}
<button {{bind-attr title="zendeskTicket.title"}} {{action redirectToZendesk zendeskTicket.url}}>{{zendeskTicket.status}}</button>
{{else}}
<button title='Click to create a new ticket in Zendesk' {{action sendToZendesk postStream.posts currentUser}}>Send to Zendesk</button>
{{/if}}
{{/if}}
@shivpkumar
shivpkumar / devise_multi_oauth.md
Last active February 25, 2018 02:58
Multiple OmniAuth for Devise

Multiple OmniAuth for Devise

This tutorial will cover how to create a Rails app that allows users to register and sign in using a choice of multiple OmniAuth providers. It's intended to be used any time you create a Rails app that you'd like to integrate with multiple OAuth providers. After you get through the steps in this guide, it's on you to make the rest of your app awesome. We're just here to start you off on the right foot.

We'll begin with the barebone basics of how to setup your Rails app, then get it working with one provider (Facebook) and finally go over how to integrate other OAuth providers into your app.

Basic Setup

@shivpkumar
shivpkumar / intro_to_rails_routing.md
Last active December 18, 2015 22:19
Intro to Rails Routing

In Sinatra, a typical get route looks like this:

get "/posts/:id" do
  @post = ...
  erb :post
end

You have your route, i.e. get "posts/:id", followed by its corresponding action, i.e. @post.. erb :post

@shivpkumar
shivpkumar / index.html
Last active December 18, 2015 08:29 — forked from dbc-challenges/index.html
DBC Phase 2 Practice Assessment Part 3
<!doctype html>
<html>
<head>
<link rel="stylesheet" href="http://cdn.jsdelivr.net/normalize/2.1.0/normalize.css">
<link rel="stylesheet" href="main.css">
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700,800">
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Lato:100,900">
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/3.0.2/css/font-awesome.min.css">
</head>
<img src="/<%= @roll.value %>.png" title="<%= @roll.value %>" alt="the roll">