Skip to content

Instantly share code, notes, and snippets.

View damaon's full-sized avatar
🍌
Banana

DT damaon

🍌
Banana
View GitHub Profile
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"
import UniversalRouter from 'universal-router';
const routes = [
{
path: '', // optional
action: () => `<h1>Home</h1>`,
},
{
path: '/posts',
action: () => console.log('checking child routes for /posts'),
@damaon
damaon / deft
Created December 18, 2017 09:25
Generate types from widget template code
#!/usr/bin/env ruby
require "json"
search_for = ARGV.shift || "widget"
file = ARGF.read
search_regex = /#{search_for}\.[^ "'}]*/i
lines = file.scan(search_regex)
@damaon
damaon / lodash-transform.js
Created December 14, 2017 15:37 — forked from robtarr/lodash-transform.js
jscodeshift - replace `_.thing(...)` with `thing(...)` and add `import {thing} from 'lodash'`
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;
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];
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; }
# 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)
class LazyRepresenter
def initialize
@getters = []
end
def call(object)
@getters.reduce({}) do |hash, getter|
hash.merge(getter.call(object))
end
end
#!/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
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]