Skip to content

Instantly share code, notes, and snippets.

defmodule GCM.Pusher do
use GenStage
# The maximum number of requests Firebase allows at once per XMPP connection
@max_demand 100
defstruct [
:producer,
:producer_from,
:fcm_conn_pid,
:pending_requests,
defmodule GCM.PushCollector do
use GenStage
# Client
def push(pid, push_requests) do
GenServer.cast(pid, {:push, push_requests})
end
# Server
Step 5 : ADD server.xml /usr/share/tomcat6/conf/server.xml
Error build: mkdir /var/lib/docker/containers/8b2e01ff4bece7456daaa37ad3754cc432269c68fbff0fdc9d563dfbb6cce79e/rootfs/usr/share/tomcat6/conf: file exists
mkdir /var/lib/docker/containers/8b2e01ff4bece7456daaa37ad3754cc432269c68fbff0fdc9d563dfbb6cce79e/rootfs/usr/share/tomcat6/conf: file exists
irb(main):018:0> a = []
=> []
irb(main):019:0> a << 3
=> [3]
irb(main):020:0> a
=> [3]
irb(main):021:0> b = a
=> [3]
irb(main):022:0> b << 4
=> [3, 4]
@jhowarth
jhowarth / login.js
Created April 27, 2011 23:08
How to post data to create a new Devise session through ajax
function login() {
var email = $('#user_email').val();
var password = $('#user_password').val();
var data = {remote: true, commit: "Sign in", utf8: "✓",
user: {remember_me: 1, password: password, email: email}};
$.post('/users/sign_in.json', data, function(resp) {
if(resp.success) {
// process success case
} else {
// let the user know they failed authentication
@jhowarth
jhowarth / _login.html.haml
Created April 27, 2011 23:04
A simple login form written in haml
%form
= label :user, :email, "Email"
= text_field :user, :email
= label :user, :password
= password_field :user, :password
%input{:type => "submit", :value => "Sign in"}
@jhowarth
jhowarth / sessions_controller.rb
Created April 27, 2011 22:52
A session controller for Devise that allows ajax logins.
class SessionsController < Devise::SessionsController
def create
resource = warden.authenticate!(:scope => resource_name, :recall => :failure)
return sign_in_and_redirect(resource_name, resource)
end
def sign_in_and_redirect(resource_or_scope, resource=nil)
scope = Devise::Mapping.find_scope!(resource_or_scope)
resource ||= resource_or_scope
@jhowarth
jhowarth / addressable.rb
Created April 15, 2011 23:15
How to open a URL that contains an underscore in the subdomain
require 'addressable/uri'
require 'net/http'
@uri = Addressable::URI.parse("http://sub_domain.host.com")
@response = Net::HTTP.get_response(@uri)
puts @response.body
@jhowarth
jhowarth / ThreadClassLoader.java
Created April 15, 2011 21:23
How to fix thread class loader issues in OSGi
ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
...initialize Toplink...
Thread.currentThread.setContextClassLoader(oldLoader);
@jhowarth
jhowarth / own3d.clj
Created April 13, 2011 00:20
own3d.clj
[:xs:schema {:xmlns:xs "http://www.w3.org/2001/XMLSchema"}
[:ordered-list! {:name "own3dreply"}
[:ordered-list! {:name "liveEvent"}
[:restricted! {:name "isLive" :base "xs:string"} [:xs:pattern {:value "true|false"}]]
[:xs:element {:name "liveViewers" :type "xs:integer"}]]]]