Skip to content

Instantly share code, notes, and snippets.

@mimikadze
mimikadze / gist:27002e219c23bbec5a626a6a47f06129
Created April 16, 2017 12:02
Sample NGINX config for rails app
upstream application {
server unix:/tmp/example_puma.sock fail_timeout=0;
}
# Optional redirect
#server {
# listen 80;
# server_name www.DOMAIN default;
# return 301 $scheme://DOMAIN$request_uri;
#}
@mimikadze
mimikadze / ramdisk.sh
Created November 29, 2016 07:28 — forked from rxin/ramdisk.sh
ramdisk create/delete on Mac OS X.
#!/bin/bash
# From http://tech.serbinn.net/2010/shell-script-to-create-ramdisk-on-mac-os-x/
#
ARGS=2
E_BADARGS=99
if [ $# -ne $ARGS ] # correct number of arguments to the script;
then
{
"always_show_minimap_viewport": true,
"color_scheme": "Packages/Material Theme/schemes/Material-Theme.tmTheme",
"enable_tab_scrolling": false,
"ensure_newline_at_eof_on_save": true,
"font_options":
[
"gray_antialias"
],
"font_size": 13,
@mimikadze
mimikadze / gist:38fe425151c017ea464d6c3da6ba7106
Created September 30, 2016 10:58
Clean the system from all unnamed Docker images
docker rm $(docker ps -a | grep Exited | awk '{print $1}')
docker rmi $(docker images -f "dangling=true" -q)
@mimikadze
mimikadze / gist:707c133427e3f71484066149d8233184
Created September 28, 2016 08:07
searchkick livesearch fix for Eugeniy
<%= form_tag root_path, :method => 'get' do %>
<div id="remote">
<input class="typeahead" type="text" name="query" placeholder="Choose the book">
</div>
<div class="col-md-1">
<button type="submit" class="btn btn-default">
<% end %>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
@mimikadze
mimikadze / gist:d0cc268c8c1f307c604be08fca2084fd
Created July 2, 2016 09:23
Material Theme for Midnight Commander
# Start with export LC_ALL=C && mc on OSX
[skin]
description = Solarized (mostly) dark skin for Midnight Commander.
256colors = true
[Lines]
horiz = ─
vert = │
lefttop = ┌
righttop = ┐
Even sums is a game for two players. Players are given a sequence of N positive integers and take turns alternately. In each turn, a player chooses a non-empty slice (a subsequence of consecutive elements) such that the sum of values in this slice is even, then removes the slice and concatenates the remaining parts of the sequence. The first player who is unable to make a legal move loses the game.
You play this game against your opponent and you want to know if you can win, assuming both you and your opponent play optimally. You move first.
Write a function:
def solution(a)
that, given a zero-indexed array A consisting of N integers, returns a string of format "X,Y" where X and Y are, respectively, the first and last positions (inclusive) of the slice that you should remove on your first move in order to win, assuming you have a winning strategy. If there is more than one such winning slice, the function should return the one with the smallest value of X. If there is more than one slice with the smallest
A new kind of cannon is being tested. The cannon shoots cannonballs in a fixed direction. Each cannonball flies horizontally until it hits the ground, and then it rests there. Cannonballs are shot from different heights, so they hit the ground at different points.
You are given two zero-indexed arrays, A and B, containing M and N integers respectively. Array A describes the landscape in the direction along which the cannon is shooting. Elements of array A represent the height of the ground, going from the cannon outwards. Array B contains levels from which consecutive cannonballs are shot.
Assume that a cannonball is shot at level H.
Let I be the smallest index, such that 0 < I < M and A[I] ≥ H. The cannonball falls at position I − 1 and increases the ground level A[I−1] by 1.
If there is no such I, and H > A[I] for all 0 ≤ I < M, then the cannonball flies beyond the horizon and has no effect on the result.
If H ≤ A[0], then the cannonball ricochets away and has no effect on the result either.
Write a func
#!/usr/bin/env ruby
require "rubygems"
require "bundler/setup"
ROOT = Pathname.new(::File.expand_path('../', __FILE__))
ENVIRONMENT = ENV.fetch('STAGE', 'development')
Bundler.require :default, ENVIRONMENT
Dotenv.load ROOT.join(".env")
@mimikadze
mimikadze / gist:5f56e291a9b6b23958fdff245cfbceef
Created May 13, 2016 09:35
Show all users in the POSIX-compliant system
cat /etc/passwd | cut -d ":" -f1