Skip to content

Instantly share code, notes, and snippets.

☀️
hablo programación

Przemek Sobstel sobstel

☀️
hablo programación
Block or report user

Report or block sobstel

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View fetch_with_timeout.js
const API_URL = '...';
const TIMEOUT = 10; // seconds
export default (path) => {
/* global fetch */
const req = fetch(API_URL + path);
const timeout = new Promise((resolve, reject) => {
return setTimeout(() => reject(new Error('request timeout')), TIMEOUT * 1000);
});
@sobstel
sobstel / README
Last active Jan 6, 2018
Climb the stairs (brain friendly, not so cpu friendly)
View README
There's a staircase with N steps, and you can climb 1 or 2 steps at a time.
Given N, write a function that returns the number of unique ways you can
climb the staircase. The order of the steps matters.
For example, if N is 4, then there are 5 unique ways:
1, 1, 1, 1
2, 1, 1
1, 2, 1
@sobstel
sobstel / warden.rb
Last active Feb 20, 2018
Warden Rails cookie
View warden.rb
Warden::Manager.after_authentication do |user, auth, _opts|
cookies = ActionDispatch::Request.new(auth.env).cookie_jar
cookies.encrypted[REMEMBER_ME_COOKIE_NAME] = { value: user.id, expires: 1.week.from_now }
end
@sobstel
sobstel / import_from_db.sh
Created Dec 4, 2017
Heroku prod database export to Docker database container
View import_from_db.sh
#!/bin/bash
# stop on first error
set -e
command -v heroku >/dev/null 2>&1 || { echo >&2 "heroku command is required"; exit 1; }
command -v docker-compose >/dev/null 2>&1 || { echo >&2 "docker-compose command is required"; exit 1; }
DUMPFILE="/tmp/_FILENAME_.dump"
@sobstel
sobstel / Gemfile
Last active Dec 2, 2017
Quick&dirty trello task list
View Gemfile
source 'https://rubygems.org'
ruby '~> 2.3.1'
gem 'cuba'
@sobstel
sobstel / optimize-images.js
Created Oct 6, 2017
Optimal images optimization
View optimize-images.js
//
// Optimizes all images
// (takes only those that have no corresponding @2x)
//
const im = require('imagemagick');
const glob = require('glob');
const fs = require('fs');
const { exec } = require('child_process');
View fetch_timeout.js
const CONNECTION_TIMEOUT = 20000;
function getData (url) {
let timer = null;
const service = fetch(url)
.then((response) => {
clearTimeout(timer);
return response.json();
});
@sobstel
sobstel / rn-scrollview-repeat-bg.js
Created May 12, 2017
React Native ScrollView repeated background
View rn-scrollview-repeat-bg.js
import React, { PropTypes, PureComponent } from 'react';
import { Image, ScrollView, } from 'react-native';
export default class ScrollViewWithBg extends PureComponent {
constructor (props) {
super(props);
this.state = {contentSize: {width: 0, height: 0}}
}
@sobstel
sobstel / translatable.rb
Created Apr 18, 2017
Traductor (rails models translations)
View translatable.rb
module Translatable
extend ActiveSupport::Concern
included do
translation_class_name = "Translations::#{model_name}Translation"
has_many :translations,
class_name: translation_class_name,
dependent: :delete_all,
inverse_of: model_name.to_s.underscore.to_sym
View app-controllers-concerns-authenticable.rb
module Authenticable
extend ActiveSupport::Concern
# Filter to use with before_action
def authenticate_user
jwt_token
rescue JWT::DecodeError => e
render json: { error: e.message }, status: :unauthorized
end
You can’t perform that action at this time.