Skip to content

Instantly share code, notes, and snippets.

@mashimom
mashimom / Solution.java
Created September 23, 2020 15:39
faster - longest substring without repeating characters
class Solution {
public int lengthOfLongestSubstring(String s) {
int r = 0;
Set<Character> set;
for(int i=0;i<s.length();i++) {
set = new HashSet<>();
int t = 0;
for(int j=i;j<s.length();j++){
if(set.contains(s.charAt(j))) break;
//*
// Target is to take strings representing binary numbers parcels,
// sum them (binary fashion) and return string representing the resulting binary number
// for the reference same code is one line in Clojure,
// which also works for arbritary number of parcels but it is limited by integer representation:
// <pre>(defn bin-sum [bns] (Integer/toString (apply + (map parse-bin bns)) 2))</pre>
//*
class Solution {
public String addBinary(String a, String b) {
int minLength = a.length() < b.length() ? a.length() : b.length();
@mashimom
mashimom / .gitattributes
Created July 18, 2020 09:57 — forked from amalloy/.gitattributes
Clojure-aware git-diff hunk headers
*.clj diff=clojure
*.cljs diff=clojure
*.cljx diff=clojure
#!/bin/sh
sudo apt-get install software-properties-common
sudo apt-add-repository ppa:ansible/ansible
sudo apt-get update
sudo apt-get install ansible
mkdir -p ~/.ansible/{host_vars,group_vars,roles}
wget -O ~/.ansible.cfg https://raw.githubusercontent.com/ansible/ansible/devel/examples/ansible.cfg
touch ~/.ansible/hosts
@mashimom
mashimom / ansible_install_ubuntu
Last active November 19, 2018 10:05
Install Ansible on Ubuntu
#!/bin/sh
sudo apt install python-setuptools python-dev build-essential
sudo easy_install pip
sudo pip install ansible
mkdir -p ~/.ansible/{host_vars,group_vars,roles}
wget -O ~/.ansible.cfg https://raw.githubusercontent.com/ansible/ansible/devel/examples/ansible.cfg
touch ~/.ansible/hosts
echo "[all]" >> ~/.ansible/hosts
@mashimom
mashimom / gist:ba1f31c53d722e037b55
Created July 20, 2015 17:10
Find a Linux process by partial name
pgrep -l xfce
## returns: 14306 xfce4-terminal
@mashimom
mashimom / Vagrantfile
Created June 20, 2015 19:13
Add a local cache to all apt, yum and npm operations (~/.vagrant.d/Vagrantfile)
Vagrant.configure("2") do |config|
config.vm.box = 'your-box'
if Vagrant.has_plugin?("vagrant-cachier")
# Configure cached packages to be shared between instances of the same base box.
# More info on http://fgrehm.viewdocs.io/vagrant-cachier/usage
config.cache.scope = :box
# OPTIONAL: If you are using VirtualBox, you might want to use that to enable
# NFS for shared folders. This is also very useful for vagrant-libvirt if you
# want bi-directional sync
@mashimom
mashimom / gist:0d0f58a65a2ab30aac75
Created May 11, 2015 11:47
ZSH alias for find using relative path with zsh globbing
alias prn="print -l $@"
@mashimom
mashimom / gist:518b70b6aab26d7b75d1
Last active August 29, 2015 14:20
ZSH alias for find using realpath with zsh globbing
alias fnd="realpath $@"
@mashimom
mashimom / gist:02033a6c3efe7bf11dab
Created May 9, 2015 16:12
Rsync without consuming all bandwidth
rsync <params like -vritzn> --bwlimit=8000 ./ <USER>@<HOSTNAME>:<PATH>