Skip to content

Instantly share code, notes, and snippets.

View nilcolor's full-sized avatar
💫
API by day, IPA by night

Alexey Blinov nilcolor

💫
API by day, IPA by night
View GitHub Profile
@nilcolor
nilcolor / Node.js CORS
Created February 8, 2011 15:28
Node.js cross-origin POST. You should response for OPTIONS request first. Something like this.
if (req.method === 'OPTIONS') {
console.log('!OPTIONS');
var headers = {};
// IE8 does not allow domains to be specified, just the *
// headers["Access-Control-Allow-Origin"] = req.headers.origin;
headers["Access-Control-Allow-Origin"] = "*";
headers["Access-Control-Allow-Methods"] = "POST, GET, PUT, DELETE, OPTIONS";
headers["Access-Control-Allow-Credentials"] = false;
headers["Access-Control-Max-Age"] = '86400'; // 24 hours
headers["Access-Control-Allow-Headers"] = "X-Requested-With, X-HTTP-Method-Override, Content-Type, Accept";
@nilcolor
nilcolor / Makefile
Created December 25, 2018 21:43 — forked from mpneuried/Makefile
Simple Makefile to build, run, tag and publish a docker containier to AWS-ECR
# import config.
# You can change the default config with `make cnf="config_special.env" build`
cnf ?= config.env
include $(cnf)
export $(shell sed 's/=.*//' $(cnf))
# import deploy config
# You can change the default deploy config with `make cnf="deploy_special.env" release`
dpl ?= deploy.env
include $(dpl)
@nilcolor
nilcolor / Intro to Common Table Expressions.md
Created July 30, 2018 13:23 — forked from felixyz/Intro to Common Table Expressions.md
Introduction to transitive closure / Common Table Expressions / iterative queries in SQL

Teh Social Netswork!

CREATE TABLE users (
 id SERIAL PRIMARY KEY,
 name VARCHAR(10) NOT NULL
);

INSERT into users VALUES

#!/bin/bash
# Description: This script spins up a multi node Docker Swarm w/ Docker
# Networking and Consul discovery w/ Registrator
# Author: Ryan C Koch
# ryanckoch@gmail.com
# Usage: bash docker-playground.sh usage
PLAYGROUND_NAME="docker-playground"
CONSUL_IMAGE="progrium/consul"
@nilcolor
nilcolor / ajax-file-upload.js
Created July 3, 2012 11:14
Upload file using FormData (a-la AJAX file upload using XMLHTTPRequest2)
function sendForm() {
var fileData = new FormData(document.getElementById("cpd-file"));
var xhr = new XMLHttpRequest();
xhr.open("POST", "/upload_file", true);
xhr.setRequestHeader('Accept', 'application/json');
xhr.onload = function(progressEvent) {
if (xhr.status == 200) {
console.log('Uploaded', xhr);
} else {
@nilcolor
nilcolor / paperclip.rb
Created August 5, 2016 21:03
Paperclip [0] patch
#/config/initializers/paperclip.rb
require 'paperclip/geometry_detector_factory'
require 'paperclip/thumbnail'
# HACK: Monkey patch to remove `[0]` from the end of filename.
# Actual until https://github.com/thoughtbot/paperclip/issues/2223
# rubocop:disable all
module Paperclip
class GeometryDetector
private
class Fixnum
LONG_MAX = ( (2 ** (64 - 2)) - 1 )
INT_MAX = ( (2 ** (32 - 2)) - 1 )
if LONG_MAX.class == Fixnum
N_BYTES = 8
N_BITS = 64
MAX = LONG_MAX
MIN = -MAX - 1
else
desc 'rolls back migrations in current branch not present in other'
task :rollback_branch_migrations, [:other_branch] do |t, args|
load "#{Dir.pwd}/Rakefile"
branch_migrations = BranchMigrations.new(args.other_branch)
puts ['Rollback the following migrations', branch_migrations, 'y,n? ']
next if %w[no n NO N].include?(STDIN.gets.chomp)
migrate_task = Rake::Task['db:migrate:down']
@nilcolor
nilcolor / gem-reset
Created September 25, 2013 08:33 — forked from nixpulvis/gem-reset
#!/usr/bin/env ruby
# Remove all gems EXCEPT defaults :)
`gem list -d`.split(/\n\n^(?=\w)/).each do |data|
match = data.match(/(?<name>([^\s]+)) \((?<versions>.*)\)/)
name = match[:name]
versions = match[:versions].split(', ')
if match = data.match(/^.*\(([\d\.]*),? ?default\): .*$/)
next if match[1].empty? # it's the only version if this match is empty
@nilcolor
nilcolor / gist:5705072
Last active December 18, 2015 01:39 — forked from chen206/gist:4030441
#!/bin/bash
#
# Install Postgres 9.2 on a clean Ubuntu 12.04
"""
LC_ALL issue
comment out the AcceptEnv LANG LC_* line in the remote /etc/ssh/sshd_config file.
sudo apt-get install language-pack-en-base
sudo dpkg-reconfigure locales
comment out the SendEnv LANG LC_* line in the local /etc/ssh/ssh_config file.