curl --silent --show-error --fail URL
- --silent hides the progress and error
- --show-error shows the error message hidden by --silent
- --fail returns an exit code > 0 when the request fails
| # simple fibonnaci benchmark | |
| # | |
| require 'benchmark' | |
| def fib(n) | |
| if n == 1 | |
| 1 | |
| elsif n == 2 | |
| 1 | |
| else |
| #!/usr/bin/env ruby | |
| # | |
| # Convert CD to mp3 on Linux | |
| # | |
| # reference: https://www.cyberciti.biz/faq/linux-ripping-and-encoding-audio-files/ | |
| # | |
| # Run extraction with | |
| # cdparanoia -B | |
| # | |
| # Convert wav to mp3 with lame |
| require 'yaml' | |
| require 'erb' | |
| # render a template | |
| # @param [String] s template | |
| # @param [Binding] ctx binding context | |
| # @return [String] render output | |
| def render(s, ctx) | |
| begin | |
| erb = ERB.new(s) |
| # Makefile flash card | |
| # | |
| # check if file exist | |
| ifneq ("$(wildcard $(path))","") | |
| FILE_EXISTS = 1 | |
| else | |
| FILE_EXISTS = 0 | |
| endif |
| # USAGE: Hash.from_xml(YOUR_XML_STRING)require 'rubygems' | |
| require 'nokogiri' | |
| # modified from http://stackoverflow.com/questions/1230741/convert-a-nokogiri-document-to-a-ruby-hash/1231297#123129 | |
| 7 | |
| class Hash | |
| class << self | |
| def from_xml(xml_io) | |
| begin | |
| result = Nokogiri::XML(xml_io) |
| // Go grep parallel | |
| // https://golang.hotexamples.com/examples/codesearch.regexp/Grep/File/golang-grep-file-method-examples.html | |
| func main() { | |
| var g regexp.Grep | |
| g.AddFlags() | |
| g.Stdout = os.Stdout | |
| g.Stderr = os.Stderr | |
| flag.Usage = usage | |
| flag.Parse() |
| #!/usr/bin/env ruby | |
| # | |
| # run gtar in parallel | |
| # | |
| l = Dir.glob("summary/*") | |
| names = l.map { |e| File.basename(e[0]).split("_")[0] }.uniq | |
| list = names.map do |user| | |
| spawn(%Q(gtar cvf archive+#{user}_2019-11-14.tgz log/#{user}*.log)) | |
| end |
| /* | |
| * Generate gift paper from random images. | |
| */ | |
| package main | |
| import ( | |
| "fmt" | |
| "image" | |
| "image/jpeg" |