Skip to content

Instantly share code, notes, and snippets.

View jaksm's full-sized avatar

Jaksa Malisic jaksm

  • Belgrade, Serbia
View GitHub Profile
@jaksm
jaksm / AnimatedRouter.css
Created September 17, 2021 11:30
Preact Animated Router (CSS only)
.page {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
.out {
animation: out 450ms ease-out;
@jaksm
jaksm / index.ts
Created February 14, 2020 21:02
csv-pair-splitter
import * as fs from "fs";
/*
* Apstrahovanje logike
* "pakovanje funckionalnosti tako da moze kasnije da se poziva sa promenjenim parametrima"
* */
function split({ inputPath, outputFolder, fileNameSuffix, inputSeparator, outputSeparator }) {
// read file contents
fs.readFile(inputPath, 'utf8', (err: any, data: string) => {
// csv files are read like string, so split them up into rows by new line ("\n") and remove "\r" from each row
import * as _ from 'lodash';
import { input } from './input';
type URLTable = URLTableEntry[];
interface URLTableEntry {
url: string;
keywords: string[];
}
const uniqueUrls: string[] = _.uniq(_.flattenDeep(input.map(({ urls }) => urls)));
@jaksm
jaksm / RestClient.php
Created August 12, 2019 09:34
DataForSeo php Rest Client
<?php
if (!function_exists('http_parse_headers')) {
function http_parse_headers($raw_headers)
{
$headers = array();
$key = ''; // [+]
foreach(explode("\n", $raw_headers) as $i => $h)
{
$h = explode(':', $h, 2);
`{
"ageRanges": ["0-5", "5-10"],
"genders": ["Male", "Female"],
"languages": ["en-EN"],
"serviceOptions": [],
"localTopics": [
"history",
"parks",
"city tours",
"nature tours",
@jaksm
jaksm / ListCard.jsx
Created July 2, 2019 09:29
Nice example on usage of hooks.
import PropTypes from "prop-types";
import React, { useEffect, useState } from "react";
import styled from "styled-components";
import { color } from "../../theme";
const Container = styled.div`
margin: 12px 0;
`;
const ListCardContainer = styled.div`
...imports
import IntlContext from "......./intl.context"
// Za class-based komponente
class BenefitCockpit extends Component {
static contextType = IntlContext;
render() {
return (
<h1>{this.context.member.suggest.title}</h1>
)
@jaksm
jaksm / Stat.jsx
Last active May 26, 2019 13:30
Semantic and animated components.
import PropTypes from "prop-types";
import React, { useEffect } from "react";
import { animated, useSpring } from "react-spring";
import styled from "styled-components";
/*
* Works like this
* <Stat value={164} label={"Lines of code"} />
* */
@jaksm
jaksm / App.js
Created May 23, 2019 13:41
Multi language React Context Api
import React, {Component} from 'react';
import './App.css';
import IntlContext from "./intl.context";
import Bla from "./Bla"
import en from "./locales/en"
import sr from "./locales/sr"
import LanguageSwitch from "./LanguageSwitch";
const translations = { en, sr }; // prevodi
@jaksm
jaksm / index.js
Created January 18, 2019 11:59
Bulk import and export folder contents
var imports = {};
function importAll(r) {
r.keys().forEach(key => {
const module = r(key);
const name = key.split("./")[1].split(".")[0];
imports[name] = module.default;
});
}