Skip to content

Instantly share code, notes, and snippets.

View ralexandr's full-sized avatar
💭
You're never wrong to do the right thing

Alexander Radyushin ralexandr

💭
You're never wrong to do the right thing
View GitHub Profile
@ralexandr
ralexandr / mysql-docker.sh
Created August 9, 2018 22:09 — forked from spalladino/mysql-docker.sh
Backup and restore a mysql database from a running Docker mysql container
# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE

Keybase proof

I hereby claim:

  • I am ralexandr on github.
  • I am ralexandr (https://keybase.io/ralexandr) on keybase.
  • I have a public key ASDbzNl2VRbjwBC3GDSpbksTPvIndhxth7SSObc96ovdoQo

To claim this, I am signing this object:

@ralexandr
ralexandr / gist:6dfb1a49b767ebec427e30dede0b8872
Last active May 31, 2018 22:35
Get nearest period (with moment.js)
function nearestMinutes(interval, someMoment) {
const roundedMinutes = Math.round(someMoment.clone().minute() / interval) * interval;
return someMoment.clone().minute(roundedMinutes).second(0);
}
function nearestPastMinutes(interval, someMoment) {
const roundedMinutes = Math.floor(someMoment.minute() / interval) * interval;
return someMoment.clone().minute(roundedMinutes).second(0);
}
function resize (file, maxWidth, maxHeight, fn) {
var reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function (event) {
var dataUrl = event.target.result;
var image = new Image();
image.src = dataUrl;
image.onload = function () {
@ralexandr
ralexandr / gist:750f796b70e9de1efb3e1f3ff078d1a7
Created March 28, 2018 02:00 — forked from sgergely/gist:3793166
Midnight Commander Keyboard Shortcuts for Mac OSX
----- Esc -----
Quick change directory: Esc + c
Quick change directory history: Esc + c and then Esc + h
Quick change directory previous entry: Esc + c and then Esc + p
Command line history: Esc + h
Command line previous command: Esc + p
View change: Esc + t (each time you do this shortcut a new directory view will appear)
Print current working directory in command line: Esc + a
Switch between background command line and MC: Ctrl + o
Search/Go to directory in active panel: Esc + s / Ctrl + s then start typing directory name
import { HTTPFetchNetworkInterface, printAST } from 'apollo-client';
/**
* Serialize a object to a query string
* @source https://stackoverflow.com/questions/1714786/query-string-encoding-of-a-javascript-object#comment47677757_18116302
*/
function serialize( obj ) {
return `?` + Object.keys(obj).map(k => k + `=` + encodeURIComponent(obj[k])).join(`&`);
}
@ralexandr
ralexandr / letsencrypt.md
Created November 22, 2016 14:41
LetsEncrypt Nginx, Apache, NodeJS

Let's Encrypt

Examples of getting certificates from Let's Encrypt working on Apache, NGINX and Node.js servers.

Obtain certificates

I chose to use the manual method, you have to make a file available to verify you own the domain. Follow the commands from running

git clone https://github.com/letsencrypt/letsencrypt
cd letsencrypt
@ralexandr
ralexandr / react-native-live-reload-xcode-settings.md
Created November 5, 2016 03:12
react-native live reload xcode settings

In the default React Native app scaffolding you have to edit AppDelegate.m to change where it loads the code if you want to test on your device. I use the following snippet to detect if it's being compiled for Debug or Production and for the Simulator or a device. For Production it uses a copy of the code included in the bundle, for Debug on the simualtor it loads from a server on localhost and for Debug on a device it loads from a server on a given IP address.

NOTE: You need to edit YOUR-IP-HERE and change it to the IP to load the code from when in Debug mode on a device. You could use a service like ngrok to make this work from anywhere.

  NSURL *jsCodeLocation;

  // Loading JavaScript code
  #if DEBUG
    // For Debug build load from development server. Start the server from the repository root:
@ralexandr
ralexandr / index.html
Created October 19, 2016 09:43
Animated input labels
<div class="container">
<form>
<h1>Sign-Up Now</h1>
<div class="field">
<label for="firstName">First Name</label>
<input type="text" id="firstName" name="firstNameTextField" placeholder="First Name">
</div>
<div class="field">
<label for="lastName">Last Name</label>
<input type="text" id="lastName" name="lastNameTextField" placeholder="Last Name">
@ralexandr
ralexandr / SASS: Button onhover background animation
Created October 19, 2016 09:37
SASS: Button onhover background animation
button {
background-image: linear-gradient(#5187c4, #1c2f45);
background-size: auto 200%;
background-position: 0 100%;
transition: background-position 0.5s;
&:hover {
background-position: 0 0;
}
}