Skip to content

Instantly share code, notes, and snippets.

View veelenga's full-sized avatar
🇺🇦
Annihilating code

Vitalii Elenhaupt veelenga

🇺🇦
Annihilating code
View GitHub Profile
@veelenga
veelenga / currency.sh
Last active July 5, 2016 09:45
i3blocks script gist for displaying current currency ratio from Google's finance convertor
#!/bin/sh
# Copyright (C) 2014 Vitaliy Elengaupt <velenhaupt@gmail.com>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
@veelenga
veelenga / git_notes.md
Last active November 20, 2015 06:00
git notes
@veelenga
veelenga / hgArtifacts.py
Created June 25, 2015 06:18
Tiny Python script to load files from Mercurial repository
from optparse import OptionParser
from subprocess import call
from subprocess import check_output
import urllib
import re
import os
import sys
import shutil
def getUrlCode(url):
@veelenga
veelenga / tap_and_itself.cr
Created September 24, 2015 10:18
Methods tap and itself in Crystal (for blogpost http://veelenga.com/tap-and-itself-methods-in-crystal/)
################################################################################
p 10.itself # 10
p "1".itself # "1"
p :sym.itself # :sym
p true.itself # true
p nil.itself # nil
p [1, 2].itself # [1, 2]
p ({"1" => "2"} of String => String).itself # {"1" => "2"}
p /1/.itself # /1/
@veelenga
veelenga / benchmark_test.cr
Last active October 3, 2015 19:50
Benchmarking in Crystal (for blogpost http://veelenga.com/benchmarking-in-crystal/)
require "benchmark"
puts ">> Array#[] vs Array#[]?"
arr = Array.new(1000, 1)
Benchmark.ips do |x|
x.report("Array#[]" ) { arr[500] }
x.report("Array#[]?") { arr[500]? }
end
puts ">> Interpolation vs Int32#to_s"
@veelenga
veelenga / import_export_mysql.md
Created December 10, 2015 10:48
Import/export mysql db

Create db dump:

mysqldump -u user -p db_name > db_name.sql

Restore db dump:

mysql -u user -p db_name < db_name.sql

@veelenga
veelenga / crystal_christmas_tree.txt
Last active March 9, 2024 18:02
Crystal Christmas Tree
$$$
crystal
crystal run
crystal build
crystal version
@veelenga
veelenga / mongo.sh
Last active December 25, 2015 15:14
MongoDB export/import database
# create dump of the database on remote server
$ mongodump --host remote_host --db database_name
# import into database on localhost
$ mongorestore --host localhost --dir dump/database_name/ --db database_name --drop
@veelenga
veelenga / leftpad.cr
Last active March 24, 2016 21:10
left-pad for Crystal
class String
def leftpad(len : Int, char = ' ')
char, len = char.to_s, len - self.size
raise ArgumentError.new if char.size != 1
len > 0 ? (char * len + self) : self
end
end