Skip to content

Instantly share code, notes, and snippets.

@marcgg
marcgg / gist:cf32671acae8ed30a219
Created July 31, 2014 13:17
Concat all i18n trads into one big file
require "yaml"
class ::Hash
# From activeressource
def deep_merge(other_hash)
self.merge(other_hash) do |key, oldval, newval|
oldval = oldval.to_hash if oldval.respond_to?(:to_hash)
newval = newval.to_hash if newval.respond_to?(:to_hash)
oldval.class.to_s == 'Hash' && newval.class.to_s == 'Hash' ? oldval.deep_merge(newval) : newval
end
@marcgg
marcgg / gist:2e57218351e27fcc20c4
Last active April 7, 2018 19:25
Mapping of country codes with international phone number prefixes, in JSON!
{
"AF": "93",
"AL": "355",
"DZ": "213",
"AD": "376",
"AO": "244",
"AQ": "672",
"AR": "54",
"AM": "374",
"AW": "297",
require 'benchmark'
ActiveRecord::Base.logger = nil
ActiveRecord::Schema.verbose = false
ActiveRecord::Migration.verbose = false
# PARAMS
sql = ""
attributes = []
@marcgg
marcgg / flow-matic
Last active August 29, 2015 14:14
flow-matic
(0) INPUT INVENTORY FILE-A PRICE FILE-B ; OUTPUT PRICED-INV FILE-C UNPRICED-INV
FILE-D ; HSP D .
(1) COMPARE PRODUCT-NO (A) WITH PRODUCT-NO (B) ; IF GREATER GO TO OPERATION 10 ;
IF EQUAL GO TO OPERATION 5 ; OTHERWISE GO TO OPERATION 2 .
(2) TRANSFER A TO D .
(3) WRITE-ITEM D .
(4) JUMP TO OPERATION 8 .
(5) TRANSFER A TO C .
(6) MOVE UNIT-PRICE (B) TO UNIT-PRICE (C) .
(7) WRITE-ITEM C .
@marcgg
marcgg / generate_scripts.rb
Created February 14, 2016 16:57
Generating shell scripts
run_template = "rvm use 2.2.3
cd FULL_PATH
echo FULL_PATH: STARTED
bundle install
echo FULL_PATH: DONE BUNDLING
rake db:drop RAILS_ENV=test
rake db:create RAILS_ENV=test
rake db:migrate RAILS_ENV=test
echo FULL_PATH: DONE WITH MIGRATIONS
bundle exec rspec spec/controllers/students_controller_spec.rb spec/models/exam_spec.rb spec/models/grade_spec.rb spec/models/student_spec.rb > ../rspec_results.log
@marcgg
marcgg / notevalues.json
Created November 1, 2016 10:56
note frequency value
var noteValues = {
'C0': 16.35,
'C#0': 17.32,
'Db0': 17.32,
'D0': 18.35,
'D#0': 19.45,
'Eb0': 19.45,
'E0': 20.60,
'F0': 21.83,
'F#0': 23.12,
class Player
def self.all
REDIS.smembers("player_ids").map do |player_id|
JSON.parse(REDIS.get("player_#{player_id}"))
end
end
def self.add(player_json)
player = JSON.parse(player_json)
raise "Player is blank" if player.blank?
@marcgg
marcgg / notes.rb
Last active November 20, 2016 14:27
class Note
def self.add(player_id, x, y)
key = "note_#{SecureRandom.hex}"
REDIS.set(key, {
x: x, y: y, player_id: player_id
}.to_json)
REDIS.expire(key, 5)
broadcast_note(player_id, x, y)
REDIS.incr("count_notes")
end

Keybase proof

I hereby claim:

  • I am marcgg on github.
  • I am marcgg (https://keybase.io/marcgg) on keybase.
  • I have a public key ASDSHW5G88X7EPK9KNVO354Zm_XExZ6qSKYYOk14-d3_YQo

To claim this, I am signing this object:

import SwiftUI
let timer = Timer
.publish(every: 1, on: .main, in: .common)
.autoconnect()
struct Clock: View {
var counter: Int
var countTo: Int