Skip to content

Instantly share code, notes, and snippets.

@lolgear
lolgear / replace_tabs_with_spaces_in_swift_files.sh
Created Sep 29, 2019
Shell command to replace tabs with spaces ( 4 count in example ) in files matching pattern ( swift files )
View replace_tabs_with_spaces_in_swift_files.sh
find . -name '*.swift' | perl -ple 's/ /\\ /g' | xargs perl -i -lpe 's/^\t/ /g'
@lolgear
lolgear / find_headers_and_move_them_to_one_directory.sh
Created Jun 29, 2019
Search in a directory Core and put all headers in one directory Core/Include
View find_headers_and_move_them_to_one_directory.sh
find Core -name '*.h' | perl -ne 'chomp; my $f = (split("\/"))[-1]; my $s = qq(mv $_ Core/Include/$f); print $s, "\n"; print qx($s);'
@lolgear
lolgear / [Proposal] Allow default parameter in generic class definition.md
Last active Mar 20, 2018
[Proposal] Allow default values for parameters in generic clause
View [Proposal] Allow default parameter in generic class definition.md

[Proposal] Allow default values for parameters in generic clause

During the review process, add the following fields as needed:

@lolgear
lolgear / scrivener_rename_jekyll_blog_post_to_metadata_title.rb
Last active Mar 6, 2018
Scrivener post-processing script which rename generated file into Jekyll post naming convention.
View scrivener_rename_jekyll_blog_post_to_metadata_title.rb
#!/usr/bin/ruby
# This script rename blog-post to jekyll conventions naming.
# Suppose, that you have a file with metadata content.
# File.txt:
# ---
# title:'Wow, title. Rename blog-post.'
# date:26.01.2018 12:31:55 GMT+3
# ---
# ruby script.rb -i File.txt
@lolgear
lolgear / simpsons_heights_ios_resource_counter.rb
Created Oct 27, 2017
This is simple resource counter that count an amount of time to produce the specific resource represented as vector
View simpsons_heights_ios_resource_counter.rb
# Space describe the dependencies between coordinates
class Space
attr_accessor :basis, :normalized_basis
def add(lhs, rhs)
# pp "left -> #{lhs}"
# pp "right -> #{rhs}"
max = [lhs.count, rhs.count].max
result = Array.new(max, 0).each_with_index.map { |e, i|
# puts "left -> #{lhs[i]} right -> #{rhs[i]} e -> #{e}"
e += lhs[i] if i < lhs.count
View GitPages_new_post_date.sh
date +"%Y-%m-%d %H:%M:%S %z" | pbcopy
View remove_image_background_not_white_color_with_threshold.sh
ls Resources/*.png | perl -lne '$old = $_; s/(\@\w+)/_inverted$1/; $_ = qx(basename $_); chomp; $_ = qq(Results/$_); $s = qq(convert $old -fuzz 10% -fill none +opaque white $_); print $s; print qx($s);'
# 1. details:
# 2. take png images from directory Resources
# 3. append "_inverted" before \@ symbol.
# 4. convert $old -fuzz 10% -fill none +opaque white $new
# 5. -fuzz add threshold in 10% for white color. Which are NOT white in 10% thresholds would be removed.
# 6. -fill none should fill color with transparent color
# 7. +opaque matches color to be replaced. plus add inversion. So, +opaque matches these colors that SHOULD NOT be replaced.
@lolgear
lolgear / CoreDataDatabaseCleanup.m
Created Mar 17, 2017
Core data database cleanup
View CoreDataDatabaseCleanup.m
/*
For example, you use Core Data sqlite.
It is necessary, because sqlite database stores data in single file.
Whole database is single file.
Now you have two options.
1. Delete all data from all tables
2. Delete database sqlite file
Second option is clean but complex.
@lolgear
lolgear / git_format_commits_between_tags.sh
Created Feb 1, 2017
Output commits between two tags with format including date and sha and message
View git_format_commits_between_tags.sh
git log --format='%ad %h %B' 'TagName'..'HEAD' | perl -ne '/^\s+$/ or print;'
@lolgear
lolgear / git_single_file_revision_search.sh
Created Nov 23, 2016
Search Podfile.lock for specific pod commit updates.
View git_single_file_revision_search.sh
# $file = path to file;
# $name = ( name to search (actually, it is a regex) )
# EncryptedCoreData:
# - :commit: 5044489e622143d6efdb69fbbc383748618b5fe4
# + :commit: 4ca0977e9e0b610e6813886276bb7bbd9406335f
#
#
# Pod revision.
git log -p -- FILE | perl -lne '$name = 'PODNAM'; (/^\s+$name[\w-]*:\s*$/ .. /^\+\s+:commit:/) and print'
You can’t perform that action at this time.