Skip to content

Instantly share code, notes, and snippets.

View js2me's full-sized avatar
🚙
I may be slow to respond.

Sergey S. Volkov js2me

🚙
I may be slow to respond.
View GitHub Profile
@js2me
js2me / md5.js
Created January 2, 2020 23:16
MD5 browser javascript
MD5 = function(d){result = M(V(Y(X(d),8*d.length)));return result.toLowerCase()};function M(d){for(var _,m="0123456789ABCDEF",f="",r=0;r<d.length;r++)_=d.charCodeAt(r),f+=m.charAt(_>>>4&15)+m.charAt(15&_);return f}function X(d){for(var _=Array(d.length>>2),m=0;m<_.length;m++)_[m]=0;for(m=0;m<8*d.length;m+=8)_[m>>5]|=(255&d.charCodeAt(m/8))<<m%32;return _}function V(d){for(var _="",m=0;m<32*d.length;m+=8)_+=String.fromCharCode(d[m>>5]>>>m%32&255);return _}function Y(d,_){d[_>>5]|=128<<_%32,d[14+(_+64>>>9<<4)]=_;for(var m=1732584193,f=-271733879,r=-1732584194,i=271733878,n=0;n<d.length;n+=16){var h=m,t=f,g=r,e=i;f=md5_ii(f=md5_ii(f=md5_ii(f=md5_ii(f=md5_hh(f=md5_hh(f=md5_hh(f=md5_hh(f=md5_gg(f=md5_gg(f=md5_gg(f=md5_gg(f=md5_ff(f=md5_ff(f=md5_ff(f=md5_ff(f,r=md5_ff(r,i=md5_ff(i,m=md5_ff(m,f,r,i,d[n+0],7,-680876936),f,r,d[n+1],12,-389564586),m,f,d[n+2],17,606105819),i,m,d[n+3],22,-1044525330),r=md5_ff(r,i=md5_ff(i,m=md5_ff(m,f,r,i,d[n+4],7,-176418897),f,r,d[n+5],12,1200080426),m,f,d[n+6],17,-1473231341),i,m,d[n+7
@js2me
js2me / media-query.css
Created December 27, 2019 10:57 — forked from AyoAlfonso/media-query.css
CSS Media Queries for Desktop, Tablet, Mobile.
/*
##Device = Desktops
##Screen = 1281px to higher resolution desktops
*/
@media (min-width: 1281px) {
//CSS
@js2me
js2me / media-query.css
Created December 27, 2019 10:56 — forked from AyoAlfonso/media-query.css
CSS Media Queries for Desktop, Tablet, Mobile.
/*
##Device = Desktops
##Screen = 1281px to higher resolution desktops
*/
@media (min-width: 1281px) {
//CSS
@js2me
js2me / react.d.ts
Created November 27, 2019 11:09
Get props type from React component
type Propsable = {
FC: React.FC;
C: React.Component;
CC: React.ComponentClass<any>;
F: (...args: any) => any;
}
type PropsOfFC<C extends Propsable["FC"]> = {
[K in keyof C["propTypes"]]: C["propTypes"][K] extends React.Validator<infer P>
? P
: K
@js2me
js2me / dotline.ts
Created November 14, 2019 13:02
DotLine
export const DotLine = styled.div<{ size: number, count: number, distance: number }>`
background: black;
width: ${({ size }) => `${size}px`};
height: ${({ size }) => `${size}px`};
opacity: 0.65;
border-radius: ${({ size }) => `${size / 2}px`};
box-shadow: ${({ count, distance }) => count === 1 ? 'none' : Array(count-1).fill(1).map((_, i) => `0 ${(i+1) * distance}px`).join(', ')};
margin-top: ${({ distance, size }) => `${distance * -(size + size/2)}px`};
@js2me
js2me / style.css
Created November 11, 2019 11:53
Point background
.background {
background-image: radial-gradient(#D7D7D7 1px, transparent 1px), radial-gradient(#ffc6c6 1px, transparent 1px);
background-position: 0 0, 25px 25px;
background-size: 50px 50px;
}
@js2me
js2me / index.d.ts
Created October 31, 2019 13:02
Sexy common TypeScript types
type Mutate<T, PropertyName extends keyof T, NewValue> = Omit<T, PropertyName> & {
[K in keyof T]: K extends PropertyName ? NewValue : T[K];
}
type PickAndOmit<TPick, TOmit, PropertyName extends (keyof TPick & keyof TOmit)> = Pick<TPick, PropertyName> & Omit<TOmit, PropertyName>
@js2me
js2me / uuid.js
Last active August 16, 2019 04:11
Random max safe integer number
export function uuid(a) {
return a ? (a ^ Math.random() * 16 >> a / 4).toString(16) : ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, uuid);
}
@js2me
js2me / mock-console.ts
Created July 31, 2019 10:18
Mock console.warn console.log console.error
const mockedMethods = ['log', 'warn', 'error']
export const { originalConsoleFuncs, consoleMessages } = mockedMethods.reduce(
(acc: any, method: any) => {
acc.originalConsoleFuncs[method] = console[method].bind(console)
acc.consoleMessages[method] = []
return acc
},
{
@js2me
js2me / base_helpers.js
Created July 22, 2019 07:55
Basic helpers which reduce your code (most of them are polyfills)
/**
* Check value on type which contains in arrayOfTypeNames
*
*
* Examples:
* valueIs('example', ['String']) -> true
* valueIs({}, ['String', 'Number']) -> false
*
* @param {any} value