Skip to content

Instantly share code, notes, and snippets.

import javax.crypto.Cipher;
import javax.crypto.Mac;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.security.AlgorithmParameters;
import java.security.spec.KeySpec;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.IvParameterSpec;
@suras
suras / search spec
Created October 27, 2014 10:04
yelo wall search rspec
require 'rails_helper'
RSpec.describe Api::V1::SearchController, :type => :controller do
describe "wall search" do
before(:each) do
Wall.__elasticsearch__.create_index! force: true
@tag_ios = Tag.create(name: "ios", score: 2)
@tag_ruby = Tag.create(name: "ruby", score: 2)
@user1 = FactoryGirl.create(:user)
@suras
suras / gist:95e1a4c618d318efe228
Last active August 29, 2015 14:04
lovocal api
create user
POST api/v1/users
input params:
user{
mobile_number*:
}
@suras
suras / gist:9860400
Created March 29, 2014 18:42
rails has_and_belongs_to_many enabling touch updated_at when hasbtm association is created
# include this module in models where adding record of has_and_belongs_to_many asscociation
# changes the updated_at column of included model.
module HabtmTouchId
extend ActiveSupport::Concern
included do
after_initialize :create_touch_true_has_and_belongs_to_many
end
@suras
suras / gist:9089279
Last active August 29, 2015 13:56
barter.li api
get book information
get '/api/v1/book_info'
output: goodreads object
get book suggestions
get '/api/v1/book_suggestions'
output: array of book names
get nearby locations
@suras
suras / gist:8450720
Created January 16, 2014 06:39
barter.li autosuggest
'use strict';
barterApp.directive('autosuggest', function($timeout, $http) {
return {
restrict: "E",
scope: {
modelupdate:"=",
suggestions:"=",
urlsend:"@"
},
@suras
suras / gist:8424198
Last active January 3, 2016 06:39
angular.js auto suggest
'use strict';
barterApp.directive('autosuggest', function($timeout, $http) {
return {
restrict: "E",
scope: {
modelupdate:"=",
suggestions:"=",
urlsend:"@"
},
@suras
suras / gist:8387914
Created January 12, 2014 17:43
rspec with devise
require 'spec_helper'
# This spec was generated by rspec-rails when you ran the scaffold generator.
# It demonstrates how one might use RSpec to specify the controller code that
# was generated by Rails when you ran the scaffold generator.
#
# It assumes that the implementation code is generated by the rails scaffold
# generator. If you are using any extension libraries to generate different
# controller code, this generated spec may or may not pass.
#
@suras
suras / agularjs reverse geocoding
Created December 31, 2013 13:27
angular.js getting location with html5 location api and reverse geocoding
// to get the current latitude and longitude from browser
// credits https://github.com/arunisrael/angularjs-geolocation
'use strict';
angular.module('geolocation',[]).constant('geolocation_msgs', {
'errors.location.unsupportedBrowser':'Browser does not support location services',
'errors.location.notFound':'Unable to determine your location',
});
angular.module('geolocation')
@suras
suras / isbn13barcode
Last active December 25, 2015 15:08
ISBN13 barcode check digit
module IsbnCalculator
def self.isbn(num)
total = multiply_by(num, 1, 3)
mod_val = total % 10
mod_val = 10 - mod_val
final_val = mod_val == 10 ? 0 : mod_val
num.to_s + final_val.to_s
end