Skip to content

Instantly share code, notes, and snippets.

@silver-xu
silver-xu / ts-boilerplate.md
Last active October 31, 2024 12:16
Setup a Node.js project with Typescript, ESLint, Prettier, Husky

Setup a Node.js project with Typescript, ESLint, Prettier, Husky

1_D8Wwwce8wS3auLAiM3BQKA

Starting a personal node project could be easy; starting a team node project could be challenging.

I am a developer currently working in SEEK Australia.

In my experience, common mistakes developer make when starting a projects are:

  • No Linting
@code4cake
code4cake / api.rb
Created December 23, 2015 20:41 — forked from kenmazaika/api.rb
require 'rubygems'
require 'httparty'
resp = HTTParty.get("http://www.catfact.info//api/v1/facts.json?page=1&per_page=30")
resp['facts'].each do |item|
puts item.inspect
end
require 'rubygems'
require 'httparty'
resp = HTTParty.get("http://www.catfact.info//api/v1/facts.json?page=1&per_page=30")
resp['facts'].each do |item|
puts item.inspect
end
module ObjectTracker
module ClassMethods
def track_method(method_name)
alias_method :"#{method_name}_without_tracking", method_name
define_method :"#{method_name}_with_tracking" do |*splat|
params = self.class.instance_method(:"#{method_name}_without_tracking").parameters.collect(&:last)
self.send(:"#{method_name}_without_tracking", *splat) # do method first
self.track_event!(method_name, Hash[*(params.zip(splat).flatten)]) # then track
end
alias_method method_name, :"#{method_name}_with_tracking"
@chantastic
chantastic / on-jsx.markdown
Last active November 10, 2024 13:39
JSX, a year in

Hi Nicholas,

I saw you tweet about JSX yesterday. It seemed like the discussion devolved pretty quickly but I wanted to share our experience over the last year. I understand your concerns. I've made similar remarks about JSX. When we started using it Planning Center, I led the charge to write React without it. I don't imagine I'd have much to say that you haven't considered but, if it's helpful, here's a pattern that changed my opinion:

The idea that "React is the V in MVC" is disingenuous. It's a good pitch but, for many of us, it feels like in invitation to repeat our history of coupled views. In practice, React is the V and the C. Dan Abramov describes the division as Smart and Dumb Components. At our office, we call them stateless and container components (view-controllers if we're Flux). The idea is pretty simple: components can't

@dhoelzgen
dhoelzgen / base_controller.rb
Last active October 7, 2021 16:19
CORS in Rails 4 APIs
class API::V1::BaseController < ApplicationController
skip_before_filter :verify_authenticity_token
before_filter :cors_preflight_check
after_filter :cors_set_access_control_headers
def cors_set_access_control_headers
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Methods'] = 'POST, GET, PUT, DELETE, OPTIONS'
// ==UserScript==
// @name GM_download emulation
// @namespace http://tampermonkey.net/
// @version 0.1
// @description emulate GM_download functionality
// @require https://github.com/eligrey/FileSaver.js/raw/master/FileSaver.js
// @match http://tampermonkey.net/empty.html
// @grant GM_xmlhttpRequest
// @copyright 2014, Jan Biniok
// ==/UserScript==
@rstacruz
rstacruz / index.md
Last active November 3, 2023 09:56
Rails models cheatsheet

Rails Models

Generating models

$ rails g model User

Associations

belongs_to

has_one