Skip to content

Instantly share code, notes, and snippets.

View chodorowicz's full-sized avatar

Jakub Chodorowicz chodorowicz

View GitHub Profile
@chodorowicz
chodorowicz / get_translated_media_or_original.php
Last active March 30, 2017 08:50
get file media file in current language, if it doesn't exist get original version
<?php
if (!function_exists('get_translated_media_or_original')) {
function get_translated_media_or_original($media_file_id) {
global $wpdb;
// check language of media file
$custom_query = "SELECT * FROM ".$wpdb->postmeta." WHERE meta_key='wpml_media_lang' AND post_id=".$wpdb->escape($media_file_id);
$meta = $wpdb->get_results( $custom_query );
$media_file_language = $meta[0]->meta_value;
// if language of media file equals current language, return that id
if($media_file_language == ICL_LANGUAGE_CODE) {
@chodorowicz
chodorowicz / .editorconfig
Last active March 25, 2017 09:10
web dev dotfiles, config files
root = true
[*]
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
@chodorowicz
chodorowicz / express-nunjucks.js
Last active March 13, 2017 02:55
express.js
require('dotenv').config({ silent: true });
var express = require('express');
var app = express();
var port = process.env.PORT || 3002;
var smptSender = require('./smtp-sender');
var bodyParser = require('body-parser')
const compress = require('compression');
const nunjucks = require('nunjucks');
const isDeveloping = process.env.NODE_ENV !== 'production';
@chodorowicz
chodorowicz / redux-ecosystem.md
Last active February 9, 2017 00:41
From Alt to Redux ecosystem (redux-actions, redux-thunk, react-redux, redux-saga)

From Alt to Redux ecosystem (redux-actions, redux-thunk, react-redux, redux-saga)

Jakub Chodorowicz

Young/Skilled

@chodorowicz
github.com/chodorowicz
@chodorowicz
chodorowicz / find.sh
Last active December 20, 2016 15:16
find shell tool
# find files in several folders
find foo bar baz -name "*.py"
# find
find . -name "__tests__"
# used with Mocha → find spec files in app and test folders
mocha $(find test app -path *.spec.js)
# find recursivelly all symlinks
@chodorowicz
chodorowicz / assertions.js
Last active November 4, 2016 15:02
webdriver
// count elements
// http://webdriver.io/api/protocol/elements.html
browser.elements('.OrdersList .Row')
.then(elements => {
assert.equal(elements.value.length, 999);
})
@chodorowicz
chodorowicz / ascii.txt
Last active October 1, 2016 17:09
ascii
o/ o/ \ /
| | |
/ \ / \ /o\
L(・o・)」
@chodorowicz
chodorowicz / reactive2016-lightning-talk-proposal.md
Last active September 23, 2016 10:33
Reactive Conference 2016 → lightning talk proposal

Proposal for a lightning talk at the Reactive 2016 conference → https://reactiveconf.com

Star ⭐ the Gist to vote on this talk.

Move all your side effect to middleware using redux-saga

Redux saga is side effects middleware which allows us to orchestrate even very complex logical flows - think multiple AJAX request which depending on the responses, writing state to localstorage etc. More over it's output are descriptions of actions which can be later processed by middleware, which makes it pure and easily testable. This talk would be a short intro to redux-saga, which would hightlight benefits of concentrating all of side effect in one place and making both actions creators and sagas pure and easily testable.

@chodorowicz
chodorowicz / setup.sh
Last active August 4, 2016 14:23
running Selenium test on CI server (SemaphoreCI)
# run your usual build scripts e.g.
# npm install
# npm run build
# download selenium standalone jar
wget http://selenium-release.storage.googleapis.com/2.53/selenium-server-standalone-2.53.0.jar
# run selenium using xvfb
# set web driver path
# get path to chrome.driver ➡️ which chromedriver
@chodorowicz
chodorowicz / events.js
Last active August 3, 2016 13:42
JavaScript DOM events
/** attach event diretly to DOM element */
var myelement = document.getElementById('my-div');
myelement.onclick = function() {
alert('Ouch!');
}
/** add event listener */
var mypara = document.getElementById('my-div');
mypara.addEventListener('click',
function() {alert('Boo!')},