Skip to content

Instantly share code, notes, and snippets.

@jvmvik
jvmvik / disk.md
Last active January 26, 2021 21:06
File, images, management...

Search for file duplicates.

$> fdupes

Find file > 10M

$> find . -type f -size +10M

@jvmvik
jvmvik / curl.md
Last active May 3, 2020 01:29
Curl

Pratical CURL commands

return not 0 exit code if http status != 200

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
@jvmvik
jvmvik / bash_tar.rb
Last active November 14, 2019 15:44
Run tar in parallel
#!/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
@jvmvik
jvmvik / gogrep.go
Created October 9, 2019 13:10
Draft to create a parallel grep using channel
// 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()
@jvmvik
jvmvik / Hash.from_xml
Created August 8, 2019 21:17 — forked from huy/Hash.from_xml
Convert xml to hash using Nokogiri
# 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)
@jvmvik
jvmvik / Makefile
Created March 6, 2019 13:47
Makefile tips
# Makefile flash card
#
# check if file exist
ifneq ("$(wildcard $(path))","")
FILE_EXISTS = 1
else
FILE_EXISTS = 0
endif
@jvmvik
jvmvik / Rakefile
Created February 1, 2019 04:30
Rakefile + ERB with better error handling
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)
@jvmvik
jvmvik / rip_cd_audio.rb
Created January 20, 2019 02:04
Rip Audio CD on Linux / Debian / Ubuntu in command line
#!/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
@jvmvik
jvmvik / fib.rb
Last active January 14, 2019 03:19
Simple fibonnaci benchmark written in Ruby. To help established based line..
# simple fibonnaci benchmark
#
require 'benchmark'
def fib(n)
if n == 1
1
elsif n == 2
1
else
@jvmvik
jvmvik / mongodb_basic.rb
Created January 4, 2019 02:56
Show basic usage of mongoDB ruby driver
require 'mongo'
client = Mongo::Client.new("mongodb://localhost:27017", {database: 'test'})
db = client.db
# Show all collection
db.collection_names
# Count number of document
db["searches"].count()