Skip to content

Instantly share code, notes, and snippets.

View zalom's full-sized avatar
😎
Building stuff

Zlatko Alomerovic zalom

😎
Building stuff
View GitHub Profile
@zalom
zalom / count-duplicates.rb
Last active May 9, 2016 08:26
Coding Test - Return a number of distinct values that occur two or more times in an array
# Count occurrences
# FIND DESCRIPTION BELOW THE CODE
def countDuplicates array
puts array.select{|x| array.count(x) > 1}
.each_with_object(Hash.new(0)) {|num,counts| counts[num] += 1}
.each_value.to_a.uniq
end
# Usage
# countDuplicates([1,3,1,4,5,6,3,2,4,4,6,7,6,7,8,8,9,7,7]);
@zalom
zalom / fizz-buzz.rb
Last active May 9, 2016 08:26
Coding Test - Fizz Buzz
# Fizz-Buzz Ruby
# FIND DESCRIPTION BELOW THE CODE
puts "Enter a number (integer): "
n = gets.chomp.to_i
i = 1
n.times do
if i%3 == 0 || i%5 ==0
if i%3 == 0 && i%5 == 0
puts "FizzBuzz"
@zalom
zalom / returnClass.js
Last active May 9, 2016 08:28
jQuey return each element's class
/* A function to return class for each Bootstrap navbar elements */
// FIND DESCRIPTION BELOW THE CODE
$(function() {
$( "#navbar" ).click(function() {
$( "ul li" ).each(function( index ) {
var class_name = $( this ).attr("class");
if( class_name === "active" || class_name === "inactive"){
console.log( index + ": " + $( this ).attr("class") );
}
@zalom
zalom / install_phantomjs.md
Created October 20, 2016 19:27
How to install PhantomJS 2.1.1

How to install PhantomJS on Ubuntu

Version: 2.1.1

Platform: x86_64

First, install or update to the latest system software.

sudo apt-get update
sudo apt-get install build-essential chrpath libssl-dev libxft-dev
@zalom
zalom / multiple_ssh_setting.md
Created December 18, 2016 14:16 — forked from jexchan/multiple_ssh_setting.md
Multiple SSH keys for different github accounts

Multiple SSH Keys settings for different github account

create different public key

create different ssh key according the article Mac Set-Up Git

$ ssh-keygen -t rsa -C "[email protected]"
@zalom
zalom / tmux-cheatsheet.markdown
Created April 8, 2017 12:34 — forked from MohamedAlaa/tmux-cheatsheet.markdown
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@zalom
zalom / download_egghead_videos.md
Last active July 8, 2017 21:53 — forked from christiangenco/download_egghead_videos.md
download egghead videos

Download videos from egghead

  1. Install the React Developer Tools Chrome Extension.

  2. Go to the egghead website, i.e. Getting Started with Redux

  3. Click View -> Developer -> Javascript Console, then the React tab, then

    1. Click on <NextUpLessonList ...> tag.
    2. If the first option is not available then find and click on a <_ listType="course" list={... > tag or enter lessons in a search field and look for <inject-t-with-lessonScreenStore lessons=[{...}, {...}, {...}, ...] in results list (and then click on it).
@zalom
zalom / Samsung_SyncMaster_2233BW_on_Ubuntu_16_04.md
Last active April 28, 2017 09:41
Add correct screen resolution for a connected Samsung SyncMaster 2233BW on Ubuntu 16.04

Set of terminal directives for adding a correct screen resolution for a connected Samsung SyncMaster 2233BW on Ubuntu 16.04

Check for the correct device that is connected

  xrandr

Create the correct resolution (this one is for Samsung SyncMaster 2233BW)

 sudo cvt 1680 1050 75
@zalom
zalom / setup.md
Created July 5, 2017 16:57 — forked from chris-jamieson/setup.md
Set up Franz for Ubuntu
  • Download Franz for your distribution from MeetFranz.com
  • change into the same directory as the downloaded file, then sudo tar -xf Franz-linux-x64-0.9.10.tgz -C /opt/franz
  • (optional) wget "https://cdn-images-1.medium.com/max/360/1*v86tTomtFZIdqzMNpvwIZw.png" -O franz-icon.png then sudo cp franz-icon.png /opt/franz
  • (optional) sudo touch /usr/share/applications/franz.desktop then sudo vim /usr/share/applications/franz.desktop

paste the following lines into the file, then save the file:

[Desktop Entry]
Name=Franz
Comment=
@zalom
zalom / rails-jsonb-queries
Created June 5, 2020 19:12 — forked from mankind/rails-jsonb-queries
Rails-5 postgresql-9.6 jsonb queries
http://stackoverflow.com/questions/22667401/postgres-json-data-type-rails-query
http://stackoverflow.com/questions/40702813/query-on-postgres-json-array-field-in-rails
#payload: [{"kind"=>"person"}]
Segment.where("payload @> ?", [{kind: "person"}].to_json)
#data: {"interest"=>["music", "movies", "programming"]}
Segment.where("data @> ?", {"interest": ["music", "movies", "programming"]}.to_json)
Segment.where("data #>> '{interest, 1}' = 'movies' ")
Segment.where("jsonb_array_length(data->'interest') > 1")