Skip to content

Instantly share code, notes, and snippets.

Working from home

Arup Rakshit aruprakshit

Working from home
View GitHub Profile
ljharb /
Last active Oct 9, 2021
Array iteration methods summarized

Array Iteration

While attempting to explain JavaScript's reduce method on arrays, conceptually, I came up with the following - hopefully it's helpful; happy to tweak it if anyone has suggestions.


JavaScript Arrays have lots of built in methods on their prototype. Some of them mutate - ie, they change the underlying array in-place. Luckily, most of them do not - they instead return an entirely distinct array. Since arrays are conceptually a contiguous list of items, it helps code clarity and maintainability a lot to be able to operate on them in a "functional" way. (I'll also insist on referring to an array as a "list" - although in some languages, List is a native data type, in JS and this post, I'm referring to the concept. Everywhere I use the word "list" you can assume I'm talking about a JS Array) This means, to perform a single operation on the list as a whole ("atomically"), and to return a new list - thus making it mu


Redux Selector Pattern

Imagine we have a reducer to control a list of items:

function listOfItems(state: Array<Object> = [], action: Object = {}): Array<Object> {
  switch(action.type) {
    case 'SHOW_ALL_ITEMS':
yang-wei /
Last active Oct 19, 2021
Elm Destructuring (or Pattern Matching) cheatsheet

Should be work with 0.18

Destructuring(or pattern matching) is a way used to extract data from a data structure(tuple, list, record) that mirros the construction. Compare to other languages, Elm support much less destructuring but let's see what it got !


myTuple = ("A", "B", "C")
myNestedTuple = ("A", "B", "C", ("X", "Y", "Z"))
benjaminbarbe /
Last active Feb 25, 2021 — forked from raucao/nginx-lua-s3.nginxconf
Nginx proxy to S3 with caching
jdickey / Trivial example of isolating Rails helper logic.rb
Last active Oct 9, 2015
Trivial example of isolating Rails helper logic.
View Trivial example of isolating Rails helper logic.rb
# In app/helpers/users_helper.rb
require_relative 'users_helper/greet'
module UsersHelper
module Internals
private_constant :Internals
include Internals
corbanb / JavaScript.sublime-build
Last active Feb 26, 2021
Sublime Text - Tools > Build System > New Build System
View JavaScript.sublime-build
// Sublime Text - Build System for Javascript
"cmd": ["node", "$file"],
"selector": "source.js"
View respond_to_missing.rb
class Wrong
def method_missing(m, *)
if m =~ /\Ahello_(.+)\z/
puts "Hello, #{$1.capitalize}"
turbod / copy_carrierwave_files.rb
Created Mar 17, 2014
Copy carrierwave files to another model
View copy_carrierwave_files.rb
original_solution.files.each do |original_file|
f = original_file.dup
f.remote_name_url =
new_solution.files << f
Kartones /
Last active Jan 18, 2021
Sublime Text 3 Cheatsheet

Keyboard shorcuts

  • CTRL + SHIFT + p: Command panel
  • CTRL + p: File search
  • CTRL + r: Method search inside current file
  • CTRL + g: Go to line #
  • CTRL + SHIFT + [: Fold code
  • CTRL + SHIFT + ]: Unfold code
  • ALT + SHIFT + 2: Double column/file mode
  • ALT + SHIFT + 1: Single column/file mode
maxim /
Last active Sep 8, 2021
How to use rails load paths, app, and lib directories.

In Rails 3

NOTE: This post now lives (and kept up to date) on my blog:

If you add a dir directly under app/

Do nothing. All files in this dir are eager loaded in production and lazy loaded in development by default.

If you add a dir under app/something/