Skip to content

Instantly share code, notes, and snippets.

View riywo's full-sized avatar
🏈
Go 49ers!

Ryosuke Iwanaga riywo

🏈
Go 49ers!
View GitHub Profile
sub check_sudo {
my @commands = (
'/bin/netstat',
);
my @unexecutable = grep {
system("sudo -l -U user $_ > /dev/null 2>&1") != 0;
} @commands;
message_for_sudo(@unexecutable);
@riywo
riywo / recipeA_attributes_default.rb
Last active December 17, 2015 13:19
chef attribute override
default["recipeA"]["name"] = "nameA"
default["recipeA"]["path"] = "/tmp/#{node["recipeA"]["name"]}"
@riywo
riywo / vagrant-serverspec.md
Last active December 17, 2015 08:19
vagrant-serverspec

vagrant-serverspec

Example

$ tree
├── Vagrantfile
└── serverspec
    ├── precise64

│   └── httpd_spec.rb

$ python test.py
test
$ echo test
test
$
@riywo
riywo / call_func.pl
Last active December 16, 2015 20:18
dynamic function calling in perl/python/ruby
#!/usr/bin/env perl
use strict;
use warnings;
package CLI;
use Data::Dumper;
sub new {
bless {}, $_[0];
}
@riywo
riywo / reference.md
Last active May 12, 2021 05:37
gdbとかassemblyのアンチョコ

2進数

  • 0xXX
    • 1 byte = 16進数2桁 = 8 bit
  • 0xXXXXXXXX
    • 4 byte = 16進数8桁 = 32 bit
    • int
  • 0xYYYYYYYYXXXXXXXX
    • 8 byte = 16進数16桁 = 64 bit
    • long int
@riywo
riywo / example.py
Last active December 16, 2015 10:59
python mox example with subprocess.Popen and builtin open
#!/usr/bin/env python
from subprocess import *
class Example(object):
def run(self):
a = open("/etc/example.txt").read()
b = Popen("/usr/bin/example.sh", shell=True, stdout=PIPE).communicate()[0]
return a + b
if __name__ == "__main__":
@riywo
riywo / foo.rb
Last active December 16, 2015 10:49
cat("/etc/hosts").grep("localhost").head(:1).cut(:f => 1)
#=> "127.0.0.1"
$ pwd
/path/to/chroot
$ find . -type l -printf "%l\t%p\n" | grep '^/'
/etc/foo ./usr/local/etc/foo
$ find . -type l -printf "%l\t%p\n" | grep '^/' | ruby -F"\t|\n" -ane 'n=$F[1].split("/").size-2; org=Array.new(n, "..").join("/")+$F[0]; system "ln -sf #{org} #{$F[1]}"'
$ find . -type l -printf "%l\t%p\n"
../../../etc/hoge ./usr/local/etc/hoge
@riywo
riywo / gist:5322782
Created April 5, 2013 21:31
a way of mongo Timestamp pretty printing
> db.foo.findOne().t
Timestamp(1365195372000, 1)
> Timestamp.prototype.toString = function() { return new Date(this.getTime()); }
> db.foo.findOne().t
Fri Apr 05 2013 13:56:12 GMT-0700 (PDT)