Skip to content

Instantly share code, notes, and snippets.

@cenkce
cenkce / deepMerge.js
Last active May 18, 2018 05:15
Deeply object merge
function isObj(val){
return val !== null && typeof val === "object";
}
function recurse(acc, obj){
for (var p in obj) {
acc[p] = isObj(obj[p]) ? recurse(acc[p] || {}, obj[p]) : obj[p];
}
return acc;
@cenkce
cenkce / Readme.md
Last active July 10, 2018 09:21
Eclipse Che Requirements for MacOS
@cenkce
cenkce / class_as_parameter_type.ts
Last active January 7, 2019 08:57
Class as a type. Also use data classes as own parameter type.
const getId = (start): (() => number) => (): number => start++;
export class SomeData {
static getId = getId(0);
public icon: string;
public text: string = "";
public color: string;
public idPrefix: string = 'data-';
public id: string;
@cenkce
cenkce / add-component.js
Last active February 21, 2019 12:29
Instantly add component to context
class StylingComponent {
}
StylingComponent.$$styleContext = {
classNames: "",
userProps: {
width: null,
height: null,
paddingLeft: 10,
paddingRight: 10

Keybase proof

I hereby claim:

  • I am cenkce on github.
  • I am cenkce (https://keybase.io/cenkce) on keybase.
  • I have a public key ASC-gr0h_WL5mVX2DVovhlHULn_2Ts-nUed-Ucdtm9S05wo

To claim this, I am signing this object:

@cenkce
cenkce / find.js
Last active September 30, 2019 10:20
Find uncommon values between two arrays
const firstArray = ['a', 'b', 'c', 'd', 'e'];
const secondArray = ['a', 'b', 'c', 'x', 'a', 'k', 'x','a','r'];
const acc = {};
const table = {};
function explore(val){
if(val !== undefined && !acc[val]){
table[val] = true;
} else if(val !== undefined) {
@cenkce
cenkce / types.ts
Last active February 12, 2020 15:48
const shareLinks: {
socialMedia: {
twitter: "twitter",
facebook: "facebook"
},
email: "email",
anotherWay: "anotherWay"
}
// or more complex types
// We can't pass single provider name like Facebook
// Because it waits a complete object of the complexDataType
declare function share(provider: complexDataType):void;
type ValuesOfType = "any prop 1" | "any prop 2" | "any prop 3" // ...
// Extracts only non nested values
type ExtractValue<T extends {[key:string]: any}> = T extends {[key:string]: any} ? T[keyof T] : T;
// Recusively extracts values
type ExtractValues<T extends {[key:string]: any}> = T extends {[key:string]: any} ? ExtractValue<T[keyof T]> : never;
type ValuesOfComplexType = ExtractValues<ComplexType>;
// or
type ValuesOfComplexType = ExtractValues<typeof ComplexConstants>;
// assings the values
// "any value 1" | "any value 2" | "any value 3" | "any value 4" ...