Skip to content

Instantly share code, notes, and snippets.

View rfprod's full-sized avatar
☯️

Vadim rfprod

☯️
View GitHub Profile
@rfprod
rfprod / iptables-vpn-killswitch.sh
Created August 1, 2018 07:12
Iptables VPN killswitch
#!/bin/bash
#---------------------------------------------------------------
# General instructions.
#---------------------------------------------------------------
# You need to setup iptables firewall, so your machine can connect ONLY
# to specified VPN servers (no other traffic allowed, except local,
# so there will be no "leaks"). Here's a script for that.
@rfprod
rfprod / DD_geo_coordinates_regex.js
Created December 20, 2017 18:01
DD geo coordinates regex
const lat1 = '-89.99151651';
const lon1 = '42.015332';
const lat2 = '-189.99151651';
const lon2 = '142.015332';
const lat3 = '189.99151651';
const lon3 = '242.015332';
const latRegX = /^(-)?(90(\.[0]+)?|[0-8]{0,1}[0-9](\.\d+)?)$/;
const lonRegX = /^(-)?(180(\.[0]+)?|[1]{0,1}[0-7]{0,1}[0-9](\.\d+)?)$/;
@rfprod
rfprod / CalculatorScript.markdown
Created December 10, 2017 20:25
Calculator script

Calculator script

Performs mathematical expression evaluation, takes string input, ignores spaces, returns a number, e.g.

  • calc('-123') = -123
  • calc('-1 +1') = 0
  • calc('2 /2+3 * 4.75- -6') = 21.25
  • calc('2 / (2 + 3) * 4.33 - -6') = 7.732
  • calc('(123.45 * (678.90/(-2.5+11.5)-(((80-(19))) * 33.25))/20)-(123.45* (678.90/(-2.5+11.5)-(((80-(19))) * 33.25))/20)+(13-2)/-(-11)') = 1

A script by V.

@rfprod
rfprod / Messaging App Template [AngularJS Material].markdown
Last active July 16, 2017 20:33
Messaging App Template [AngularJS Material]

Messaging App Template [AngularJS Material]

User stories: User can select a Conversation, and see messages inside the Conversation in a separate section to the right of Conversations list. User can post a message to the selected Conversation (this information is stored locally and is discarded on the page reload). User can use markdown for message text formatting.

A Pen by V on CodePen.

License.

Custom Events

Rules

  • an event object has subscribe and unsubscribe methods to add and remove handlers
  • subscribe and unsubscribe are able to take an arbitrary number of arguments and tolerate invalid arguments (not functions, or for unsubscribe, functions which are not subscribed) by skipping them
  • multiple subscription of the same handler is allowed, and in this case unsubscription removes the last subscription of the same handler
  • an event object has an emit method which must invoke all the handlers with the arguments provided
  • emit uses its own invocation context as handers' invocation context
  • the order of handlers invocation matches the order of subscription
@rfprod
rfprod / Text Input Stats.markdown
Last active June 1, 2017 14:26
Text Input Stats

Text Input Stats

User stories

  • User can input text in textarea
  • User can see statistics in numerical form on text input beneath textarea: TOTAL number of characters, number of a characters, number of b characters, number of c characters
  • User can see numerical statistics visualized with pie chart.

A Pen by V on CodePen.

Dartboard Score

The function dartboardScore(x, y) accepts coordinates of thrown dart and returns gained score, e.g.:

Outside of the board: "X"
Bull's eye: "DB"
Bull: "SB"
A single number, example: "10"
A triple number: "T10"
A double number: "D10"
@rfprod
rfprod / ParseMolecule.markdown
Last active April 30, 2017 21:10
Parse Molecule

Parse Molecule

The function parseMolecule counts the number of atoms of each element contained in the molecule, in a given chemical formula represented by a string, and returns an object.

Sample output for formula H2O: {H: 2, O: 1}

A script by V.

License.