Skip to content

Instantly share code, notes, and snippets.

View wendy0402's full-sized avatar

wendy kurniawan soesanto wendy0402

View GitHub Profile
@wendy0402
wendy0402 / binary search algorithm
Last active August 29, 2015 14:11
alternative simple implementation of tail recursion for binary search algorithm
define_method(:search) do |value, array, from = 0, to = (array.size - 1)|
mid = (from + to) / 2
return mid if value == array[mid]
return nil if to == 0 || from == (array.size - 1)
value < array[mid] ? to = mid - 1 : from = mid + 1
redo
end
@wendy0402
wendy0402 / rules.md
Last active August 29, 2015 14:15 — forked from henrik/rules.md
  1. Your class can be no longer than 100 lines of code.
  2. Your methods can be no longer than five lines of code.
  3. You can pass no more than four parameters and you can’t just make it one big hash.
  4. When a call comes into your Rails controller, you can only instantiate one object to do whatever it is that needs to be done. And your view can only know about one instance variable.

You can break these rules if you can talk your pair into agreeing with you.

@wendy0402
wendy0402 / rvm_install.sh
Last active August 29, 2015 14:18
Install RVM
echo 'go to home folder'
cd $HOME
echo "installing mpapis public key"
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
echo "Download and Install RVM"
\curl -sSL https://get.rvm.io | bash -s stable --ruby
echo "Updating Bash Profile"

Chapter 1 - Object Oriented Design

The purpose of design is to allow you to do design later, and it's primary goal is to reduce the cost of change.

SOLID Design:

  • Single Responsibility Principle: a class should have only a single responsibility
  • Open-Closed Principle: Software entities should be open for extension, but closed for modification (inherit instead of modifying existing classes).
  • Liskov Substitution: Objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program.
  • Interface Segregation: Many client-specific interfaces are better than one general-purpose interface.
@wendy0402
wendy0402 / karma.conf.js
Last active August 29, 2015 14:21
configuration example for setup test environment using karma, requirejs, mocha, chai, and sinon
// Karma configuration
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
@wendy0402
wendy0402 / sum_prime.js
Created July 24, 2015 16:01
summarize prime number, but to check whether it is prime or not, based on previous prime number
function sumPrimes(num) {
prime = [2,3];
sum = 2 + 3;
for(n = 4; n <= num; n++){
var prime_flag = true;
for(prime_d = 0; prime_d < prime.length; prime_d++){
if(n % prime[prime_d] === 0){
prime_flag = false;
}
}
@wendy0402
wendy0402 / digitalocean.md
Last active August 29, 2015 14:26 — forked from JamesDullaghan/digitalocean.md
Deploy rails app to digitalocean with nginx, unicorn, capistrano & postgres

Deploy Rails app to digitalocean with nginx, unicorn, capistrano & postgres

Create droplet of your liking (ubuntu 12.10 x32)

ssh to root in terminal with your server ip

ssh root@123.123.123.123

Add ssh fingerprint and enter password provided in email

@wendy0402
wendy0402 / digital_ocean_setup.md
Last active August 29, 2015 14:26 — forked from ChuckJHardy/digital_ocean_setup.md
DigitalOcean Ubuntu 14.04 x64 + Rails 4 + Nginx + Unicorn + PostgreSQL + Capistrano 3 Setup Instructions

DigitalOcean Ubuntu 14.04 x64 + Rails 4 + Nginx + Unicorn + PostgreSQL + Capistrano 3

SSH into Root

$ ssh root@123.123.123.123

Change Root Password

@wendy0402
wendy0402 / gulpfile.js
Created September 29, 2015 16:04
gulpfile to watch, browserify and copy to public
var gulp = require('gulp');
var browserify = require('browserify');
var babelify = require('babelify');
var source = require('vinyl-source-stream');
var gutil = require('gulp-util');
var uglify = require('gulp-uglify');
gulp.task('browserify', function(){
browserify({debug:true, entries: 'src/js/main.js'})
.transform(babelify)
@wendy0402
wendy0402 / test redirection using Rack::Test
Last active January 26, 2016 11:23
test redirection using Rack::Test, rspec with poltergeist
before do
# because we cannot mock redirection, set driver to not follow redirects
@current_driver_config = page.driver.instance_variable_get(:@options)
page.driver.instance_variable_set(:@options, @current_driver_config.merge({follow_redirects: false}))
end
after do
# set driver setting to follow redirection again
page.driver.instance_variable_set(:@options, @current_driver_config)
end