Skip to content

Instantly share code, notes, and snippets.

@akotlov
akotlov / Camera2.md
Created September 12, 2018 05:49 — forked from Tanapruk/Camera2.md
Camera2 API

TextureView

You need to initialize TextureView before opening a camera. TextureView is for displaying the image from camera on the device. However, you cannot use it unless the texture is ready, either because the screen is currently off or it is initializing.

You should check mTextureView.isAvailable() before opening your camera. Else you will mTextureView.setSurfaceTextureListener(). And open your camera in the callback method onSurfaceTextureListener.

Camera

Before opening your camera you should check for a camera permission first.

@akotlov
akotlov / difference.js
Created August 29, 2018 05:34 — forked from Yimiprod/difference.js
Deep diff between two object, using lodash
/**
* Deep diff between two object, using lodash
* @param {Object} object Object compared
* @param {Object} base Object to compare with
* @return {Object} Return a new object who represent the diff
*/
function difference(object, base) {
function changes(object, base) {
return _.transform(object, function(result, value, key) {
if (!_.isEqual(value, base[key])) {
@akotlov
akotlov / postgres-notify-trigger.sql
Created August 21, 2018 04:13 — forked from bithavoc/postgres-notify-trigger.sql
I used this trigger to notify table changes via NOTIFY (migrating off RethinkDB)
CREATE OR REPLACE FUNCTION notify_trigger() RETURNS trigger AS $$
DECLARE
channel_name varchar DEFAULT (TG_TABLE_NAME || '_changes');
BEGIN
IF TG_OP = 'INSERT' THEN
PERFORM pg_notify(channel_name, '{"id": "' || NEW.id || '"}');
RETURN NEW;
END IF;
IF TG_OP = 'DELETE' THEN
PERFORM pg_notify(channel_name, '{"id": "' || OLD.id || '"}');
@akotlov
akotlov / osx.sh
Created May 7, 2018 19:37 — forked from rfunduk/osx.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with useful tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2263406/osx.sh | sh
#
@akotlov
akotlov / constructor-async.js
Created April 22, 2018 20:59 — forked from christophemarois/constructor-async.js
Async properties in JS Class constructor
// For demonstration purposes
async function getHTML () {
if (Math.random() > 0.5) {
return 'Randomly succeeded'
} else {
throw new Error('Randomly failed')
}
}
// Checks that an instance promise didn't resolve with an error,
@akotlov
akotlov / etc-init.d-redis.conf
Created August 16, 2017 05:49 — forked from sairam/etc-init.d-redis.conf
Redis is an open source, BSD licensed, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets. This works on Fedora. After adding the description for chkconfig the error "service redis_6379 does not support chkconfig" disappeared.
#!/bin/sh
#
# redis - this script starts and stops the redis daemon
#
# chkconfig: - 85 15
# description: Redis is an open source, BSD licensed, advanced \
# key-value store. It is often referred to as a \
# data structure server since keys can contain \
# strings, hashes, lists, sets and sorted sets.
# processname: redis
@akotlov
akotlov / install-redis.sh
Created August 16, 2017 04:43 — forked from FUT/install-redis.sh
Install Redis on EC2
1. Install Linux updates, set time zones, followed by GCC and Make
sudo yum -y update
sudo ln -sf /usr/share/zoneinfo/America/Indianapolis \
/etc/localtime
sudo yum -y install gcc make
2. Download, Untar and Make Redis 2.8 (check here http://redis.io/download)
// Port, host and auth token of Redis server might be defined as environment
// variables. If not, fall back to defaults.
var redisPort = process.env.REDIS_PORT || 6379,
redisHost = process.env.REDIS_HOST || '127.0.0.1',
redisAuth = process.env.REDIS_AUTH || null,
redis = require('redis');
// Since we are waiting for the error event, we don't have to check for errors
// individually after each Redis command.
var onError = function (error) {
@akotlov
akotlov / redis.md
Created August 8, 2017 03:22 — forked from federico-garcia/redis.md
Redis

Redis

Redis stands for REmote DIctionary Server. By default, redis stores all data in memory. It's a key-structure database. redis-server is the actual datastore. redis-cli is the command line interface that performs any redis command. By default, redis binds to port 6379.

Starting the redis server

redis-server

While you can build a complete system using Redis only, I think most people will find that it supplements their more generic data solution - whether that be a traditional relational database, a document-oriented system, or something else. It’s the kind of solution you use to implement specific features.

@akotlov
akotlov / http_streaming.md
Created August 6, 2017 19:25 — forked from CMCDragonkai/http_streaming.md
HTTP Streaming (or Chunked vs Store & Forward)

HTTP Streaming (or Chunked vs Store & Forward)

The standard way of understanding the HTTP protocol is via the request reply pattern. Each HTTP transaction consists of a finitely bounded HTTP request and a finitely bounded HTTP response.

However it's also possible for both parts of an HTTP 1.1 transaction to stream their possibly infinitely bounded data. The advantages is that the sender can send data that is beyond the sender's memory limit, and the receiver can act on