Skip to content

Instantly share code, notes, and snippets.

View hendrysadrak's full-sized avatar

Hendry Sadrak hendrysadrak

View GitHub Profile
@hendrysadrak
hendrysadrak / vue-2.7-vuex-script-setup.ts
Last active January 7, 2024 01:10
Vue 2.7, Composition API, Vuex
import { store, type RootState } from '@/store'
import { mapValues } from 'lodash'
import { computed, getCurrentInstance, type ComputedRef } from 'vue'
import type { ActionTree, GetterTree, MutationTree, Store } from 'vuex'
type GetRestParams<T extends (a: any, ...args: any) => any> = T extends (
a: any,
...args: infer P
) => any
? P
@hendrysadrak
hendrysadrak / crawlera-errors-typescript-enum-definition.ts
Created October 8, 2020 11:46
Crawlera Errors Typescript Enum Definition
enum CrawleraError {
banned = 'banned',
noslaves = 'noslaves',
bad_session_id = 'bad_session_id',
user_session_limit = 'user_session_limit',
invalid_request = 'invalid_request',
bad_uri = 'bad_uri',
user_suspended = 'user_suspended',
bad_proxy_auth = 'bad_proxy_auth',
@hendrysadrak
hendrysadrak / Throttle.js
Created October 25, 2016 13:17
ES6 Throttle implementation with arguments and context
/**
* Simple ES6 Throttle implementation with arguments and context
*
* @param callback {Function} - Function to throttle
* @param [limit=30] {number} - Ms to throttle
* @param [context=this] - Context to run in
* @return {Function}
*/
const throttle = ( callback, limit = 30, context = this ) => {
let
@hendrysadrak
hendrysadrak / gulpfile.js
Last active April 24, 2016 18:33
Codepen.io extract - gulp task
// # npm i --save-dev gulp gulp-sass gulp-sourcemaps gulp-babel babel-preset-es2015 browser-sync gulp-autoprefixer
'use strict';
var gulp = require('gulp'),
sass = require('gulp-sass'),
sourcemaps = require('gulp-sourcemaps'),
babel = require('gulp-babel'),
browserSync = require('browser-sync').create(),
autoprefixer = require('gulp-autoprefixer');
@hendrysadrak
hendrysadrak / Canvas Element - Line
Created November 18, 2014 18:04
Canvas Element - Line
var lines = [];
function Line(x, y, toX, toY, width, color) {
this.x = x;
this.y = y;
this.toX = toX;
this.toY = toY;
this.width = width;
this.color = color;
this.alpha = 1;
@hendrysadrak
hendrysadrak / WP is body class
Created August 6, 2014 10:25
Wordpress - check if class exists in body class array
<?php
function isBodyClass($classToSearchFor) {
$classes = get_body_class();
return in_array($classToSearchFor, $classes);
}
?>