Skip to content

Instantly share code, notes, and snippets.

View sallar's full-sized avatar
:shipit:
Staring into an abyss

Sallar sallar

:shipit:
Staring into an abyss
View GitHub Profile
@sallar
sallar / example.ts
Last active August 13, 2023 01:08
TypeScript Either / Pattern Matching
import { Either, Left, Right, match } from './patterns.ts';
interface Person {
name: string;
}
const readValueFromAPI = (): Either<Error, Person> => {
// ...
const person: Person = {
name: 'Test',
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<input type="password" name="password">
@sallar
sallar / main.js
Created February 22, 2018 17:10
Electron IPC Enqueue
ipc.on('channel:enqueue', (e, payload) => {
const { channelName, stack, id } = payload;
getQueue()
.channel(channelName)
.enqueue(
() => {
return new Promise(resolve => {
ipc.once(`channel:resolve:${id}`, resolve);
e.sender.webContents.send(`channel:execute:${id}`);
});
@sallar
sallar / part1.rs
Last active December 2, 2017 21:15
Rust Learning
enum SomethingOrNothing<T> {
Something(T),
Nothing,
}
use self::SomethingOrNothing::*;
use std::io::prelude::*;
use std::io;
pub trait Minimum: Copy {
@sallar
sallar / ts-curry.ts
Created November 20, 2017 08:40
Typescript Module Curry
module Cart {
export function test1() {
console.log('hi');
}
export function test2() { }
}
function curryModule<T>(mod: T): T {
return Object
.keys(mod)
@sallar
sallar / collection-utils.js
Created July 1, 2017 14:13
Recursive Collection Utils
// By Sallar Kaboli
import { sortBy, at } from 'lodash';
export function sortDeepByKey(list, sortKey, childrenKey) {
if (!sortKey || !childrenKey) {
throw new Error('Insufficient data provided for sorting');
}
return sortByKey(list, sortKey).map(item => {
return {
...item,
@sallar
sallar / index.js
Created June 27, 2017 10:46
SES Example
const nodemailer = require('nodemailer');
const aws = require('aws-sdk');
// create Nodemailer SES transporter
const transporter = nodemailer.createTransport({
SES: new aws.SES({
apiVersion: '2010-12-01',
region: 'eu-west-1'
})
});
@sallar
sallar / index.js
Created October 18, 2016 11:05
requirebin sketch
const { normalize, Schema, arrayOf } = require('normalizr');
const { v4 } = require('uuid');
const group = new Schema('groups');
const groups = arrayOf(group);
group.define({
children: groups
});
@sallar
sallar / reducer.js
Created January 25, 2016 14:08
Redux Reducers Example
function reducer(state = []) {
return [...state, {
title: "Test",
completed: false
}];
}
@sallar
sallar / amd-jsdoc.md
Created November 30, 2015 20:11
WebStorm AMD/JSDoc Problem

OK, So imagine you have this module which accepts another module as a parameter to one of it’s methods:

define("modules/module2", [], function() {

    return {
        /**
         * @param {module:myNamespace/module1} SomeModule
         */
 somethingElse: function(SomeModule) {