Skip to content

Instantly share code, notes, and snippets.

git config --global user.name "User Name" // set user name
git config --global user.email "user@email.com" // set user email
git config --list // show active settings
git help commit // open git manual in browser
cd c:/targetdir // change directory
git init // create git repository in this directory or reinit existing
git status // show info about files status (untracted / unmodified etc)
git add . // add all files to unmodified status
git commit -m "Comment" // commit files
git remote add origin https://github.com/user/repositoryName // set remote repository
@cubespace
cubespace / gist:6090fa961ada5fc5db96a66dd067a0f6
Created May 30, 2017 08:57 — forked from igorpronin/gist:14e289e0928d95917a58
cmd create network path and copy dir with includes
net use X: \\SERVER\Share
// привязать к расшареной папке на сетевом ресурсе имя диска (X)
xcopy C:\users D:\copy1 /H /Y /C /R /S
// скопировать все файлы и подкаталоги ( /S ) с перезаписью существующих без запроса ( /Y ) , включая скрытые и системные. ( /H ) с перезаписью файлов с атрибутом "Только чтение" (/R) и игнорированием ошибок ( /C )
npm install rimraf -g
rimraf node_modules
// Delete folder with all includes
rd /s/q path_to_folder
rmdir /s/q path_to_folder
@cubespace
cubespace / postgresql
Created May 30, 2017 08:57 — forked from igorpronin/postgresql
Вывести имена колонок и тип данных для определенной таблицы
-- 1
select column_name, data_type
from information_schema.columns
where table_name = 'users';
-- 2
SELECT
column_name, data_type, character_maximum_length
FROM
@cubespace
cubespace / postgresql
Created May 30, 2017 08:57 — forked from igorpronin/postgresql
Подсчет количества элементов таблицы postgeSQL
SELECT count(*) FROM my_table;
-- больше способов
-- https://habrahabr.ru/post/30046/
@cubespace
cubespace / sql, postgres, psql
Created May 30, 2017 08:57 — forked from igorpronin/sql, postgres, psql
Копировать структуру таблицы
CREATE TABLE table2 AS SELECT * FROM table1 WHERE 1=2;
(This creates the structure only -- no data will be transferred because
1 will never equal 2). :)
@cubespace
cubespace / postgresql, sql, postgres, psql
Created May 30, 2017 08:57 — forked from igorpronin/postgresql, sql, postgres, psql
Копировать выборочно данные из одной таблицы в другую
--example 1
INSERT INTO cheap_books (id, note)
SELECT id, 'Was in use'
FROM Books WHERE id > (SELECT MAX(id) FROM Books) - 3
--example2
INSERT INTO public.table1 (id_user, id_operator, status)
@cubespace
cubespace / postgres
Created May 30, 2017 08:56 — forked from igorpronin/postgres
Удаление дубликатов из таблицы c primary key
-- http://stackoverflow.com/questions/1746213/how-to-delete-duplicate-entries
-- Given table table, want to unique it on (field1, field2) keeping the row with the max field3:
DELETE FROM table USING table alias
WHERE table.field1 = alias.field1 AND table.field2 = alias.field2 AND
table.max_field < alias.max_field
-- For example, I have a table, user_accounts, and I want to add a unique constraint on email, but I have some duplicates. Say also that I want to keep the most recently created one (max id among duplicates).
@cubespace
cubespace / php
Created May 30, 2017 08:56 — forked from igorpronin/php
генерация уникальной случайной строки php
<?php
/**
*
* @var Получаем текущее время в миллисекундах и случайное число
* и хэшируем полученную строку
*
*/
$hashe = md5( microtime() . mt_rand() );
# Выводим хэш
@cubespace
cubespace / php, regexp
Created May 30, 2017 08:56 — forked from igorpronin/php, regexp
Возврат подстроки, которая начинается с определенной строки и заканчивается определенной строкой без их включения в результат, preg_match
$str = 'the result inside big string';
preg_match("/(?<=the )(.*)(?= inside)/", $str, $result_arr);
echo $result_arr[0]; // result
/*
(?<=) - с чего начинается искомая строка
(?=) - чем заканчивается искомая строка
(.*) - искомая строка содержит любое количество любых символов
PS: хороший конструктор регулярных выражений - http://www.phpliveregex.com/