Skip to content

Instantly share code, notes, and snippets.

@avivshafir
avivshafir / alfy_alfred_node_workflow.js
Last active February 19, 2018 21:04
Alfy | Alfred workflow node example
const alfy = require("alfy");
const alfyFetchOptions = {
auth: auth,
maxAge: requestCacheInMilis
};
const auth = "username:password";
const requestCacheInMilis = 1000 * 60 * 60 * 24; //24 hours
@avivshafir
avivshafir / tsconfig.json
Last active March 5, 2018 17:04
tsconfig for dynamic imports
{
"compilerOptions": {
"target": "es5",
"sourceMap": false,
"inlineSourceMap": true,
"module": "esnext",
"moduleResolution": "node",
"jsx": "react",
"preserveConstEnums": true,
"removeComments": false,
@avivshafir
avivshafir / generateTagsReactLoadable.js
Last active March 5, 2018 17:30
Using React Loadable for lazy loading our GenerateTags component
const GenerateTags = Loadable({
loader: () =>
import(/* webpackChunkName: "generateTags" */ "./GenerateTags"),
loading: LoadingSpinner
});
@avivshafir
avivshafir / webpack.js
Last active March 5, 2018 18:34
webpack 4 loading vendors into vendor.js and generating a manifest file which includes the webpack runtime
mode: "production",
entry: {
app: path.join(__dirname, "index.tsx"),
},
output: {
path: path.resolve(__dirname, "public/dist"),
publicPath: "",
chunkFilename: "[name].js",
filename: "[name].js"
},
@avivshafir
avivshafir / combineReducers.tsx
Last active March 5, 2018 19:04
adding redux form reducer to our app reducers
import { reducer as formReducer } from "redux-form";
const applicationReducer: Reducer<any> = combineReducers({
user,
sidenav,
navigation,
//...
form: formReducer
});
@avivshafir
avivshafir / injectingAsyncReducers.ts
Last active March 5, 2018 19:16
Injecting Async Redux Reducers
export function injectAsyncReducer(store, name, asyncReducer) {
if (store.asyncReducers[name]) {
return;
}
store.asyncReducers[name] = asyncReducer;
store.replaceReducer(createReducer(store.asyncReducers));
}
export const configureStore = (initialState: AppState) => {
const enhancer = compose(applyMiddleware(...getMiddleware()));
@avivshafir
avivshafir / GenerateTags.tsx
Last active March 5, 2018 19:20
Injecting the redux form reducer on the component load
public componentDidMount() {
const reduxFormReducer = require("redux-form").reducer;
injectAsyncReducer(store, "form", reduxFormReducer);
}
@avivshafir
avivshafir / fp_scala_p1.scala
Last active April 23, 2018 07:01
fp in scala part 1
def fib(n: Int): Int = {
@annotation.tailrec
def loop(n: Int, prev: Int, cur: Int): Int =
if (n == 0) prev
else loop(n - 1, cur, prev + cur)
loop(n, 0, 1)
}
fib(6)
@avivshafir
avivshafir / Valid Palindrome II.js
Created October 20, 2018 19:33
Given a non-empty string s, you may delete at most one character. Judge whether you can make it a palindrome.
//Given a non-empty string s, you may delete at most one character. Judge whether you can make it a palindrome.
//https://leetcode.com/explore/interview/card/facebook/5/round-1-phone-interview/289/
//Solution 1 - Not efficient o(n^2)
//---------------------------------------------------
var validPalindrome = function(s) {
for (let i = 0; i < s.length; i++) {
let w = s.substr(0, i) + s.substr(i + 1);
if (isPal(w)) {
return true;
@avivshafir
avivshafir / .block
Created June 24, 2019 12:19
FEM: Exercise 1 starter
license: mit