Skip to content

Instantly share code, notes, and snippets.

@janzikan
janzikan / results.txt
Created June 19, 2018 08:23
Ruby: sum vs inject benchmark
Ruby version 2.4.1
Sum of 100 numbers
Warming up --------------------------------------
sum 190.410k i/100ms
inject 184.380k i/100ms
Calculating -------------------------------------
sum 3.303M (± 1.5%) i/s - 33.131M in 10.034500s
inject 3.046M (± 1.7%) i/s - 30.607M in 10.050375s
@janzikan
janzikan / json.rb
Created June 19, 2018 07:51
Ruby: yajl vs oj benchmark
require 'benchmark/ips'
require 'oj'
require 'yajl'
FILENAME = 'tweet.json'.freeze
json = File.read(FILENAME)
Benchmark.ips do |x|
x.config(time: 20, warmup: 2)
@janzikan
janzikan / stopwatch.rb
Created November 21, 2017 13:32
Ruby: Measure execution time of your code
def stopwatch(cycles = 1)
cycles = cycles.to_i
return if cycles == 0
start = Time.now.to_f
cycles.times do
yield
end
@janzikan
janzikan / cachematrix.R
Created May 17, 2017 15:56
R: Generate inverse matrix witch caching
# Provide getter and setter methods for the given matrix and its
# inverse that is cached in a variable.
makeCacheMatrix <- function(x = matrix()) {
# Variable used for caching
inverse <- NULL
# Set
set <- function(y) {
x <<- y
@janzikan
janzikan / mastodon_stats.gs
Created April 21, 2017 08:18
Google Apps Script: Mastodon stats scraping
function addData() {
var values = fetchStats();
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
sheet.appendRow([currentDateTime(), values[0], values[1]]);
}
function fetchStats() {
var url = 'https://instances.mastodon.xyz/list';
var content = UrlFetchApp.fetch(url).getContentText();
@janzikan
janzikan / deploy_jekyll.rake
Created July 18, 2015 07:30
Rake: task for deployment of jekyll site
task :deploy do
command = "jekyll build && \
git push origin master && \
rsync -avz --delete _site/ [SERVER]:/var/www/[PROJECT_DIR]"
sh command
end
@janzikan
janzikan / post-receive
Created July 16, 2015 12:13
Git: deployment with post receive hook
#!/bin/sh
unset GIT_DIR
cd /var/www/[PROJECT_DIR] && git pull origin master
@janzikan
janzikan / git_stats.rb
Created November 14, 2014 15:00
Ruby: Git statistics
#!/usr/bin/env ruby
require 'optparse'
require 'optparse/date'
options = {}
parser = OptionParser.new do |opts|
opts.banner = 'Usage: git_stats.rb [options]'
@janzikan
janzikan / send_email.vbs
Created May 4, 2014 06:19
VBS: Send email
'****CONFIGURE THE FROM EMAIL ADDRESS AND PASSWORD
Const fromEmail = "username@gmail.com"
Const password = "password"
'****END OF CONFIGURATION
Dim emailObj, emailConfig
Set emailObj = CreateObject("CDO.Message")
emailObj.From = fromEmail
@janzikan
janzikan / bck_mysql
Last active November 22, 2015 01:27
Backup MySQL databases
#!/bin/bash
cd [backup_folder]
today=`date +%Y-%m-%d`
filename="mysql/mysql-$today.sql"
# Backup all databases
# mysqldump -u [username] -p[password] --all-databases > $filename