Skip to content

Instantly share code, notes, and snippets.

View liuzxc's full-sized avatar
🎯
Focusing

刘兴起 liuzxc

🎯
Focusing
View GitHub Profile
@pftg
pftg / .circleci_config.yml
Created January 13, 2018 21:02
Pre-compile Assets and Cache for CircleCI
- restore_cache:
keys:
- v1-asset-cache-{{ arch }}-{{ .Branch }}
- v1-asset-cache-
- run: bundle exec rake assets:precompile
- save_cache:
key: v1-asset-cache-{{ arch }}-{{ .Branch }}-{{ epoch }}
paths:
@0sc
0sc / encrypt_decrypt.rb
Created January 12, 2018 16:12
Simple encrypt decrypt strings in ruby
require 'openssl'
def encrypt_string(str)
cipher_salt1 = 'some-random-salt-'
cipher_salt2 = 'another-random-salt-'
cipher = OpenSSL::Cipher.new('AES-128-ECB').encrypt
cipher.key = OpenSSL::PKCS5.pbkdf2_hmac_sha1(cipher_salt1, cipher_salt2, 20_000, cipher.key_len)
encrypted = cipher.update(str) + cipher.final
encrypted.unpack('H*')[0].upcase
end
@masutaka
masutaka / circle.yml
Created April 16, 2017 10:25
capistrano deployment using CircleCI 2.0
version: 2
jobs:
build:
docker:
- image: ruby:2.3.3-alpine
working_directory: /home/circleci/masutaka.net
steps:
- setup_remote_docker:
# https://circleci.com/docs/2.0/docker-layer-caching/
reusable: true
@ebenoist
ebenoist / consumer.go
Last active March 1, 2020 16:23
nsq consumer
package main
import (
"errors"
"log"
"os"
"os/signal"
"syscall"
"github.com/nsqio/go-nsq"
@pixeltrix
pixeltrix / time_vs_datatime.md
Last active February 18, 2024 19:20
When should you use DateTime and when should you use Time?

When should you use DateTime and when should you use Time?

It's a common misconception that [William Shakespeare][1] and [Miguel de Cervantes][2] died on the same day in history - so much so that UNESCO named April 23 as [World Book Day because of this fact][3]. However because England hadn't yet adopted [Gregorian Calendar Reform][4] (and wouldn't until [1752][5]) their deaths are actually 10 days apart. Since Ruby's Time class implements a [proleptic Gregorian calendar][6] and has no concept of calendar reform then there's no way to express this. This is where DateTime steps in:

>> shakespeare = DateTime.iso8601('1616-04-23', Date::ENGLAND)
=> Tue, 23 Apr 1616 00:00:00 +0000
>> cervantes = DateTime.iso8601('1616-04-23', Date::ITALY)
=> Sat, 23 Apr 1616 00:00:00 +0000
@jhass
jhass / .rubocop.yml
Last active December 15, 2023 22:23
My preferred Rubocop config
AllCops:
RunRailsCops: true
# Commonly used screens these days easily fit more than 80 characters.
Metrics/LineLength:
Max: 120
# Too short methods lead to extraction of single-use methods, which can make
# the code easier to read (by naming things), but can also clutter the class
Metrics/MethodLength:
@vitorbritto
vitorbritto / regex.md
Last active May 2, 2024 13:24
Regex Cheat Sheet

Regular Expressions

Basic Syntax

  • /.../: Start and end regex delimiters
  • |: Alternation
  • (): Grouping
@clintongormley
clintongormley / load_test_data.sh
Last active January 5, 2024 07:32
Run these commands in your shell to setup the test data for Chapter 5
curl -XPUT 'http://localhost:9200/us/user/1?pretty=1' -d '
{
"email" : "john@smith.com",
"name" : "John Smith",
"username" : "@john"
}
'
curl -XPUT 'http://localhost:9200/gb/user/2?pretty=1' -d '
{
@pyk
pyk / active-record-migration-expert.md
Last active August 2, 2021 09:20
become active record migration expert (Rails 4.0.2)

become active record migration expert (Rails 4.0.2)

workflow:

create model

$ rails g model NameOfModel
    invoke  active_record
    create    db/migrate/YYYYMMDDHHMMSS_create_name_of_models.rb
@mlavin
mlavin / NOTES.rst
Created September 23, 2013 14:17
Celery Late Ack Example

Running the Example

Start the worker:

celery -A tasks worker --loglevel=info -c 2 --pidfile=celery.pid

In another terminal send 6 tasks:

python script.py