Skip to content

Instantly share code, notes, and snippets.

View chetan's full-sized avatar
🙌
like my work? sponsor me!

Chetan Sarva chetan

🙌
like my work? sponsor me!
View GitHub Profile
@chetan
chetan / index.php
Created September 9, 2013 22:02
wordpress template index.php
<?php require_once("_setup.php"); ?>
<div class="container">
<?php require_once("_header.php"); ?>
<div class="page">
<div class="row">
<div class="content col-md-8">
@chetan
chetan / file-per-table.sh
Last active December 22, 2015 16:09
Dump each table to a separate file
DB=foo
for table in `mysql -uroot $DB -e 'show tables' | grep -v '^Tables_in'`; do
echo dumping $table;
mysqldump5 -uroot -t --skip-opt --compact $DB $table > t-$table.sql;
done
@chetan
chetan / pass_fd_io.rb
Created September 5, 2013 20:22
Pass file descriptors (FD) between unrelated processes via a unix socket
# PASS FD TO ANOTHER PROCESS VIA UNIX SOCKET
def start_fd_listener
@pass_fd = UNIXServer.new("/tmp/puma_fd.sock")
ENV["PUMA_PASS_FD"] = @pass_fd.path
Thread.new {
begin
while true do
sock = @pass_fd.accept
@chetan
chetan / ruby_strings.txt
Created August 22, 2013 19:08
fun with ruby strings
ruby-2.0.0-p247 $ pry
[1] pry(main)> "foo" "bar"
=> "foobar"
[2] pry(main)> a = "foo"; b = "bar";
[3] pry(main)> a b
NoMethodError: undefined method `a' for main:Object
from (pry):3:in `__pry__'
{
"name": "Short name for this script",
// Hash of options accepted by this script, via stdin
// [OPTIONAL]
"options": {
"option_name" : {
"name" : "Sample option",
"desc" : "Description of option (defaults to 'foo')",
#!/usr/bin/env ruby
require 'fileutils'
require 'torrent-ruby' # gem install torrent-ruby
buff = []
while true do
begin
buff << STDIN.read_nonblock(64000)
rescue
[3] pry(main)> class String
[3] pry(main)* def call
[3] pry(main)* puts "hi"
[3] pry(main)* end
[3] pry(main)* end
=> nil
[4] pry(main)> "".call()
hi
=> nil
[5] pry(main)> "".()
@chetan
chetan / Gemfile
Created June 6, 2013 20:59
multi_json error
source "https://rubygems.org"
gem "multi_json"
gem "oj"
gem "json"
# Gems included by the bundle:
# * bundler (1.3.4)
# * json (1.8.0)
# * multi_json (1.7.6)
#!/usr/bin/env ruby
require "daemons"
require "fileutils"
module Daemons
class Controller
def catch_exceptions(&block)
begin
@chetan
chetan / cp.rake
Created May 29, 2013 21:13
Buildr classpath helper
module BuildrClasspath
include Extension
first_time do
# Define task not specific to any projet.
desc 'Create classpath for passing to java command'
Project.local_task('classpath')
end