Skip to content

Instantly share code, notes, and snippets.

View logrusorgru's full-sized avatar

Konstantin Ivanov logrusorgru

View GitHub Profile
@logrusorgru
logrusorgru / mysql.sql
Last active January 16, 2024 07:01
SQL: uniqueness, automatic created_at, updated_at refresh + soft delete. SQLite, PostgreSQL, MySQL
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- --
-- mysql --
-- --
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
--
-- mysql <http://sqlfiddle.com/#!9/91afb5/2>
-- note: sqlfiddle is very stupid
@logrusorgru
logrusorgru / gin-logger.go
Created March 10, 2016 09:12
Gin logger without colors
/*
// Creates a router without any middleware by default
r := gin.New()
r.Use(gin.Recovery())
r.Use(logger.Logger()) // use this logger without colors
*/
package logger
@logrusorgru
logrusorgru / Makefile
Last active January 25, 2023 18:13
GNU Assembler: пишем разделяемые библиотеки
all: clean build run
build:
gcc -nostdlib -Wall -shared -fPIC hello_exit.S -Wl,-soname,libhelloexit.so.1 -o libhelloexit.so.1.0
ln -sv libhelloexit.so.1.0 libhelloexit.so.1
ln -sv libhelloexit.so.1.0 libhelloexit.so
gcc -nostdlib -Wall -L. -I. hello.c -lhelloexit -Wl,-rpath,. -o hello
@echo Done
run:
@logrusorgru
logrusorgru / gist:60710e8faf8a50631fc3
Created September 21, 2014 12:53
Colorized Golang output

Colorized Golang output

Get package from here

// import "golorize"

fmt.Println( golorize.Red("[FAIL] Some Errors Occurred") )
@logrusorgru
logrusorgru / gist:848683192f1549fbb021
Last active August 29, 2015 14:04
ActiveRecord serialize, make it faster

ActiveRecord Serialize

serialize :column, JSON realy faster then standart YAML serialize

Small benchmark

class Some &lt; ActiveRecord:Base
@logrusorgru
logrusorgru / gist:63ba4fed0485e450c084
Last active August 29, 2015 14:02
Nokogiri and dollar sign $

Nokogiri does not understand the dollar sign $ in selectors.

Some example:

require 'nokogiri'

html = %Q{
  <!DOCTYPE html>
 
@logrusorgru
logrusorgru / r3r4lambda.md
Last active August 29, 2015 14:02
Rails 3 to Rails 4 => lambda instead of conditions

Rails 3

has_many  :active_events, :through => :event_users, 
          :class_name => "Event", 
          :source => :event, 
          :conditions => ['event_users.active = ?',true]

Rails 4

@logrusorgru
logrusorgru / gist:9867976
Last active December 16, 2022 02:54
Rails - How to check for online users? Redis.

Rails - How to check for online users? Redis.

Init Redis

   # config/initializers/redis.rb
    
   $redis_onlines = Redis.new
   # it's the simplest way, but i'd recommend:
   # $redis_onlines = Redis.new path: "/tmp/redis.sock", db: 15, driver: :hiredis