Skip to content

Instantly share code, notes, and snippets.

Avatar

Давид Мзареулян davidmz

View GitHub Profile
View yellow-ff-theme.json
{
"page-background": "url(\"https://images.unsplash.com/photo-1584203095493-6d23037b6b13?w=1920&q=80\")",
"box-header-background": "#f3c635",
"link-color": "#a56c0b"
}
@davidmz
davidmz / settable-context.jsx
Last active Apr 20, 2020
React context that can be updated from the consumer
View settable-context.jsx
import React, { createContext, useState, useCallback } from 'react';
export const context = createContext({
query: '',
setQuery: () => undefined,
});
export function Provider({ children }) {
const [query, setStateQuery] = useState('');
const setQuery = useCallback((q) => setStateQuery(q), []);
@davidmz
davidmz / snippet.js
Created Nov 25, 2019
[500px sorder] Snipper for sorting 500px private gallery in photo id order #500px
View snippet.js
(async () => {
const galleryId = (() => {
const m = /^\/g\/(\w+)$/.exec(location.pathname);
if (!m) {
throw new Error("Invalid location (not a private gallery)");
}
return m[1];
})();
const userId = window.currentUser.id;
const csrfToken = window.PxApp.csrf_token;
@davidmz
davidmz / loops.js
Last active Sep 12, 2019
Loop control script for MPV video player #video #mpv
View loops.js
var hotKey = "k";
var numRe = /\d+(?:\.\d+)?/g;
var interval = null;
mp.register_event("file-loaded", function() {
// Trying to load loops file
mp.remove_key_binding("loopContinue");
clearInterval(interval);
var videoPath = mp.get_property("path");
@davidmz
davidmz / frfTop20Hashtags.txt
Created Sep 9, 2019
[Top 20 freefeed post hashtags] At 2019-09-04 #freefeed
View frfTop20Hashtags.txt
name | count
-------------------+-------
frf_inspired | 480
worldcup | 288
training | 259
wudru | 258
music | 255
poidem | 244
spb | 229
1 | 227
@davidmz
davidmz / 1-nested-routes.ts
Last active Aug 28, 2018
Nested routes for mobx-state-router
View 1-nested-routes.ts
import { Route as PlainRoute, RouterStore, RouterState } from 'mobx-state-router';
import { TransitionHook } from 'mobx-state-router/dist/types/router-store';
export interface Route extends PlainRoute {
children?: Route[];
}
type KeysOfType<A extends object, B> = { [K in keyof A]: A[K] extends B ? K : never }[keyof A];
type HookKey = Exclude<KeysOfType<PlainRoute, TransitionHook | undefined>, undefined>;
@davidmz
davidmz / collect-links.php
Created Feb 22, 2017
Short link extractor for Friendfeed archives
View collect-links.php
@davidmz
davidmz / log-crypt.go
Last active Nov 20, 2016
Скрипт для обфуцирования юзернеймов, UUID-ов и токенов в логах Фидика
View log-crypt.go
package main
import (
"bufio"
"crypto/hmac"
"crypto/sha1"
"encoding/hex"
"flag"
"fmt"
"os"
@davidmz
davidmz / Pragmatic_JSON_API.md
Last active Apr 30, 2016
Pragmatic JSON API
View Pragmatic_JSON_API.md

Запросы к API производятся методами GET (безопасные операции, не меняющие состояния сервера) и POST (все остальные + те, которым мешают ограничения GET).

Параметры запроса передаются как GET-параметры и/или как JSON-encoded тело POST-запроса.

Ответ сервера может быть двух типов: успех или ошибка. В обоих случаях используется HTTP-статус "200 OK". Ответ всегда представляет собой JSON-объект с обязательным полем status имеющим значение "ok" или "error".

Формат ответа «успех»:

@davidmz
davidmz / file_upload.php
Created Mar 13, 2016
Пример загрузки файла-картинки на PHP
View file_upload.php
<?php
$strTargetDir = "user_images/";
$fileUploadField = "file_name";
$max_image_width = 600;
$max_image_height = 600;
$max_image_size = 1 << 20; // 1 MiB
$error_msg = "";
// ....
You can’t perform that action at this time.