Skip to content

Instantly share code, notes, and snippets.

View pachacamac's full-sized avatar
🌶️
Mmmmhmmmm

Marc pachacamac

🌶️
Mmmmhmmmm
  • Hacker/Founder
  • Germany, Berlin
View GitHub Profile
@pachacamac
pachacamac / monaco-editor.html
Last active September 7, 2020 22:35
monaco editor
<!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">
@pachacamac
pachacamac / gitlab_issues_to_csv.rb
Created January 10, 2020 15:17
gitlab_issues_to_csv
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 September 27, 2019 12:53
human readable time differences without dependencies
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:
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 June 28, 2018 17:59
get current factory berlin events
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 13:27
reminder script in ruby
#!/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 13:56
rock paper scissors lizard spock
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
https://app.joincoup.com/api/v1/scooters.json
https://app.joincoup.com/api/v1/business_areas.json
@pachacamac
pachacamac / rubocop.yml
Created September 8, 2017 09:51
rubocop config
AllCops:
RunRailsCops: true
TargetRubyVersion: 2.4
Style/Encoding:
Enabled: false
Metrics/LineLength:
Max: 120
@pachacamac
pachacamac / hooks.rb
Created June 5, 2017 15:07
add before and after hooks
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