Skip to content

Instantly share code, notes, and snippets.

View pokorson's full-sized avatar

Mateusz Pokora pokorson

  • Motimate
  • Lodz
View GitHub Profile
@pokorson
pokorson / script.js
Created March 2, 2016 10:25
MomentJS local from UTC
var localTime = moment.utc(YOUR_DATE).toDate();
localTime = moment(localTime).format('YYYY-MM-DD HH:mm:ss');
.square-radio
= radio_button_tag :promotion_length, 7, id: 'promotion_length_7'
= label_tag 'promotion_length_7', 'Promuj przez 7 dni cena: 450 złotych'
.square-radio
= radio_button_tag :promotion_length, 14, id: 'promotion_length_14'
= label_tag 'promotion_length_14', 'Promuj przez 14'
.square-radio
= radio_button_tag :promotion_length, 28, id: 'promotion_length_28'
= label_tag 'promotion_length_28', 'Promuj przez 28'
@pokorson
pokorson / view.haml
Created March 2, 2016 10:41
JS nested fields form
# Example for haml with one field in NesteIdem, file :image
# js adding and removing fields. Edit and destroy nested fields without parent is not covered
# Our relation
# Parent has many NestedItems, NestedItem belongs to Parent
.nested-container
.btn.btn-default.add-nested Dodaj więcej zdjęć +
.nested-items
.nested-item{ data: { index: 0 }}
# input tag name will generate nested object in params
@pokorson
pokorson / element_in_view.js
Created March 2, 2016 10:42
JS Element in View
####### Function takes jQuery object as argument
####### currently working only for one element
var isInView = function($element){
elementOffsetTop = $element.offset().top;
elementHeight = $element.outerHeight();
windowTop = document.body.scrollTop;
windowHeight = window.innerHeight;
if( elementOffsetTop < (windowTop + windowHeight)
&& (elementOffsetTop + elementHeight) > windowTop)
return true;
@pokorson
pokorson / nvmrc
Created January 10, 2017 10:47 — forked from xiaolai/nvmrc
bash function for load .nvmrc automatically
# for nvm
export NVM_DIR="$HOME/.nvm"
. "$(brew --prefix nvm)/nvm.sh"
load-nvmrc() {
if [[ -f .nvmrc && -r .nvmrc ]]; then
nvm use
elif [[ $(nvm version) != $(nvm version default) ]]; then
echo "Reverting to nvm default version"
nvm use default
@pokorson
pokorson / .zshrc
Created January 10, 2017 11:35
autoload .nvmrc in zsh - from nvm docs
autoload -U add-zsh-hook
load-nvmrc() {
local node_version="$(nvm version)"
local nvmrc_path="$(nvm_find_nvmrc)"
if [ -n "$nvmrc_path" ]; then
local nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")")
if [ "$nvmrc_node_version" != "N/A" ] && [ "$nvmrc_node_version" != "$node_version" ]; then
nvm use
@pokorson
pokorson / add_flow.rb
Created March 18, 2017 13:51
Add flow annotation to all js
files = Dir.glob("./src/**/*").select { |f| f.include?('.js') }
files.each do |f|
content = IO.read(f)
IO.write f, "// @flow \n\n#{content}"
end
const createAction = (type) => {
return (payload) => ({type, payload})
}
const createReducer = (initState, handlers) => {
return (state = initState, action) => {
const actionHandler = handlers[action.type];
if (actionHandler) {
const result = actionHandler(state, action.payload);
return Object.assign({}, state, result);
@pokorson
pokorson / range.js
Last active May 27, 2017 16:26
Javascript range
function range(from, to) {
return Array.apply(null, Array(to - from + 1)).map(function (x, i) { return to - from + i; })
}
@pokorson
pokorson / actions.js
Last active August 2, 2017 13:04
Simple api middleware for redux
export const fetchTransactions = () => {
return {
type: "API_FETCH",
config: {
type: ACTIONS.FETCH_TRANSACTIONS,
action: () => axios.get(/* sample url */),
transform: response => response.data.result,
},
};
};