Skip to content

Instantly share code, notes, and snippets.

@giladmanor
giladmanor / SomeService.java
Created December 18, 2013 11:53
Neo4j <=> RubyOnRails ::: example code for migrating functionality to java || how to pass the live embedded database handle down to java || as used in wikibrains || this example assumes the use of neo4j.rb
// Java stateless service that extracts and orders a list of nodes
public class SomeService {
// this would be an example implementation of a service that retrieves a given list of nodes by one property (i.e. name)
// and ordering the list by another property (i.e. value) and returns it with the highest value first
public static List loveMeSomeData(GraphDatabaseService service, String[] nodeNames) {
//grabbing the nodes by the list of names
HashMap<String, Integer> list = new HashMap<>();
for (String name : nodeNames) {
@giladmanor
giladmanor / bridge.rb
Created December 15, 2013 11:54
Requires JRUBY!!!! This little thing helps us lazy people in connecting java and ruby classes. Pop the javable.rb into your lib and include it where ever you want to use it. this GITS includes: the javable.rb => does all the work the javable_init.rb => helps you initialize and have this injected into whatever (see instructions at the end of the …
require 'javable'
#this example uses neo4j.rb.
class Bridge < Neo4j::Rails::Model
include Javable
require_jar_folder #by default imports all .jar files from lib/
def initialize
super
#Create a ruby instance from the full java class name
@giladmanor
giladmanor / mgr.rb
Created August 12, 2013 14:19
Simplest Ruby/Rails Producer-Consumer thread example
require 'thread'
class Mgr
# This initiates the queue and the threads
def self.run
@mutex = Mutex.new
@cv = ConditionVariable.new
@working = true
@clue_bank = 0
10.times{|i|
@giladmanor
giladmanor / service.js
Created June 8, 2013 07:30
Angular | Rails JSONP
angular.module('myapp.component', ['ngResource']).factory('MyService', function($resource) {
return $resource('http://giladmanor.com\\:3000/t/t', {alt: 'json', callback: 'JSON_CALLBACK'},
{ 'send': { method: 'JSONP'}});
});
@giladmanor
giladmanor / Context.js
Created June 4, 2013 18:04
Angular Context object: This service serves as an application wide context for passing information and events seamlessly between controllers.
angular.module('myApp.context', []).factory('Context', function($rootScope, $location) {
return {
'contentTypeFilter': "All",
'contentScopeFilter': "pub",
'focusedItemId': -1,
'profileData':{},
'broadcast': function(eventName){
console.log("! Broadcasting: "+ eventName);
$rootScope.$broadcast( eventName );
},
def get_token
token = "AKA #{params[:id]} #{Time.now.to_f}".hash
Rails.cache.write(token,params[:id], :timeToLive => 60.seconds)
render :json => token
end
def use_token
session[:user_id] = Rails.cache.read(params[:token])
redirect_to "/"
end