Skip to content

Instantly share code, notes, and snippets.

Avatar
🍪
Mmmmmmm

Marc pachacamac

🍪
Mmmmmmm
  • Hacker/Founder
  • Germany, Berlin
View GitHub Profile
View monaco-editor.html
<!doctype html>
<head>
<title>Frontend Playground</title>
<meta charset=utf8>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="robots" content="noindex, nofollow">
<meta name="googlebot" content="noindex, nofollow">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" data-name="vs/editor/editor.main" href="https://unpkg.com/monaco-editor@0.8.3/min/vs/editor/editor.main.css">
View gitlab_issues_to_csv.rb
require 'gitlab'
require 'json'
require 'time'
require 'csv'
Gitlab.endpoint = 'https://gitlab.com/api/v4'
Gitlab.private_token = '<ENTER YOUR PRIVATE TOKEN>'
PROJECT_ID = 123 # ENTER YOUR PROJECT_ID
def parse_times(items)
@pachacamac
pachacamac / time_in_words.rb
Last active Sep 27, 2019
human readable time differences without dependencies
View time_in_words.rb
def td_in_words(s, skip: 1)
words = [['years',0], ['months',1], ['days',1], ['hours',0], ['minutes',0], ['seconds',0]]
vals = (Time.mktime(0)+s).strftime("%Y %m %d %H %M %S").split(' ').map(&:to_i)
skip.times{ words.pop && vals.pop }
str = vals.zip(words).select{|v,(w,n)| v!=n}.map{|v,(w,n)| [v-n, (v-n)==1 ? w[0..-2] : w]}.map{|v,w| "#{v} #{w}"}.join(' ')
str = "0 #{words.last[0]}" if str.empty?
str
end
#usage:
View deep_objectize_json
JSON.parse({a: { b: { c: 1 }}}.to_json, object_class: OpenStruct)
https://stackoverflow.com/questions/26809848/convert-hash-to-object
@pachacamac
pachacamac / factory_events_json.rb
Created Jun 28, 2018
get current factory berlin events
View factory_events_json.rb
require 'mechanize'
require 'open-uri'
require 'json'
require 'time'
def mechanize_session
browser = Mechanize.new
#browser.history_added = Proc.new { sleep 0.5 }
browser.user_agent = 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36'
yield(browser)
@pachacamac
pachacamac / remind_me
Last active May 29, 2018
reminder script in ruby
View remind_me
#!/usr/bin/env ruby
require 'chronic'
require 'time'
require 'securerandom'
abort('notify-send not installed') if `which notify-send`.empty?
ts = ARGV.join(' ')
t = Chronic.parse(ts)
@pachacamac
pachacamac / rpsls.rb
Created May 26, 2018
rock paper scissors lizard spock
View rpsls.rb
VALID_CHOICES = {
'rock' => %w(scissors lizard),
'paper' => %w(rock spock),
'scissors' => %w(paper lizard),
'lizard' => %w(paper spock),
'spock' => %w(rock scissors)
}
last_player_choice = nil
strategy_modifier = rand(0.2..0.8)
player_score = 0
View coup apis
https://app.joincoup.com/api/v1/scooters.json
https://app.joincoup.com/api/v1/business_areas.json
View rubocop.yml
AllCops:
RunRailsCops: true
TargetRubyVersion: 2.4
Style/Encoding:
Enabled: false
Metrics/LineLength:
Max: 120
@pachacamac
pachacamac / hooks.rb
Created Jun 5, 2017
add before and after hooks
View hooks.rb
module Hooks
def before(*method_names, &block)
to_prepend = Module.new do
method_names.each do |name|
define_method(name) do |*args, &blk|
yield(name, *args)
super(*args, &blk)
end
end
end
You can’t perform that action at this time.