Skip to content

Instantly share code, notes, and snippets.

View sitano's full-sized avatar

Ivan Prisyazhnyy sitano

View GitHub Profile
@sitano
sitano / gist:a9260aac7bd40bc5310b
Created May 25, 2015 10:41
diff for github.com/cznic/ql, issue99_test, a8fb57c..cb5e47f
diff --git a/issue99_test.go b/issue99_test.go
index a8fb57c..cb5e47f 100644
--- a/issue99_test.go
+++ b/issue99_test.go
@@ -10,6 +10,8 @@ import (
"strconv"
"strings"
"sync"
+ "time"
+ "fmt"
@sitano
sitano / gist:bed03bc66f56a71570a5
Last active August 29, 2015 14:22
modified fibonacci, O(n^1.58), Karatsuba algorithm, Fast SQR = (x*b + y)^2, where len(x) = len(y) +/- 1
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
using namespace std;
#define assert(x) ((void)(!(x) && (cout << "ERROR: at " << __FILE__ << ":" << __LINE__ << " " << #x << endl)))
@sitano
sitano / gist:2123d9ae297b641fafef
Last active April 17, 2021 03:09
nginx cors with if multiple conditions with http basic auth
location ~* /cache/ {
proxy_pass http://127.0.0.1:8000;
if ($http_origin ~* "^https?://(dev|admin|www)\.site\.com$" ) {
set $cors "A";
}
if ($request_method = 'OPTIONS') {
set $cors "${cors}B";
}
@sitano
sitano / redis.conf
Created July 16, 2015 14:18
docker upstart redis startup script
description "Redis container"
author "Ivan Prisyazhnyy"
start on filesystem and started docker
stop on runlevel [!2345] or stopping docker
# Docker has a timeout of 10 seconds so as long as this
# is longer so we don't kill the wait process
kill timeout 20
@sitano
sitano / nginx.conf
Last active August 29, 2015 14:25
openrusty nginx lua http traffic replication with multiple capture example
worker_processes 2;
events {
worker_connections 1024;
}
http {
access_log /dev/stderr combined;
keepalive_timeout 65;
@sitano
sitano / redis-server.conf
Created July 30, 2015 09:24
redis-server simple upstart script
start on runlevel [2345]
stop on runlevel [!2345]
respawn
respawn limit 3 5
kill timeout 10
limit nofile 65535 65535
setuid redis
@sitano
sitano / ansible-common-default.yaml
Created July 30, 2015 15:27
ansible task example on how to setup kernel.mm.transparent_hugepage (block) if it exists
# file: roles/common/tasks/item.yml
- name: be sure basic packages are installed
apt: pkg={{item}} state=latest update_cache=yes
tags: common
with_items:
- git
- subversion
- vim
- block:
@sitano
sitano / recover-bst-on.cc
Created October 25, 2015 19:41
Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing its structure.
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
@sitano
sitano / recover-bst-o1.cc
Last active October 25, 2015 19:46
O(1) space solution using Morris single threaded tree traversal to: two elements of a binary search tree (BST) are swapped by mistake, recover the tree without changing its structure.
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
class Solution {
public:
void solveSudoku(vector<vector<char>>& board) {
for (int row = 0; row < 9; row ++) {
auto rowi = &board[row];
for (int col = 0; col < 9; col ++) {
if ((*rowi)[col] == '.') {
for (char a = '1'; a <= '9'; ++ a) {
if (can(board, col, row, a)) {
(*rowi)[col] = a;