Skip to content

Instantly share code, notes, and snippets.

View gist:cb99156df686b8ab02cc
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 Oct 27, 2014
yelo wall search rspec
View search spec
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)
View gist:95e1a4c618d318efe228
create user
POST api/v1/users
input params:
user{
mobile_number*:
}
@suras
suras / gist:9860400
Created Mar 29, 2014
rails has_and_belongs_to_many enabling touch updated_at when hasbtm association is created
View gist:9860400
# 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 Aug 29, 2015
barter.li api
View gist:9089279
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 Jan 16, 2014
barter.li autosuggest
View gist:8450720
'use strict';
barterApp.directive('autosuggest', function($timeout, $http) {
return {
restrict: "E",
scope: {
modelupdate:"=",
suggestions:"=",
urlsend:"@"
},
@suras
suras / gist:8424198
Last active Jan 3, 2016
angular.js auto suggest
View gist:8424198
'use strict';
barterApp.directive('autosuggest', function($timeout, $http) {
return {
restrict: "E",
scope: {
modelupdate:"=",
suggestions:"=",
urlsend:"@"
},
@suras
suras / gist:8387914
Created Jan 12, 2014
rspec with devise
View gist:8387914
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 Dec 31, 2013
angular.js getting location with html5 location api and reverse geocoding
View agularjs 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 Dec 25, 2015
ISBN13 barcode check digit
View isbn13barcode
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