Skip to content

Instantly share code, notes, and snippets.

View ys's full-sized avatar
💭
Doing stuff with computers

Yannick Schutz ys

💭
Doing stuff with computers
View GitHub Profile
@ys
ys / stored_procedure_service.rb
Created September 13, 2012 12:50
Execute stored procedure
class StoredProcedureService
def self.instance
@instance ||= StoredProcedureService.new
end
def execute(name, *args)
results = []
begin
connection.execute("CALL #{name}(#{args.join(',')})").each(as: :hash, symbolize_keys: true) do |row|
#!/bin/bash
# Fill Disk with random data for testing
myname=`basename $0`
usage() {
echo "Usage: $myname [-d dircount] [-f filecount] [-b maxblockcount] [-s blocksize] [-v] [-q] [-h]"
exit 0
}
help() {
<link href="http://code.divshot.com/geo-bootstrap/swatch/bootstrap.min.css" rel="stylesheet"/>
<style>
body{
background: white !important;
}
h1{
text-align: center;
margin: 50px;
}
def tar(path)
base_path = path.split("/")[0..-2].join("/")
folder = path.split("/")[-1]
if File.exist?(".gitignore")
ok = system("/usr/bin/tar -C \"#{base_path}\" --exclude='.git' --exclude-from=.gitignore -cvzf \"#{tempfile}\" \"#{folder}\"")
else
ok = system("/usr/bin/tar -C \"#{base_path}\" -cvzf \"#{tempfile}\" \"#{folder}\"")
end
unless ok
raise StandardError, $?
@ys
ys / My_first_thought.rb
Created August 23, 2012 11:11
How would you align these kind of things in Ruby?
local_var.method_with_hash_and_block(
mandatory_param,
option_1: a,
option_2: blabla,
option_3: blablablablablabla,
option_4: bblablablablablablablabla,
option_5: bblablablabla,
) do |v|
d = v.bla
e = v.bla

JAPANESE ICED COFFEE

Materials

  • 30 grams of coffee
  • 250 grams of hot water
  • 250 grams of ice
  • Your favorite pour over device (Chemex, Hario V60, Beehouse Dripper, Kalita Wave, etc.)
  • A container to brew into (mug, Chemex, mason jar, serving carafe, etc.)
  • A filter
  • A scale
#! /usr/bin/env ruby
issue= ARGV.shift
current_branch = `git rev-parse --abbrev-ref HEAD`
default_branch = ENV.fetch("DEFAULT_BRANCH", "master")
origin_url = `git config --get remote.origin.url`
if origin_url.start_with?("git")
repo = origin_url.split(':')[1].split('.')[0]
else
repo = origin_url.sub('https://github.com/', '').split('.')[0]
@ys
ys / torrent
Created January 28, 2014 11:41
#! /usr/bin/env ruby
require 'transmission_api'
require 'pp'
class TorrentCli
def initialize(conf_file = "#{ENV['HOME']}/.torrent.conf")
@conf_file = conf_file
unless File.exist?(conf_file)
$stderr.puts "Config file does not exists. Default is : ~/.torrent.conf"
exit 1
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>{{ page.title }}</title>
<meta name="viewport" content="width=device-width">
<!-- syntax highlighting CSS -->
<link href='http://fonts.googleapis.com/css?family=PT+Sans+Narrow:400,700' rel='stylesheet' type='text/css'>
@ys
ys / padded.rb
Created December 13, 2013 15:11
#!/usr/bin/env ruby
def padded_tweet(message)
if message.size >= 140
return message[0..139]
end
if %w{. ! ? …}.include? message[-1]
return message.ljust(140, message[-1])
end
return message.ljust(140, '!')