Skip to content

Instantly share code, notes, and snippets.

View bloadvenro's full-sized avatar

Viktor bloadvenro

View GitHub Profile
#!/bin/sh
LAYOUT_COUNT=2
CURRENT_LAYOUT=$(gsettings get org.gnome.desktop.input-sources current)
CURRENT_LAYOUT_NUMBER=$(echo -n $CURRENT_LAYOUT | tail -c 1)
DESIRED_LAYOUT=$(expr $CURRENT_LAYOUT_NUMBER + 1)
if [ `expr $DESIRED_LAYOUT % $LAYOUT_COUNT` -eq 0 ]
@dfkaye
dfkaye / json-normalize.js
Last active May 23, 2023 12:49
normalize a JSON string (add correct quotes, remove comments, blank lines, and so on)
// 22 Feb 2020 TODO:
// needs trailing comma fix (allow trailing comma in arrays and object literals).
// see JWCC at https://nigeltao.github.io/blog/2021/json-with-commas-comments.html
export { normalize };
// var normalize = (function() {
// ///////////////////////////////////////////////////
// REVISE THIS FILE, PUT THE MAIN FUNCTION AT TOP,
@william8th
william8th / .tmux.conf
Last active April 30, 2024 17:03
Tmux open new pane in same directory
# Set the control character to Ctrl+Spacebar (instead of Ctrl+B)
set -g prefix C-space
unbind-key C-b
bind-key C-space send-prefix
# Set new panes to open in current directory
bind c new-window -c "#{pane_current_path}"
bind '"' split-window -c "#{pane_current_path}"
bind % split-window -h -c "#{pane_current_path}"
@evxn
evxn / do-on-subscribe.rxjs.operator.ts
Last active March 5, 2021 17:26
rxjs on subscribe hook, callback on subscribe, doOnSubscribe operator, doOnSubscribe pipe, rxjs onSubscribe
import {defer} from 'rxjs/observable/defer';
import {Observable} from 'rxjs/Observable';
/** Example
import {from} from 'rxjs/observable/from';
from([1, 2, 3])
.pipe(doOnSubscribe(() => console.log('subscribed to stream')))
.subscribe(x => console.log(x), null, () => console.log('completed'));
*/
@alendit
alendit / hkt.ts
Created January 24, 2017 10:11
HKT in typescript don't work. But why?
interface Functor<F, A> {
map: <B>(this: Functor<F, A>, f: (a: A) => B) => Functor<F, B>
}
class Maybe<A> implements Functor<Maybe<A>, A> {
private constructor(public value: A) { }
static Nothing<A>() { return new Maybe<A>(undefined); }
static Just<A>(value: A) { return new Maybe<A>(value); }
map<B>(this: Maybe<A>, f: ((a: A) => B)): Maybe<B> {
@LKay
LKay / TypesafeField.tsx
Last active February 15, 2020 15:35
Redux Form 6.2.0 typings
import { Field } from "redux-form"
interface TypesafeFieldProps { foo: string }
const TypesafeField = Field as new () => Field<TypesafeFieldProps, any>
const node1 = (<TypesafeField name="test" component="input" foo="bar" />) // OK
const node2 = (<TypesafeField name="test" component="input" foo="bar" fizz="buzz" />) // Error (as expected)
@armw4
armw4 / redux-is-smarter-than-you-think.md
Last active June 19, 2021 20:10
Optimizing your react components via redux....shouldComponentUpdate for free and more...

The Beginning

Yes...it's true...redux is smart....smarter than you even know. It really does want to help you. It strives to be sane and easy to reason about. With that being said, redux gives you optimizations for free that you probably were completely unaware of.

connect()

connect is the most important thing in redux land IMO. This is where you tie the knot between redux and your underlying components. You usually take state and propogate it down your component hiearchy in the form of props. From there, presentational

@ahtcx
ahtcx / deep-merge.js
Last active April 29, 2024 17:13
Deep-Merge JavaScript objects with ES6
// ⚠ IMPORTANT: this is old and doesn't work for many different edge cases but I'll keep it as-is for any of you want it
// ⚠ IMPORTANT: you can find more robust versions in the comments or use a library implementation such as lodash's `merge`
// Merge a `source` object to a `target` recursively
const merge = (target, source) => {
// Iterate through `source` properties and if an `Object` set property to merge of `target` and `source` properties
for (const key of Object.keys(source)) {
if (source[key] instanceof Object) Object.assign(source[key], merge(target[key], source[key]))
}
anonymous
anonymous / MaJoYq.markdown
Created October 1, 2015 08:26
MaJoYq
@telekosmos
telekosmos / uniq.js
Last active November 15, 2022 17:13
Remove duplicates from js array (ES5/ES6)
var uniqueArray = function(arrArg) {
return arrArg.filter(function(elem, pos,arr) {
return arr.indexOf(elem) == pos;
});
};
var uniqEs6 = (arrArg) => {
return arrArg.filter((elem, pos, arr) => {
return arr.indexOf(elem) == pos;
});