Skip to content

Instantly share code, notes, and snippets.

Yaroslav JLarky

Block or report user

Report or block JLarky

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View discriminating.ts
export type Left<L> = { left: L };
export type Right<R> = { right: R };
export type Either<L, R> = Left<L> | Right<R>;
export function isLeft<L, R>(value: Either<L, R>): value is Left<L> {
return "left" in value;
}
export function isRight<L, R>(value: Either<L, R>): value is Right<R> {
return "right" in value;
@JLarky
JLarky / action.ts
Last active Nov 9, 2019
type safe redux actions (typescript)
View action.ts
// like typesafe-actions
export type AnyAction<T extends string, A> = A & {
type: T;
};
export function createAction<T extends string, P, AC extends (...args: any[]) => AnyAction<T, P>>(
type: T,
map: AC
): AC & { type: T } {
@JLarky
JLarky / grapheme-splitter.d.ts
Created Aug 1, 2017
grapheme-splitter typescript type declaration
View grapheme-splitter.d.ts
// import GraphemeSplitter = require("grapheme-splitter");
// console.log((new GraphemeSplitter()).splitGraphemes("🌷🎁💩😜👍🏳️‍🌈"));
declare module 'grapheme-splitter' {
class GraphemeSplitter {
constructor();
public splitGraphemes(input: string): string[];
public countGraphemes(input: string): number;
}
@JLarky
JLarky / encode_uri_rfc3986_binary.erl
Last active Apr 8, 2018
Erlang url encode with unicode/utf8 support working on binary instead of lists/strings
View encode_uri_rfc3986_binary.erl
-module(encode_uri_rfc3986_binary).
-author('Renato Albano <renatoalbano@gmail.com>').
-author('JLarky <jlarky@gmail.com>').
-export([encode/1]).
%% Taken from <http://erlangexamples.com/>,
%% from <http://github.com/CapnKernul/httparadise>
%% and <http://www.erlang.org/doc/man/edoc_lib.html>
@JLarky
JLarky / html_encode.ex
Created Apr 28, 2017
Encode html entities or escape html with Elixir and xmerl Erlang module
View html_encode.ex
defp html_encode(text) do
[_ | xml] = :xmerl.export_simple([{:xmlText, [], 0, [], text, :text}], :xmerl_xml)
:erlang.iolist_to_binary(xml)
end
View cbs-adblcok-filter.txt
[Adblock Plus 2.0]
! Title: cbs adblock
! Version: 1
! Expires: 1 days
! cbs https://adblockplus.org/forum/viewtopic.php?f=2&t=21002&sid=44caa2415db4ba23cdd8bd503379dd03&start=390#p150134
@@||pubads.g.doubleclick.net/gampad/ads?*rule=$domain=cbs.com
@@|http://$xmlhttprequest,image,domain=cbs.com
@@/adblock$domain=cbs.com
@@||ifmnwi.club$domain=cbs.com
View 00_goodState.ts
constructor(dispatcher) {
super(dispatcher, () => ({
greetings: [],
newGreeting: ''
}));
}
View green_icon.jsx
const StatusIcon = () => {
const color1 = "green";
const color2 = "#74ba74";
const color3 = "#74ba74";
const radius = 50;
return <div id="status_icon"><style>{`
#status_icon{
width: ${radius}px;
height: ${radius}px;
border-radius: ${radius}px;
View 03_sameroomDispatcher.ts
const onDispatch = (action: Event) => {
if (action instanceof AddGreetingEvent) {
const {payload} = action;
this._state.newGreeting = '';
this._state.greetings = this._state.greetings.concat(payload);
this.emitChange();
} else if (action instanceof RemoveGreeting) {
const {payload} = action;
this._state.greetings = this._state.greetings.filter(g => g !== payload);
this.emitChange();
View 02_katoDispatcher.ts
const onDispatch = (action: Event) => {
switch(action.type) {
case GreetingActionTypes.ADD_GREETING:
let payload1 = (<AddGreetingEvent> action).payload;
this._state.newGreeting = '';
this._state.greetings = this._state.greetings.concat(payload1);
this.emitChange();
break;
case GreetingActionTypes.REMOVE_GREETING:
let payload2 = (<RemoveGreeting> action).payload;
You can’t perform that action at this time.