Skip to content

Instantly share code, notes, and snippets.

@hyoshida
hyoshida / remove_all_docker_images.sh
Created May 18, 2018 09:04
Remove all docker images
docker images -aq | xargs docker rmi
#!/usr/bin/perl
use 5.008;
use warnings FATAL => 'all';
use strict;
# Highlight by reversing foreground and background. You could do
# other things like bold or underline if you prefer.
my @OLD_HIGHLIGHT = (
color_config('color.diff-highlight.oldnormal'),
@hyoshida
hyoshida / backup_without_pack.rake
Last active February 16, 2016 03:08
Buckup/Restore GitLab without tar packaging
# original: https://github.com/gitlabhq/gitlabhq/blob/7-10-stable/lib/tasks/gitlab/backup.rake
require 'active_record/fixtures'
namespace :gitlab do
namespace :backup_without_pack do
# Create backup of GitLab system
desc "GITLAB | Create a backup of the GitLab system"
task create: :environment do
warn_user_is_not_gitlab
@hyoshida
hyoshida / ArrayExtensions.as
Last active January 13, 2016 10:29
Extensions for Vector and Array in ActionScript 3
Array.prototype.findBy = function(attributes:Object):Array {
return VectorUtil.of(this).findBy(attributes);
};
Array.prototype.setPropertyIsEnumerable("findBy", false);
Array.prototype.getOneBy = function(attributes:Object):Array {
return VectorUtil.of(this).getOneBy(attributes);
};
Array.prototype.setPropertyIsEnumerable("getOneBy", false);
@hyoshida
hyoshida / scope_matcher.rb
Last active October 26, 2015 15:05
Rspec one-liner that tests named scopes in Rails.
# Based on http://stackoverflow.com/questions/6853744/how-can-i-have-rspec-test-for-my-default-scope/6853925#6853925
#
# ### Example
#
# class User < ActiveRecord::Base
# scope :recent, -> { order(created_at: :desc).limit(10) }
# end
#
# describe User do
# it { is_expected.to scope(:recent) { order(created_at: :desc).limit(10) } }
@hyoshida
hyoshida / findup
Created September 13, 2015 09:50
Shell script one-liner to find duplicate files.
find $* -type f | ([ -x "`which sha1sum 2> /dev/null`" ] && xargs sha1sum || xargs shasum) | awk '{ p[$1] = p[$1] ? p[$1] " = " $2 : $2 } END { for (key in p) { if (p[key] ~ / = /) print p[key] } }'
@hyoshida
hyoshida / Makefile
Last active August 29, 2015 14:25
Restart Jenkins from the build of Jenkins
suid: restart_jenkins
sudo chown root restart_jenkins
sudo chmod u+s restart_jenkins
restart_jenkins: restart_jenkins.c
cc restart_jenkins.c -o restart_jenkins
@hyoshida
hyoshida / more_readable_interface.rb
Last active August 29, 2015 14:17
More readable interface in Ruby
# ----------------------------------------------------------------------
#
# I think Java style interface is unreadable in Ruby.
# Because must methods and normal methods are mixed.
#
# Ruby で Java の interface のような実装をすると、
# 普通のメソッドと実装必須なメソッドが混ざってわかりにくい。
#
class Car
def engine
@hyoshida
hyoshida / display_category_tree_by_awesome_nested_set.rb
Created March 9, 2015 05:53
Display the category tree by awesome_nested_set
Category.roots.map do |root|
tree = []
root.class.each_with_level(root.self_and_descendants) do |category, level|
tree << "#{' ' * level}#{category.name}"
end
tree
end.join("\n").display
@hyoshida
hyoshida / beepmusic.sh
Created February 15, 2015 13:57
Beep music in FreeBSD
#!/bin/sh
# requirements: kldload speaker
echo 'CDE ~ CDE ~ GEDCDED ~ CDE ~ CDE ~ GEDCDEC ~ GGEGAAG ~ EEDDL2C' > /dev/speaker