Skip to content

Instantly share code, notes, and snippets.

View tonidezman's full-sized avatar
🎯
Focusing

Toni Dezman tonidezman

🎯
Focusing
View GitHub Profile
comment = "# frozen_string_literal: true\n"
filemode = "r+"
dirs = Dir[Rails.root.join('spec/**/*.rb').to_s] + Dir[Rails.root.join('lib/**/*.rake').to_s] + Dir[Rails.root.join('lib/**/*.rb').to_s]
dirs.each do |filename|
contents = File.open(filename, "r") do |f|
f.read
end
contents = comment + contents
@istana
istana / devise.sk.yml
Created June 26, 2013 13:07
Slovak locale for Devise
# Additional translations at https://github.com/plataformatec/devise/wiki/I18n
# Just to be clear:
# Author: Ivan Stana, http://github.com/istana
# License: MIT
# Base file: devise.en.yml
# Some elements taken from https://gist.github.com/MarosPixel/1295185 thx
# For versions 2.2, 3.0, maybe other
sk:
@robinboening
robinboening / player.rb
Last active January 13, 2019 06:16
ruby-warrior level6
class Player
FULL_HEALTH = 20
def play_turn(warrior)
@warrior = warrior
if need_to_rest?
if able_to_rest?
warrior.rest!
@baweaver
baweaver / open_source.md
Created December 2, 2016 18:14
So you want to start on Open Source?

So you want to start on Open Source?

A short guide for getting you started into the magical world of OSS.

What is your passion?

Are you a musician? Look for musical tools. Are you an artist? Look for some graphics libraries. Find something that works with your other passions to get you going.

If your passion is programming, look for ways to improve the environment.

@brysgo
brysgo / post_checkout_migrations.sh
Last active October 5, 2019 11:13 — forked from skyriverbend/rails_switch_branch.py
Post checkout hook for managing rails migrations and bundle install
CHECKING_OUT_BRANCH=$3
OLD_BRANCH=$1
NEW_BRANCH=$2
if [ $CHECKING_OUT_BRANCH -eq 1 ]
then
FILES_CHANGED=`git diff $OLD_BRANCH $NEW_BRANCH --name-status`
MIGRATIONS_REMOVED=`echo "$FILES_CHANGED" | egrep 'D\tdb/migrate/([0-9]+)' | sort -r`
MIGRATIONS_ADDED=`echo "$FILES_CHANGED" | egrep 'A\tdb/migrate/([0-9]+)'`
@chumpy
chumpy / yaml_compare.rb
Created January 29, 2012 00:20
compare two yaml files in ruby
#require 'active_support/core_ext'
class YamlCompare
def self.compare_keys first_file_info, second_file_info, results_location
first_file = Hash.new
second_file = Hash.new
deltas_file = Hash.new
File.open( first_file_info[:file_location] ) { |yf| first_file = YAML.load( yf ) }
File.open( second_file_info[:file_location] ) { |yf| second_file = YAML.load( yf ) }
first_file[first_file_info[:root]].each_pair do |k,v|
@mssola
mssola / singleton.rb
Created August 2, 2013 07:44
Different ways to create the Singleton pattern in Ruby.
##
# This files shows some possible implementations of the Singleton pattern
# in Ruby. I'm not a huge fan of the Singleton pattern, but it's nice
# in some cases. In this file I'm going to implement a simple logger.
#
##
# The first implementation that can come to our minds is to create a class
# that holds an instance as a class variable that can be accessed through
@jonatas
jonatas / hypertable_trigger.sql
Last active January 24, 2022 08:36
Timescale continuous aggregates over top of continuous aggregates - Caggs over top of caggs (POC)
DROP TABLE ticks CASCADE;
DROP TABLE ohlc_1s CASCADE;
CREATE TABLE ticks ( time TIMESTAMP NOT NULL, symbol varchar, price decimal, volume int);
CREATE TABLE ohlc_1s ( time TIMESTAMP NOT NULL, symbol varchar, o decimal, h decimal, l decimal, c decimal, v int);
SELECT create_hypertable('ticks', 'time');
SELECT create_hypertable('ohlc_1s', 'time');
CREATE OR REPLACE FUNCTION feed_ohlc_1s() RETURNS trigger AS
$BODY$
DECLARE
@stupidbodo
stupidbodo / consistent-hashing.py
Created December 31, 2015 02:46
Consistent Hashing Example - Python
from hashlib import md5
from bisect import bisect
class Ring(object):
def __init__(self, server_list, num_replicas=3):
nodes = self.generate_nodes(server_list, num_replicas)
hnodes = [self.hash(node) for node in nodes]
hnodes.sort()
@cansadadeserfeliz
cansadadeserfeliz / tests.py
Last active December 28, 2022 09:20
Mock/replace timezone.now() with a custom date in Django unittes
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import datetime
from mock import patch
from django.test import TestCase
from django.utils import timezone
class DatesTestCase(TestCase):