Skip to content

Instantly share code, notes, and snippets.

nhm tanveer hossain khan (hasan) we4tech

Block or report user

Report or block we4tech

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@we4tech
we4tech / fibonacci_series.kt
Created Sep 5, 2017
Fibonacci series upto n
View fibonacci_series.kt
fun findFibSeries(n: Int) {
val series = mutableListOf(0, 1)
(0..n).map { n ->
series.add(series.takeLast(2)
.reduce {sum, it -> sum + it})
}
series.forEach { println(it) }
}
@we4tech
we4tech / javascript_generator_fibonacci.js
Created Jul 28, 2017
Use ES6 generator to generate infinite fibonacci series
View javascript_generator_fibonacci.js
function *calcFib () {
let n = 0
let fib = function(v) {
return v <= 1 ? v : fib(v - 1) + fib(v - 2)
}
while (true) yield fib(n++)
}
@we4tech
we4tech / tunnel
Created Aug 13, 2016
Tunnel for PayPal IPN
View tunnel
#!/usr/bin/env bash
ssh -v -nNT -R 9999:localhost:3000 ubuntu@staging.source4style.com
@we4tech
we4tech / nice-shadow.scss
Created Jul 29, 2016
Collection of Nice Shadow effects
View nice-shadow.scss
.shadow1 {
box-shadow: 0 0 20px 1px rgba(114,114,189,0.1);
}
@we4tech
we4tech / country_field.js.jsx.coffee
Created Mar 30, 2016
An Example of How to Use React from AngularJS
View country_field.js.jsx.coffee
window.UIControls.CountryField = React.createClass
mixins: [CountriesMixin]
getInitialState: -> {code: @props.data}
changeCountry: (evt) ->
code = evt.currentTarget.value
@setState(code: code)
@props.onChange(code) if @props.onChange?
@we4tech
we4tech / lazy_attribute.rb
Created Dec 30, 2013
Define attribute which value is loaded and stored lazily. Ie. You want to get some data from a 3rd party API call but instead of setting them explicitly you want to get those on demand. Here are few lines of code to get it workable.
View lazy_attribute.rb
module Concerns
module LazyAttribute
extend ActiveSupport::Concern
included do
class_attribute :lazy_attributes
end
module ClassMethods
def attr_lazy(name, &logic_impl)
@we4tech
we4tech / rthread_importer.rb
Last active Dec 31, 2015
An illustration how we can use ruby thread for accelerating our normal RAKE tasks. (intended for posting in a local Ruby developers group https://www.facebook.com/groups/rubydevs/)
View rthread_importer.rb
namespace :somestuffs do
desc 'Importing some big stuff that requies lotta network stuff'
task :import
file, tasks = ENV['FILE'], Queue.new
# Parse out CSV file and retrieve each row and queue them up
# for further processing.
#
# Keeping it a thread allows us to let this process continue while other
# threads are not in RUNNING state.
@we4tech
we4tech / as_active_merchant.rb
Created Oct 9, 2013
Simple written "Model Concern" for adding active merchant
View as_active_merchant.rb
# Integrate with ActiveMerchant and Expose active merchant related methods.
#
# This module also includes Validator for ActiveMerchant.
module Concerns::AsActiveMerchant
extend ActiveSupport::Concern
included do
validates_with Validators::ActiveMerchant, if: :cc_number_is_changed?
end
@we4tech
we4tech / with_default_mongoid_methods.rb
Last active Dec 24, 2015
What if, we've more pictorial relationship syntax than syntactical sugar ?
View with_default_mongoid_methods.rb
class Message
include Mongoid::Document
include Mongoid::Timestamps
field :subject, type: String
field :content, type: String
belongs_to :replied_to, class_name: 'Message', inverse_of: :replies, touch: true
belongs_to :sender, class_name: 'User', inverse_of: :sent_messages
has_many :replies, class_name: 'Message', inverse_of: :replied_to
@we4tech
we4tech / exp_factory_method.rb
Created Sep 21, 2013
Instead of relying on 3rd party service, we could wrap them in bridge or expose through factory or facade
View exp_factory_method.rb
def handle_action_created(action)
if action.from.kind_of?(Source)
$redis.lpush(
"#{self.class.name}:#{self.id}",
[action.from.node.id, action.from.node.neo_id].join(":")
)
end
end
# Perhaps we could do
You can’t perform that action at this time.