Skip to content

Instantly share code, notes, and snippets.

View malina's full-sized avatar
🌴

Alexandr Shumov malina

🌴
View GitHub Profile
@malina
malina / combinations.js
Created August 30, 2018 10:26 — forked from axelpale/combinations.js
JavaScript functions to calculate combinations of elements in Array.
/**
* Copyright 2012 Akseli Palén.
* Created 2012-07-15.
* Licensed under the MIT license.
*
* <license>
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
@malina
malina / Git push deployment in 7 easy steps.md
Created August 20, 2018 09:20 — forked from thomasfr/Git push deployment in 7 easy steps.md
7 easy steps to automated git push deployments. With small and configurable bash only post-receive hook
@malina
malina / Angular 6 HMR
Created August 15, 2018 15:54 — forked from A-STAR/Angular 6 HMR
Angular 6 HMR
Работает hmr, вот мой краткий вариант инструкции:
npm install --save-dev @angularclass/hmr
src/environments/environment.prod.ts
Добавить поле: hmr: false
src/environments/environment.ts
Добавить поле: hmr: true
package.json
@malina
malina / deploy.rake
Created April 27, 2018 12:49 — forked from ndbroadbent/deploy.rake
Rake task for precompiling assets locally before deploying to Heroku
require 'fileutils'
# Warning: The following deploy task will completely overwrite whatever is currently deployed to Heroku.
# The deploy branch is rebased onto master, so the push needs to be forced.
desc "Deploy app to Heroku after precompiling assets"
task :deploy do
deploy_branch = 'heroku'
remote = 'heroku'
deploy_repo_dir = "tmp/heroku_deploy"
@malina
malina / http_multipart_post.cr
Created April 16, 2018 10:55 — forked from decors/http_multipart_post.cr
Crystal-lang HTTP Multipart/form-data POST
require "http/client"
class MultiPartFormData
property io : IO::Memory
property size : Int32
def initialize(name, filename, file, boundary=nil)
@boundary = boundary || "boundary"
first = [boundary_line, content_disposition(name, filename), "", ""].join("\r\n")
last = ["", boundary_last, ""].join("\r\n")
@io = IO::Memory.new
@malina
malina / route_hooks.js
Created April 10, 2018 07:53 — forked from danielchappell/route_hooks.js
Ember.Route hook order
import Ember from 'ember';
// Ember 1.10
export default Ember.Route.extend({
//---fire in order on route enter---
beforeModel(transition) {
//empty by default
# -*- encoding : utf-8 -*-
class AddLowerUnaccentFunctionToDb < ActiveRecord::Migration
def self.up
execute "CREATE OR REPLACE FUNCTION lower_unaccent(character varying)
RETURNS text
AS $$
SELECT lower(translate($1
, '¹²³áàâãäåāăąÀÁÂÃÄÅĀĂĄÆćčç©ĆČÇĐÐèéêёëēĕėęěÈÊËЁĒĔĖĘĚ€ğĞıìíîïìĩīĭÌÍÎÏЇÌĨĪĬłŁńňñŃŇÑòóôõöōŏőøÒÓÔÕÖŌŎŐØŒř®ŘšşșߊŞȘùúûüũūŭůÙÚÛÜŨŪŬŮýÿÝŸžżźŽŻŹ'
, '123aaaaaaaaaaaaaaaaaaacccccccddeeeeeeeeeeeeeeeeeeeeggiiiiiiiiiiiiiiiiiillnnnnnnooooooooooooooooooorrrsssssssuuuuuuuuuuuuuuuuyyyyzzzzzz'
));
SELECT count(DISTINCT concat(page_views.id, page_views.visitor_id, atc_clicks.time::timestamp::date))
FROM page_views
INNER JOIN atc_clicks ON page_views.id = atc_clicks.page_view_id
WHERE atc_clicks.time::timestamp::date BETWEEN '2017-07-01' AND '2017-07-31';
@malina
malina / gist:1846e896dbed10d41d3977b68a96cdde
Created March 2, 2018 04:55 — forked from cpjolicoeur/gist:3590737
Ordering a query result set by an arbitrary list in PostgreSQL

I'm hunting for the best solution on how to handle keeping large sets of DB records "sorted" in a performant manner.

Problem Description

Most of us have work on projects at some point where we have needed to have ordered lists of objects. Whether it be a to-do list sorted by priority, or a list of documents that a user can sort in whatever order they want.

A traditional approach for this on a Rails project is to use something like the acts_as_list gem, or something similar. These systems typically add some sort of "postion" or "sort order" column to each record, which is then used when querying out the records in a traditional order by position SQL query.

This approach seems to work fine for smaller datasets, but can be hard to manage on large data sets with hundreds (or thousands) of records needing to be sorted. Changing the sort position of even a single object will require updating every single record in the database that is in the same sort group. This requires potentially thousands of wri

@malina
malina / keymap.cson
Created February 14, 2018 04:24 — forked from rezapadillah/keymap.cson
Enable Emmet In laravel blade and vue language on atom
1. Go to keymap.cson on your atom editor
2. Copy and paste :
'atom-text-editor[data-grammar="text html php blade"]:not([mini])':
'tab': 'emmet:expand-abbreviation-with-tab'
'atom-text-editor[data-grammar~="vue"]:not([mini])':
'tab': 'emmet:expand-abbreviation-with-tab'