Skip to content

Instantly share code, notes, and snippets.

<?php
function isAjax() {
return (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
}
@samokoder
samokoder / guid.php
Created July 29, 2016 12:50
Simple guid-gen for php
<?php
function getGUID() {
$hash = md5(uniqid());
$phash = array(
substr($hash, 0, 8),
substr($hash, 8, 4),
substr($hash, 12, 4),
substr($hash, 16, 4),
substr($hash, 20),
@samokoder
samokoder / Ruby_finance_testcase.md
Created July 9, 2017 14:48 — forked from beshkenadze/Ruby_finance_testcase.md
Тестовое задание для Ruby-разработчика

Задание

Реализовать на Ruby с использованием Rails приложение со следующим функционалом:

  1. Регистрация / авторизация пользователей.
  2. Создание портфеля акций (5-6 акций достаточно) для пользователя: стандартный CRUD.
  3. Данные должны скачиваться с Yahoo Finance.
  4. Сделать вывод графика "стоимость портфеля от времени" за 2 последних года по выбранным в п.2 акциям.

Требования

@samokoder
samokoder / my-perf.js
Last active September 17, 2017 20:52
function myPerf() {
var i = window.performance.timing,
n = i.navigationStart;
return {
dns: (i.domainLookupEnd - i.domainLookupStart),
tcp: (i.connectEnd - i.connectStart),
srt: (i.responseStart - i.requestStart),
pdt: (i.responseEnd - i.responseStart),
rrt: (i.fetchStart - n),
@samokoder
samokoder / my.cnf.old
Created April 19, 2018 09:53 — forked from wood-goblin/my.cnf.old
Percona mysql sample config: /etc/mysql/my.cnf
# Generated by Percona Configuration Wizard (http://tools.percona.com/) version REL5-20120208
[mysql]
# CLIENT #
port = 3306
socket = /var/lib/mysql/data/mysql.sock
[mysqld]
@samokoder
samokoder / env.sh
Created August 7, 2018 19:09
GoLang env
#!/bin/bash
export GOPATH=$(pwd)
@samokoder
samokoder / rtlcss.js
Created August 8, 2018 09:45
Snippet to append rtl prefix
const fs = require('fs');
const rtlcss = require('rtlcss');
const options = {
'autoRename': false,
'autoRenameStrict': false,
'blacklist':{},
'clean': true,
'greedy': false,
'processUrls': false,
@samokoder
samokoder / mongoDump.md
Created February 4, 2019 17:01 — forked from JaniAnttonen/mongoDump.md
Export Docker MongoDB collection as a JSON file

First, find the container that runs your MongoDB and ssh into it.

Then, find the collection you want to export:

mongo
show dbs
use <database>
show collections
exit
@samokoder
samokoder / serial-async.js
Created February 10, 2019 13:43
Execute multiple promises one after another (not in parallel)
// see https://stackoverflow.com/a/24985483
const fetchList = list => {
return list.reduce((promise, item) => {
return promise.then(() => {
// or any other promise
return new Promise((resolve) => {
console.log(`delay for ${item} secs`);
setTimeout(() => {
resolve();
@samokoder
samokoder / mysql-docker.sh
Created February 10, 2019 17:55 — forked from spalladino/mysql-docker.sh
Backup and restore a mysql database from a running Docker mysql container
# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE