Skip to content

Instantly share code, notes, and snippets.

View chrisyeung1121's full-sized avatar
🌝
Working from Moon

Christopher Yeung chrisyeung1121

🌝
Working from Moon
View GitHub Profile
@chrisyeung1121
chrisyeung1121 / 1_java_string_char_array
Created March 24, 2015 15:43
Characters Array v.s. String Array
String[] stringArray = {"a", "b", "c"}; // Compile okay
String[] stringArray2 = {'a', 'b', 'c'}; // single quotation is for Character Class
Character[] charArray = {'a', 'b', 'c', 'd'}; // Compile okay
Character[] charArray2 = {"a", "b"}; // Error: Double quotation is parsed as String
Character[] charArray3 = {'ab'}; // Error: Too many characters. Can only have one.
@chrisyeung1121
chrisyeung1121 / 2_android_array_to_adapter
Created March 24, 2015 15:49
Android: Add String Array to ArrayAdapter
// Created in CarsFragment.java
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_cars, container, false);
String[] dummyCarData = {
@chrisyeung1121
chrisyeung1121 / 3_git_print_sha1_of_certain_commit
Last active August 29, 2015 14:17
Git command to print the SHA1 of the nth commit
# where 6 = showing the sixth commit.
git rev-list --all | tail -n 6 | head -n 1
# $> b753a30804cc0770b52686166a21cbdea642ff08
# Knowing the output, we can then do the following to checkout to that certain commit
git checkout b753
@chrisyeung1121
chrisyeung1121 / 4_java_final_variable.java
Created March 24, 2015 16:13
Java's final variable
// http://javarevisited.blogspot.hk/2011/12/final-variable-method-class-java.html
// Final variable
final int CONSTANT_PI = 3.14; // Note constant are usually defined in ALL CAPS
CONSTANT_PI = 2.14; // will cause compilation error
// final method
// final method cannot be overriden by subclass
// final Class
ActiveRecord::Base.logger = Logger.new(STDOUT)
@chrisyeung1121
chrisyeung1121 / useful linux commands
Last active August 29, 2015 14:19
linux command cheat sheet
# Check netstat
netstat -anp tcp
# List which apps are using port 5000
lsof -i :5000
# Check brew package info
brew info elasticsearch
# To start elasticsearch without launctl
@chrisyeung1121
chrisyeung1121 / restart_crontab.sh
Created April 17, 2015 04:53
crontab needs to restart after configuring timezone
# It checks the cron jobs that run before
sudo grep CRON /var/log/syslog
# Check timezone
cat /etc/timezone
# Restart Crontab
sudo /etc/init.d/cron restart
@chrisyeung1121
chrisyeung1121 / devise_customize_login_routes.rb
Created April 21, 2015 15:10
Devise customising login paths
devise_for :users,
:skip => [:registrations, :sessions]
as :user do
# Sessions
get '/login2' => 'users/sessions#new', :as => :new_user_session
# :new_user_session is being defined by devise_for :users already, so have to use :skip!
end
@chrisyeung1121
chrisyeung1121 / 6_routes.rb
Last active August 29, 2015 14:19
Scoping controllers in rails routes
as :user do
# Sessions
get '/login' => 'users/sessions#new', as: :new_user_session
# Registration
controller 'users/registrations' do
get '/signup', action: :new, as: :new_user_registration
end
end
@chrisyeung1121
chrisyeung1121 / 7_heroku_push.sh
Created April 21, 2015 19:30
Sprockets::FileNotFound: couldn't find file 'swiper/dist/js/swiper.jquery.js' with type 'application/javascript'
Sprockets::FileNotFound: couldn't find file 'swiper/dist/js/swiper.jquery.js' with type 'application/javascript'
How to solve?