Skip to content

Instantly share code, notes, and snippets.

View mvalipour's full-sized avatar
🚴‍♂️
Cycling...

| Mo Valipour mvalipour

🚴‍♂️
Cycling...
View GitHub Profile
@mvalipour
mvalipour / 2.go
Last active January 16, 2021 12:25
const DECK uint64 = 1 << 52 - 1
func isValidSet(x uint64) (bool) {
return x <= DECK
}
@mvalipour
mvalipour / playing-cards.css
Created January 3, 2019 20:51
Playing cards in CSS3
.pc { content: "\1F0A0"; font-size: 5em; line-height: 100%;}
.pc.suit-hearts,
.pc.suit-diamonds { color: indianred; }
.pc.suit-hearts.face-2:after { content: "\1F0A2" }
.pc.suit-hearts.face-3:after { content: "\1F0A3" }
.pc.suit-hearts.face-4:after { content: "\1F0A4" }
.pc.suit-hearts.face-5:after { content: "\1F0A5" }
.pc.suit-hearts.face-6:after { content: "\1F0A6" }
.pc.suit-hearts.face-7:after { content: "\1F0A7" }
@mvalipour
mvalipour / _usage.md
Last active January 3, 2019 01:03
A minimalistic enums implementation in ruby

Usage

class MyClass
  include Enums
  
  enum foo: [:x, :y]
end
@mvalipour
mvalipour / .bash_profile
Last active August 11, 2017 16:17
Mo's bash shortcuts
alias c='bundle exec rails c'
alias hc='heroku run bundle exec rails c'
alias hl='heroku login --sso'
@mvalipour
mvalipour / ext.js
Created July 15, 2017 18:37
Hacky code to generate new file based on text selection in atom
toSnakeCase = s => s.replace(/(?:^|\.?)([A-Z])/g, (x,y) => "_" + y.toLowerCase()).replace(/^_/, "")
editor = atom.workspace.getActiveTextEditor();
path = editor.getPath();
fileName = editor.getFileName();
fileExt = fileName.split('.').pop();
dir = path.substring(0, path.length - fileName.length);
selectedText = editor.getSelectedText();
newPath = dir + toSnakeCase(selectedText) + '.' + fileExt;
@mvalipour
mvalipour / romanToInt
Created December 6, 2016 01:12
romanToInt
/**
* @param {string} s
* @return {number}
*/
var romanToInt = function(s) {
var map = {
'I': 1,
'V': 5,
'X': 10,
'L': 50,
@mvalipour
mvalipour / postorderTraversal.js
Created December 5, 2016 23:38
postorderTraversal
/**
* Definition for a binary tree node.
* function TreeNode(val) {
* this.val = val;
* this.left = this.right = null;
* }
*/
/**
* @param {TreeNode} root
* @return {number[]}
@mvalipour
mvalipour / readme.md
Created November 28, 2016 12:48
Redux: Use store for state not cache

In Redux: use store for state not cache

Background

In Redux, you should not use Store as cache, but rather for things that need to be truly retained, across the application.

For example, when you have a screen to display holidays, and another screen to display details of a holiday:

there is a tendency to keep the list of holidays in the central store, so that when we go "back" from details screen, our list is available immediately (without need to wait for an api call).

@mvalipour
mvalipour / readme.md
Last active March 9, 2020 16:42
Transpile and Deploy ES6 node app to Azure app service using TeamCity and Octopus

Background

Web have a node application written in ES6/babel which cannot (yet) be run by the latest stable node engine. Locally we use babel-node to run the application using babel's on-the-fly transpiler; However this is strongly discourages on the production environment (due to memory and performance footprints).

So we would need to transpile our application to the stable ECMA and deploy the artefacts to Azure -- instead of the original app.

Why not use kudu?

function solution(input) {
if (input.length === 0) {
return [];
}
// sort by first element of each interval
// O(n log n)
intervals = input.slice(0);
intervals.sort(([a], [b]) => a - b);