Skip to content

Instantly share code, notes, and snippets.

View zernie's full-sized avatar
🏠
Working from home

zernie zernie

🏠
Working from home
View GitHub Profile
@jakoblind
jakoblind / managing-state.js
Last active March 28, 2017 09:23
Demonstration of two ways to manage React state. With recompose and with ES6 classes
// First we have our component which takes data and callback functions as props
const ProductDetails = ({ selectedColor, selectedSize, setSelectedColor, setSelectedSize }) => {
return (
<div>
<p>Selected color is: {selectedColor}</p>
<p>Selected size is: {selectedSize}</p>
<button onClick={() => setSelectedSize(64)}> set selected size 64</button>
<button onClick={() => setSelectedColor("green")}> set selected color to green </button>
</div>
);
@zmts
zmts / tokens.md
Last active June 11, 2024 08:13
Про токены, JSON Web Tokens (JWT), аутентификацию и авторизацию. Token-Based Authentication

Про токены, JSON Web Tokens (JWT), аутентификацию и авторизацию. Token-Based Authentication

Last major update: 25.08.2020

  • Что такое авторизация/аутентификация
  • Где хранить токены
  • Как ставить куки ?
  • Процесс логина
  • Процесс рефреш токенов
  • Кража токенов/Механизм контроля токенов
@genekogan
genekogan / scrapeImages.py
Created February 22, 2017 11:49
scraping full size images from Google Images
from bs4 import BeautifulSoup
import requests
import re
import urllib2
import os
import argparse
import sys
import json
# adapted from http://stackoverflow.com/questions/20716842/python-download-images-from-google-image-search
@danwhitston
danwhitston / browser_testing_on_wsl.md
Last active March 31, 2022 21:39
Browser testing for Ruby from within Windows Subsystem for Linux

This is a rough guide to setting up browser testing through Selenium on Windows Subsystem for Linux (WSL), aka Bash on Ubuntu on Windows. It assumes the following environment:

  • Windows 10, running WSL
  • A Ruby dev environment, running inside WSL
  • Code that we want to test using a web driver, in this case Selenium, with a Capybara and RSpec test framework

The coding project folders are stored in the main Windows filing hierarchy and accessed via dev/mnt, but that makes no real difference to development and testing other than making it possible to edit the code using a GUI based editor within Windows.

The problem with browser testing in WSL is that it relies on opening and controlling a web browser, and browsers don’t work on WSL at present as it deliberately doesn’t include X Windows or some other GUI manager - it’s meant to be command line after all. So while you can apt-get firefox, trying to actually run it isn’t going to work.

sudo apt-get update
sudo apt-get install build-essential chrpath libssl-dev libxft-dev -y
sudo apt-get install libfreetype6 libfreetype6-dev -y
sudo apt-get install libfontconfig1 libfontconfig1-dev -y
cd ~
export PHANTOM_JS="phantomjs-2.1.1-linux-x86_64"
wget https://github.com/Medium/phantomjs/releases/download/v2.1.1/$PHANTOM_JS.tar.bz2
sudo tar xvjf $PHANTOM_JS.tar.bz2
sudo mv $PHANTOM_JS /usr/local/share
sudo ln -sf /usr/local/share/$PHANTOM_JS/bin/phantomjs /usr/local/bin
@blaze182
blaze182 / deploy.rb
Created February 20, 2016 13:57
Capistrano 3 PostgreSQL backup task for Rails
# ...
# config/deploy.rb, config/deploy/production.rb etc.
# contents omitted
###
# example: add backup task prior to deploy
namespace :deploy do
before :deploy, "db:dump"
end
const stateIdLens = propLens('id')
const stateTokenLens = propLens('token')
let setCurrentUserId = (state, action) => set(idLens, action.payload.result, state)
let setCurrentUserToken = (state, action) => set(tokenLens, action.payload.token, state)
compose(setCurrentUserId, setCurrentUserToken)
@jhilden
jhilden / README.md
Last active October 3, 2021 10:32
Setup for using i18n-js together with react-rails i18n-js for server side prerendering

When using react-rails for an internationalized app it makes a lot of sense to use i18n-js for translations, so that you can reuse the the strings from your rails app's .yml files (and all the tooling & services that exist around that).

When you use the prerender feature of react-rails you face 2 problems:

  • The first is that translation.js & i18n.js from i18n-js need to be loaded inside the server-side JS prerendering processes, which is achieved by loading them inside the components.js.
  • The second problem is the server processes need to be aware of the current locale of each HTTP request. This is done by adding a custom renderer and using the before_render hook to configure i18n-js accordingly for each render call.
@gaearon
gaearon / slim-redux.js
Last active May 5, 2024 15:14
Redux without the sanity checks in a single file. Don't use this, use normal Redux. :-)
function mapValues(obj, fn) {
return Object.keys(obj).reduce((result, key) => {
result[key] = fn(obj[key], key);
return result;
}, {});
}
function pick(obj, fn) {
return Object.keys(obj).reduce((result, key) => {
if (fn(obj[key])) {
@ghinda
ghinda / object-to-form-data.js
Last active May 21, 2024 20:48
JavaScript Object to FormData, with support for nested objects, arrays and File objects. Includes Angular.js usage.
// takes a {} object and returns a FormData object
var objectToFormData = function(obj, form, namespace) {
var fd = form || new FormData();
var formKey;
for(var property in obj) {
if(obj.hasOwnProperty(property)) {
if(namespace) {