Skip to content

Instantly share code, notes, and snippets.

@nurbek-ab
nurbek-ab / diff.js
Created January 11, 2017 12:12
Show diff between two javascript objects
// http://stackoverflow.com/questions/31683075/how-to-do-a-deep-comparison-between-2-objects-with-lodash
function compare(a, b) {
var result = {
different: [],
missing_from_first: [],
missing_from_second: []
};
_.reduce(a, function (result, value, key) {
function isScrolledIntoView(elem)
{
var $elem = $(elem);
var $window = $(window);
var docViewTop = $window.scrollTop();
var docViewBottom = docViewTop + $window.height();
var elemTop = $elem.offset().top;
var elemBottom = elemTop + $elem.height();
@nurbek-ab
nurbek-ab / button.css
Last active August 14, 2017 17:45
Bootstrap 3 button with transparent background
/**
* Tested on Bootstrap 3.3.2
* Usage: <button class="btn btn-transparent" type="button">Click me</button>
*/
.btn-transparent {
background: transparent;
color: #F2F2F2;
-webkit-transition: background .2s ease-in-out, border .2s ease-in-out;
-moz-transition: background .2s ease-in-out, border .2s ease-in-out;
-o-transition: background .2s ease-in-out, border .2s ease-in-out;
@nurbek-ab
nurbek-ab / outOfViewport.js
Last active November 15, 2017 11:02 — forked from LukyVj/outOfViewport.js
Detect which elements overlap your document width.
function outOfViewport(colorWrapper, colorTag, colorClass) {
const bodyWidth = document.body.offsetWidth;
const list = document.querySelectorAll('*');
for (let elem of list) {
if (elem.offsetWidth > bodyWidth) {
console.log(
`%c [` +
`%c` + elem.tagName +
`%c.` + elem.classList +
`%c]` +
@nurbek-ab
nurbek-ab / simple-pagination.js
Created March 28, 2018 12:01 — forked from kottenator/simple-pagination.js
Simple pagination algorithm
// Implementation in ES6
function pagination(c, m) {
var current = c,
last = m,
delta = 2,
left = current - delta,
right = current + delta + 1,
range = [],
rangeWithDots = [],
l;
@nurbek-ab
nurbek-ab / connect.js
Created November 29, 2019 23:51 — forked from gaearon/connect.js
connect.js explained
// connect() is a function that injects Redux-related props into your component.
// You can inject data and callbacks that change that data by dispatching actions.
function connect(mapStateToProps, mapDispatchToProps) {
// It lets us inject component as the last step so people can use it as a decorator.
// Generally you don't need to worry about it.
return function (WrappedComponent) {
// It returns a component
return class extends React.Component {
render() {
return (
@nurbek-ab
nurbek-ab / git-ssh-auth-win-setup.md
Created January 5, 2019 06:08 — forked from bsara/git-ssh-auth-win-setup.md
Setup SSH Authentication for Git Bash on Windows

Setup SSH Authentication for Git Bash on Windows

Prepararation

  1. Create a folder at the root of your user home folder (Example: C:/Users/uname/) called .ssh.
  2. Create the following files if they do not already exist (paths begin from the root of your user home folder):
  • .ssh/config
@nurbek-ab
nurbek-ab / removeSearchParam.js
Created October 4, 2020 14:55
Remove URL search parameter
const removeSearchParam = param => {
const url = new URL(window.location.href)
url.searchParams.delete(param)
window.history.replaceState(null, null, url)
}
@nurbek-ab
nurbek-ab / functions.php
Last active April 5, 2021 10:59
Change wordpress search results permalink (base url, search base).
<?php
function nice_search_redirect() {
global $wp_rewrite;
if ( !isset( $wp_rewrite ) || !is_object( $wp_rewrite ) || !$wp_rewrite->using_permalinks() )
return;
$search_base = $wp_rewrite->search_base;
if ( is_search() && !is_admin() && strpos( $_SERVER['REQUEST_URI'], "/{$search_base}/" ) === false ) {
wp_redirect( home_url( "/{$search_base}/" . urlencode( get_query_var( 's' ) ) ) );
exit();
@nurbek-ab
nurbek-ab / text-align.css
Created January 21, 2015 08:48
Bootstrap text-align for different screen sizes
.text-xs-left {
text-align: left !important;
}
.text-xs-right {
text-align: right !important;
}
.text-xs-center {
text-align: center !important;