Skip to content

Instantly share code, notes, and snippets.

@samgooi4189
samgooi4189 / method_def_ruby
Created April 18, 2018 07:27
method definition in ruby, colon vs equals
$ irb
2.4.3 :001 > def foo(a:1, b:2)
2.4.3 :002?> print "#{a}#{b}"
2.4.3 :003?> end
=> :foo
2.4.3 :004 > def foobar(a:1, b:2)
2.4.3 :005?> foo(a,b)
2.4.3 :006?> end
=> :foobar
2.4.3 :007 > foobar(3,4)
@samgooi4189
samgooi4189 / weird_rspec_error
Created April 3, 2018 14:11
AbstractController::ActionNotFound: The action 'index' could not be found for
I am seeing this error after running rspec:
Failure/Error: raise ActionNotFound, "The action '#{action}' could not be found for #{self.class.name}"
AbstractController::ActionNotFound:
The action 'index' could not be found for Api::V1::ExpertSchedulesController
All other routes are not throwing error in the controller.
@samgooi4189
samgooi4189 / rspecStubTime
Last active March 14, 2018 08:13
Mocking Time.now in rspec
put in 'before' block inside rspec scenario:
@time_now = Time.parse("2018-03-08T00:00:00.000Z")
allow(Time).to receive(:now).and_return(@time_now)
You should see that the Time.now is being used in rspec scenario, but this won't be used in factory_bot.
You can selectively use it in certain test cases.
@samgooi4189
samgooi4189 / login_devise_csrf
Created March 13, 2018 11:00
Login to Devise with CSRF
First you need to expose your CSRF token
SessionsController.rb:
def new
render json: {"CSRF": form_authenticity_token}
end
When you visit GET sign_in path, you will get the CSRF token.
To sign_in with POST,
@samgooi4189
samgooi4189 / L510BIOSflash
Created November 4, 2017 05:37
Flashing Toshiba Satelite L510 BIOS from USB
Preparing the bootable pendrive
1. Download http://wincmd.ru/black_dog/v6535/crdisk.rar, password is "crisis"
2. Download Ultimate BIOS-Boot-Edition from https://biosflash.com/e/bios-boot-usb-stick.html
3. Follow the steps in biosflash.com until you finish created the USB bootable drive
4. Download driver from Toshiba https://support.toshiba.com/support/viewContentDetail?contentId=2486122
5. Extract the downloaded driver file, you will able to see PR10M150.fd
6. Copy all the files extracted from crdisk.rar to the bootable pendrive, you should able to see PHLASH16.exe when you open you pendrive
7. Copy PR10M150.fd to bootable pendrive, then rename it to BIOS.FD
8. Remove BIOS.WPH file from the bootable pendrive
@samgooi4189
samgooi4189 / simpleSSLCertDebug.rb
Created October 6, 2017 16:12
Debug SSL cert with Ruby
require 'net/https'
# To know more can visit http://www.rubydoc.info/stdlib/net/Net/HTTP
# For http only website, can use quirktools.com
# For weird SSL cert, can use ktmb.com.my
# For self-signed cert, use self-signed.badssl.com
# More example: https://badssl.com/
if ARGV[0]
host = ARGV[0]
@samgooi4189
samgooi4189 / virtualenv_pip.txt
Created August 26, 2017 07:44
using virtualenv installed using pip
Here are the steps to have working virtualenv:
$ pip install virtualenv
$ sudo /usr/bin/easy_install virtualenv
@samgooi4189
samgooi4189 / gooi_bot.rb
Last active August 1, 2017 13:48
gooi_bot
class GooiBot < RTanque::Bot::Brain
NAME = 'gooi_bot'
include RTanque::Bot::BrainHelper
MAX_RAND_DIVISION = 10.0
def tick!
## main logic goes here
@current_heading ||= sensors.heading
@samgooi4189
samgooi4189 / InvestigateDeviseParameterSanitizerr
Created July 15, 2017 09:41
Why devise_parameter_sanitizer.sanitize return empty params? [Solved]
Problem:
(byebug) devise_parameter_sanitizer.sanitize(:sign_up)
{}
Investigation:
1. We post the data to the backend in this format
```
$ curl -X POST -H "Content-Type: application/json" --data "{\"user\": {\"email\":\"abc@abc.com\", \"password\": \"1234567890\", \"password_confirmation\": \"1234567890\"}}" localhost:3000/api/v1/users
```
@samgooi4189
samgooi4189 / mysql_rails_console_fix
Created May 13, 2017 16:32
Solving mysql error for rails console
Sympthoms:
$ rails c
Running via Spring preloader in process 19704
Loading development environment (Rails 5.1.0)
2.4.0 :001 > User.connection
Mysql2::Error: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
from (irb):1
Fix: