Skip to content

Instantly share code, notes, and snippets.

@akotlov
akotlov / Date Range Mongo Query
Created July 31, 2016 20:40 — forked from guilleferrer/Date Range Mongo Query
Query for a date range using Mongo Timestamps
db.Collection.find({
created_at : {
'$gte': new Timestamp(new Date(2012, 0, 21), 0),
'$lte': new Timestamp(new Date(2012, 0, 22), 0)
})
@akotlov
akotlov / Iframe.js
Created July 18, 2017 20:46 — forked from msmfsd/Iframe.js
React iframe component
/*
INIT: ensure Babel/Eslint/Flow is configured for ES Class Fields & Static Properties
JSX USAGE: <Iframe src='http://web.site' onLoad={myOnloadFunction}/>
*/
import React, { Component, PropTypes } from 'react'
import ReactDOM from 'react-dom'
class Iframe extends Component {
static propTypes: Object = {
@akotlov
akotlov / gist:3ae1093971b285dfe7d5134408fbdfab
Created July 25, 2017 07:58 — forked from tonymtz/gist:d75101d9bdf764c890ef
Uninstall nodejs from OSX Yosemite
# first:
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.pkg.bom | while read f; do sudo rm /usr/local/${f}; done
sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*
# To recap, the best way (I've found) to completely uninstall node + npm is to do the following:
# go to /usr/local/lib and delete any node and node_modules
cd /usr/local/lib
sudo rm -rf node*
@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

@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.

// 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 / 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)
@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 / 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 / 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
#