Skip to content

Instantly share code, notes, and snippets.

View karpolan's full-sized avatar
❤️
React + Node

Anton Karpenko karpolan

❤️
React + Node
View GitHub Profile
@miguelgrinberg
miguelgrinberg / rest-server.py
Last active March 29, 2024 09:05
The code from my article on building RESTful web services with Python and the Flask microframework. See the article here: http://blog.miguelgrinberg.com/post/designing-a-restful-api-with-python-and-flask
#!flask/bin/python
from flask import Flask, jsonify, abort, request, make_response, url_for
from flask_httpauth import HTTPBasicAuth
app = Flask(__name__, static_url_path = "")
auth = HTTPBasicAuth()
@auth.get_password
def get_password(username):
if username == 'miguel':
@ksloan
ksloan / gist:d1b9ace61fddd2356ebf
Last active December 29, 2022 17:57
CSS Color Definitions for Font-Awesome Social Icons
.fa-facebook, .fa-facebook-square {
color: #3b5998
}
.fa-twitter, .fa-twitter-square {
color: #00aced
}
.fa-google-plus, .fa-google-plus-square {
color: #dd4b39
}
.fa-youtube, .fa-youtube-play, .fa-youtube-square {
@velsa
velsa / WoopyCase-ru.md
Last active September 6, 2015 11:40
Woopy Case (RU)

Кейс Woopy:

Супер защита 21го века для телефонов и планшетов

Для Iphone, IPad 6 и Ipad mini

  • Состоит из резинового бампера (как тут) с магнитными разъемами для зарядного устройства и наушников, резиновых кнопкок для регулировки громкости и вкл/выкл, а также колесика для включения/выключения звука (как в catalyst, см. ниже)
  • 2 специальных магнитных адаптера для кабеля зарядки и кабеля наушников, как тут: зарядка, и тут: audio
  • Дополнительная задняя крышка и передняя крышка со стеклом для защиты устройства от воды / пыли.
  • Задняя крышка защелкивается на бампере и частично покрывает его. Устройство удобнее держать в руке (ребристая поверхность)
@ftvs
ftvs / PhonecallReceiver.java
Last active October 11, 2023 10:05
Detecting an incoming call coming to an Android device. Remember to set the appropriate permissions in AndroidManifest.xml as suggested in the Stackoverflow link. Usage example in comments. Source: Gabe Sechan http://stackoverflow.com/a/15564021/264619 Explanation: http://gabesechansoftware.com/is-the-phone-ringing/#more-8
package com.gabesechan.android.reusable.receivers;
import java.util.Date;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;
public abstract class PhonecallReceiver extends BroadcastReceiver {
@mike-casas
mike-casas / install-nvm-zsh.txt
Last active June 13, 2024 00:46
install nvm on mac with zsh shell
After install zsh
- brew update
- brew install nvm
- mkdir ~/.nvm
after in your ~/.zshrc or in .bash_profile if your use bash shell:
export NVM_DIR=~/.nvm
source $(brew --prefix nvm)/nvm.sh
@karpolan
karpolan / shuffle.js
Created August 10, 2019 10:44
Shuffle the Array in JavaScript
/* eslint-disable import/prefer-default-export */
/* eslint-disable no-param-reassign */
/**
* Shuffles array in place. ES6 version.
* @param {Array} a - array containing all items to shuffle.
*/
export function shuffle(a) {
for (let i = a.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
@karpolan
karpolan / withSuspense.js
Created August 10, 2019 10:46
withSuspense() HOC for React.lazy() + React.Suspense
import React from 'react';
import { CircularProgress, LinearProgress } from '@material-ui/core/';
/**
* Wraps the React Component with React.Suspense and FallbackComponent while loading.
* @param {React.Component} WrappedComponent - lazy loading component to wrap.
* @param {React.Component} FallbackComponent - component to show while the WrappedComponent is loading.
*/
export const withSuspense = (WrappedComponent, FallbackComponent = null) => {
return class extends React.Component {
@utilmind
utilmind / js-ucwords
Last active August 23, 2019 08:00
ucwords() for JavaScript
// The unicode-safe ucwords() func for JS (to capitalize the first characters of words),
// which additionally respects double-lastnames like Russian Засс-Ранцев and weird French names,
// like Honoré de Balzac and d'Artagnan.
String.prototype.ucwords = function() {
return this.toLowerCase()
.replace(/(^|\s|\-)[^\s$]/g, function(m) {
return m.toUpperCase();
})
// French, Arabic and some noble names...
@sibelius
sibelius / withRouter.tsx
Created February 19, 2020 17:08
withRouter for react-router-dom v6
import { useHistory } from 'react-router-dom';
export const withRouter = (Component) => {
const Wrapper = (props) => {
const history = useHistory();
return (
<Component
history={history}
{...props}
@karpolan
karpolan / ObjectAsList.js
Last active February 12, 2023 20:25
React component to print out <ul> list with all properties of JavaScript object
import { useMemo } from 'react';
const sortByAbc = ([a], [b]) => a.localeCompare(b);
const sortByZxy = ([a], [b]) => b.localeCompare(a);
const sortNone = () => 0;
/**
* Renders <ul> list with all properties of the given JavaScript object
* @param {object} object - object to print out
* @param {boolean} [sortAbc] - properties sorted A-Z when true