Skip to content

Instantly share code, notes, and snippets.

View kekby's full-sized avatar
🎯
Focusing

Bulat Gombotsyrenov kekby

🎯
Focusing
View GitHub Profile
@kekby
kekby / machine.js
Last active February 14, 2020 07:33
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@kekby
kekby / machine.js
Last active February 14, 2020 04:57
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@kekby
kekby / test_ecto.exs
Created January 29, 2020 07:22
testing ecto example
defmodule AuctionTest do
use ExUnit.Case
alias Auction.{Item, Repo}
doctest Auction
setup do
:ok = Ecto.Adapters.SQL.Sandbox.checkout(Repo)
end
describe "list_items/0" do
@kekby
kekby / objectify.js
Created May 9, 2018 13:26
create obj from array
export default (list, fn) => {
return list.reduce((acc, value) => {
return { ...acc, [fn(value)]: value }
}, {})
}
// const cars = [
// { brand: 'bmw', model: 'm3', year: 2013 },
// { brand: 'opel', model: 'astra', year: 2014 },
// { brand: 'honda', model: 'accent', year: 2014 },
@kekby
kekby / gist:f6d5b675336fddc6bc2c9209a5008616
Created January 11, 2018 02:18
react-dropzone with redux-form
import React, { Component, PropTypes, } from 'react';
import { reduxForm, Field } from 'redux-form';
import Dropzone from 'react-dropzone';
const FILE_FIELD_NAME = 'files';
const renderDropzoneInput = (field) => {
const files = field.input.value;
return (
@kekby
kekby / script.js
Created November 27, 2017 07:34
rus numbers
function declOfNum(titles){
var cases = [2, 0, 1, 1, 1, 2];
return function(number){
return titles[ (number%100>4 && number%100<20)? 2 : cases[(number%10<5)?number%10:5] ];
}
};
@kekby
kekby / db.php
Created November 24, 2017 03:38
DB.php with constants and array of key - values
$db['db_host'] = 'localhost';
$db['db_user'] = 'root';
$db['db_password'] = '';
$db['db_name'] = 'cms';
foreach($db as $key => $value){
define(strtoupper($key), $value);
};
$connection = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
@kekby
kekby / get_set.php
Created November 15, 2017 06:40
SQL search all possible values from SET TYPE colum
SELECT
REPLACE(COLUMN_TYPE, 'set', '') `values` FROM information_schema.COLUMNS WHERE
TABLE_SCHEMA = 'vote-app' -- your database name here
AND
TABLE_NAME = 'districts' -- your table name here
AND
COLUMN_NAME = 'district' -- your column name";
@kekby
kekby / image_load.php
Created November 15, 2017 06:28
PHP Image Load Script
//image upload
$target_dir = "img/";
$target_file = $target_dir . basename($_FILES["image_pit"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if (isset($_FILES['image_pit'])) {
$check = getimagesize($_FILES["image_pit"]["tmp_name"]);
echo $_FILES["image_pit"]["tmp_name"];
if($check !== false) {
@kekby
kekby / delete_users.php
Created November 14, 2017 12:17
PHP + MYSQL DELETE USER FROM DB FUNCTION
function delete_user() {
global $connection;
$id = $_POST['id'];
echo $id;
if (!$connection) {
die ('connection failed');
};
$query = "DELETE FROM users ";
$query .= "WHERE id = $id ";