Skip to content

Instantly share code, notes, and snippets.

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

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:

View notes.rb
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
View player.rb
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 / notevalues.json
Created Nov 1, 2016
note frequency value
View notevalues.json
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,
@marcgg
marcgg / generate_scripts.rb
Created Feb 14, 2016
Generating shell scripts
View generate_scripts.rb
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 / flow-matic
Last active Aug 29, 2015
flow-matic
View 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 .
View mysql_index_madness.rb
require 'benchmark'
ActiveRecord::Base.logger = nil
ActiveRecord::Schema.verbose = false
ActiveRecord::Migration.verbose = false
# PARAMS
sql = ""
attributes = []
@marcgg
marcgg / gist:2e57218351e27fcc20c4
Last active Apr 7, 2018
Mapping of country codes with international phone number prefixes, in JSON!
View gist:2e57218351e27fcc20c4
{
"AF": "93",
"AL": "355",
"DZ": "213",
"AD": "376",
"AO": "244",
"AQ": "672",
"AR": "54",
"AM": "374",
"AW": "297",
@marcgg
marcgg / gist:cf32671acae8ed30a219
Created Jul 31, 2014
Concat all i18n trads into one big file
View gist:cf32671acae8ed30a219
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