Skip to content

Instantly share code, notes, and snippets.

@akirasosa
akirasosa / gist:6697643
Last active April 18, 2019 10:28
Volley. Use cache if there is no internet connection.
public class MyStringRequest extends StringRequest{
public MyStringRequest(int method, String url, Response.Listener<String> listener, Response.ErrorListener errorListener) {
super(method, url, listener, errorListener);
}
@Override
public void deliverError(VolleyError error) {
if (error instanceof NoConnectionError) {
Cache.Entry entry = this.getCacheEntry();
if(entry != null) {
@akirasosa
akirasosa / gist:6547654
Created September 13, 2013 07:26
I have a tons of rspec test cases. Here is an easy way to distribute them between Jenkins slaves.
# LABEL was passed from an upstream job. It will be in 0, 1 or 2.
find ./spec -name "*_spec.rb" | awk "NR % 3 == ${LABEL} {print}" | xargs rspec
@akirasosa
akirasosa / Gemfile
Created September 12, 2013 10:18
speed up rspec tests using elasticsearch by bypass useless connections to the elasticsearch server
# Gemfile
group :test do
gem "webmock"
end
@akirasosa
akirasosa / github.json
Last active December 22, 2015 21:19
I provision jenkins slaves by using chef. Jenkins slaves have to access to the github.com, heroku.com and so on via ssh. They have to know know_hosts.
echo "cookbook 'ssh_known_hosts', github: 'opscode-cookbooks/ssh_known_hosts'" >> Berksfile
berks install
berks upload
knife data bag create ssh_known_hosts
knife data bag from file ssh_known_hosts data_bags/ssh_known_hosts/github.json
knife data bag from file ssh_known_hosts data_bags/ssh_known_hosts/heroku.json
knife role from file roles/jenkins-slave.rb
@akirasosa
akirasosa / gist:6505112
Created September 10, 2013 04:50
force poltergeist to use 'Accept-Language' as "en"
# spec/spec_helper.rb
RSpec.configure do |config|
config.before(:each) do
if Capybara.current_driver == :poltergeist
page.driver.headers = { 'Accept-Language' => "en" }
end
end
end
@akirasosa
akirasosa / gist:6374297
Created August 29, 2013 04:31
add encrypted_data_bag_secret to starter kit
openssl rand -base64 512 > .chef/encrypted_data_bag_secret
echo 'encrypted_data_bag_secret "#{current_dir}/encrypted_data_bag_secret"' >> .chef/knife.rb
# knife bootstrap myhost -x user -N node-name -r 'role[somerole]' --sudo