Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Arup Rakshit aruprakshit

🏠
Working from home
View GitHub Profile
@ljharb
ljharb / array_iteration_thoughts.md
Last active Oct 9, 2021
Array iteration methods summarized
View array_iteration_thoughts.md

Array Iteration

https://gist.github.com/ljharb/58faf1cfcb4e6808f74aae4ef7944cff

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.

Intro

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

View reduxSelectorPattern.md

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':
      return action.data.items
    default:
@yang-wei
yang-wei / destructuring.md
Last active Oct 19, 2021
Elm Destructuring (or Pattern Matching) cheatsheet
View destructuring.md

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 !

Tuple

myTuple = ("A", "B", "C")
myNestedTuple = ("A", "B", "C", ("X", "Y", "Z"))
@benjaminbarbe
benjaminbarbe / README.md
Last active Feb 25, 2021 — forked from raucao/nginx-lua-s3.nginxconf
Nginx proxy to S3 with caching
View README.md
@jdickey
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
end
private_constant :Internals
include Internals
@corbanb
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}"
else
super
end
end
end
@turbod
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 = original_file.name.url
new_solution.files << f
end
@Kartones
Kartones / sublime-text-cheatsheet.md
Last active Jan 18, 2021
Sublime Text 3 Cheatsheet
View sublime-text-cheatsheet.md

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
maxim / rails_load_path_tips.md
Last active Sep 8, 2021
How to use rails load paths, app, and lib directories.
View rails_load_path_tips.md

In Rails 3

NOTE: This post now lives (and kept up to date) on my blog: http://hakunin.com/rails3-load-paths

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/