Skip to content

Instantly share code, notes, and snippets.

View allenwei's full-sized avatar

Allen Wei allenwei

  • Gradual Inc.
  • Xi'an, China
View GitHub Profile
@allenwei
allenwei / App.js
Last active November 12, 2021 01:41
useState with props correct way
import React from "react";
const Box = ({ num }) => {
const [state, setState] = React.useState(num);
React.useEffect(() => {
setState(num);
}, [num]);
return <div>child state ${state}</div>;
@allenwei
allenwei / App.js
Last active March 17, 2020 00:25
useState with props Wrong way
import React from "react";
const Box = ({ num }) => {
const [state, setState] = React.useState(num);
return <div>child state ${state}</div>;
};
const App = () => {
const [state, setState] = React.useState();
@allenwei
allenwei / sphinx.rb
Created January 21, 2015 03:20 — forked from assimovt/sphinx.rb
require 'formula'
class Libstemmer < Formula
# upstream is constantly changing the tarball,
# so doing checksum verification here would require
# constant, rapid updates to this formula.
head 'http://snowball.tartarus.org/dist/libstemmer_c.tgz'
homepage 'http://snowball.tartarus.org/'
end
@allenwei
allenwei / 0_reuse_code.js
Last active August 29, 2015 14:11
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@allenwei
allenwei / CocoaHTTPServer.podspec
Created March 28, 2012 12:42
CocoaHTTPServer.podspec
Pod::Spec.new do |s|
s.name = 'CocoaHTTPServer'
s.version = '2.2.1'
s.license = 'BSD'
s.summary = 'A small, lightweight, embeddable HTTP server for Mac OS X or iOS applications'
s.homepage = 'https://github.com/robbiehanson/CocoaHTTPServer'
s.authors = { 'Robbie Hanson' => 'cocoahttpserver@googlegroups.com' }
s.source = { :git => 'https://github.com/robbiehanson/CocoaHTTPServer.git', :tag => '2.2.1' }
s.source_files = '{Core,Extensions}/**/*.{h,m}'
s.clean_paths = %w{Samples Vendor}
@allenwei
allenwei / restkit_master.podspec
Created March 26, 2012 14:21
restkit podspec master
Pod::Spec.new do |s|
s.name = 'RestKit'
s.version = '0.9.3'
s.summary = 'RestKit is a framework for consuming and modeling RESTful web resources on iOS and OS X.'
s.homepage = 'http://www.restkit.org'
s.author = { 'Blake Watters' => 'blakewatters@gmail.com' }
s.source = { :git => 'https://github.com/RestKit/RestKit.git' }
# It has no source_files itself, so the resolver should not allow dependencies on this spec unless it’s a `part_of' type dependency
@allenwei
allenwei / gist:1488989
Created December 17, 2011 02:59
Include Module in Class
class User
include UserModules::Invitation
end
module UserModules::Invitation
extend ActiveSupport::Concern
included do
validate :validate_invitation_code
after_create :apply_invitation_code
has_one :invitation, :class_name => "InvitationCode"
@allenwei
allenwei / gist:1488988
Created December 17, 2011 02:59
Include Module in Class
class User
include UserModules::Invitation
end
module UserModules::Invitation
extend ActiveSupport::Concern
included do
validate :validate_invitation_code
after_create :apply_invitation_code
has_one :invitation, :class_name => "InvitationCode"