This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gh_print() { | |
local github_url="$1" | |
local repo_name=$(basename "$github_url" .git) | |
local tmp_dir="/tmp/$repo_name" | |
# Clone the repository | |
if git clone "$github_url" "$tmp_dir" > /dev/null 2>&1; then | |
: # Silent success | |
else | |
echo "Failed to clone repository" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UniversalRouter from 'universal-router'; | |
const routes = [ | |
{ | |
path: '', // optional | |
action: () => `<h1>Home</h1>`, | |
}, | |
{ | |
path: '/posts', | |
action: () => console.log('checking child routes for /posts'), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require "json" | |
search_for = ARGV.shift || "widget" | |
file = ARGF.read | |
search_regex = /#{search_for}\.[^ "'}]*/i | |
lines = file.scan(search_regex) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default (fileInfo, api) => { | |
const j = api.jscodeshift; | |
const methods = []; | |
const root = j(fileInfo.source); | |
const body = root.find(j.Program).get('body', 0).node; | |
const { comments } = body; | |
delete body.comments | |
root.get().node.comments = comments; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type ReduxAction = { type: string }; | |
type Reducer<T> = (T, ReduxAction) => T; | |
type ReducerDefinition<T> = { [ACTION_TYPE: string]: (ReduxAction) => (T) => T }; | |
export function createReducer<T>( | |
initialState: T, | |
definition: ReducerDefinition<T> | |
): Reducer<T> { | |
return (state: T = initialState, action: ReduxAction): T => { | |
const actionResponse = definition[action.type]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bundle exec rubocop -a || { echo "Fix rubocop errors and try again!" ; exit 1; } | |
./bin/coffeelint app || { echo "Fix coffeelint errors and try again!" ; exit 1; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# withFn(name, function, arguments) | |
augument = (object, withFn) -> | |
_.each _.keys(object), (name) -> | |
fn = object[name] | |
if (typeof fn == 'function') | |
object[name] = ((name, fn) -> | |
args = arguments | |
-> | |
withFn.apply(this, [args[0], args[1], arguments]) | |
fn.apply(this, arguments) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LazyRepresenter | |
def initialize | |
@getters = [] | |
end | |
def call(object) | |
@getters.reduce({}) do |hash, getter| | |
hash.merge(getter.call(object)) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# If errors spotted return true | |
def check_file_size!(path, file) | |
if file.lines.size > 150 | |
puts "[FILE SIZE][#{path}] MAX: 150 lines" | |
return true | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rails c | |
irb(main):011:0> rr = Rack::Request.new({}) | |
=> #<Rack::Request:0x007fb6a11193d8 @env={}> | |
irb(main):012:0> rr.method(:location).source | |
=> " def location\n @location ||= Geocoder.search(geocoder_spoofable_ip, ip_address: true).first\n end\n" | |
irb(main):003:0> rr.method(:location).source_location | |
=> ["/Users/damiantrojnar/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/geocoder-1.2.14/lib/geocoder/request.rb", 8] |
NewerOlder