Skip to content

Instantly share code, notes, and snippets.

@TimLang
TimLang / CoordConvert.rb
Created June 26, 2023 06:11 — forked from fcce/CoordConvert.rb
ruby 版经纬度坐标系转换
class CoordConvert
class << self
PI = 3.14159265358979324
X_PI = PI * 3000.0 / 180.0 #圆周率转换量
## Krasovsky 1940
## a = 6378245.0, 1/f = 298.3
## b = a * (1 - f)
## ee = (a^2 - b^2) / a^2
A = 6378245.0 #椭球体的长半轴半径
EE = 0.00669342162296594323 #椭球体的第一偏心率
@TimLang
TimLang / rails http status codes
Created April 26, 2023 14:14 — forked from mlanett/rails http status codes
HTTP status code symbols for Rails
HTTP status code symbols for Rails
Thanks to Cody Fauser for this list of HTTP responce codes and their Ruby on Rails symbol mappings.
Status Code Symbol
1xx Informational
100 :continue
101 :switching_protocols
102 :processing
@TimLang
TimLang / puma.service
Created April 20, 2023 07:15 — forked from arteezy/puma.service
Manage Puma with systemd and rbenv
[Unit]
Description=Puma Rails Server
After=network.target
[Service]
Type=simple
User=deploy
WorkingDirectory=/home/deploy/app/current
ExecStart=/home/deploy/.rbenv/bin/rbenv exec bundle exec puma -C /home/deploy/app/shared/config/puma.rb
ExecStop=/home/deploy/.rbenv/bin/rbenv exec bundle exec pumactl -S /home/deploy/app/shared/tmp/pids/puma.state stop
@TimLang
TimLang / gist:ffc7c03cf277fd83526194b831289fd1
Created July 21, 2020 02:01 — forked from sukeerthiadiga/gist:3772311
Mysql2::Error: Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE)
locate my.cnf
change character set and collation
[mysqld]
character_set_server = utf8
collation_server = utf8_general_ci
in console if your database is not huge.
PUT /term_test
{
"settings": {
"index": {
"number_of_shards": 2,
"number_of_replicas": 0
}
},
"mappings": {
"item": {
@TimLang
TimLang / receipt
Created July 31, 2018 08:08 — forked from sauloarruda/receipt
Apple iOS in app purchase validate receipt in Ruby
ewoJInNpZ25hdHVyZSIgPSAiQXBNVUJDODZBbHpOaWtWNVl0clpBTWlKUWJLOEVk
ZVhrNjNrV0JBWHpsQzhkWEd1anE0N1puSVlLb0ZFMW9OL0ZTOGNYbEZmcDlZWHQ5
aU1CZEwyNTBsUlJtaU5HYnloaXRyeVlWQVFvcmkzMlc5YVIwVDhML2FZVkJkZlcr
T3kvUXlQWkVtb05LeGhudDJXTlNVRG9VaFo4Wis0cFA3MHBlNWtVUWxiZElWaEFB
QURWekNDQTFNd2dnSTdvQU1DQVFJQ0NHVVVrVTNaV0FTMU1BMEdDU3FHU0liM0RR
RUJCUVVBTUg4eEN6QUpCZ05WQkFZVEFsVlRNUk13RVFZRFZRUUtEQXBCY0hCc1pT
QkpibU11TVNZd0pBWURWUVFMREIxQmNIQnNaU0JEWlhKMGFXWnBZMkYwYVc5dUlF
RjFkR2h2Y21sMGVURXpNREVHQTFVRUF3d3FRWEJ3YkdVZ2FWUjFibVZ6SUZOMGIz
SmxJRU5sY25ScFptbGpZWFJwYjI0Z1FYVjBhRzl5YVhSNU1CNFhEVEE1TURZeE5U
SXlNRFUxTmxvWERURTBNRFl4TkRJeU1EVTFObG93WkRFak1DRUdBMVVFQXd3YVVI
async def main():
coroutine1 = do_some_work(1)
coroutine2 = do_some_work(2)
coroutine3 = do_some_work(4)
tasks = [
asyncio.ensure_future(coroutine1),
asyncio.ensure_future(coroutine2),
asyncio.ensure_future(coroutine3)
]
@TimLang
TimLang / gist:1b17b16e7652617ccf4c941eabc2632a
Created May 14, 2018 02:27 — forked from tmc/gist:777085
multiprocessing gevent chat example
import sys
import gevent
from gevent.monkey import patch_all; patch_all()
from gevent import server, event, socket
from multiprocessing import Process, current_process, cpu_count
"""
Simple multiprocess StreamServer that proxies messages between clients.
Avoids using a multiprocessing.Event since it blocks on a semaphore.
@TimLang
TimLang / rest_client.ex
Created January 19, 2017 09:24 — forked from miwee/rest_client.ex
Rest Client implementation based on HTTPoison
defmodule RestClient do
require Logger
alias Poison, as: JSON
@baseurl "http://someapi.com"
@username "username"
@password "password"
def get_by_path(path, id, params)
when is_binary(id) or is_integer(id) and is_list(params) do
@TimLang
TimLang / gist:10986e93267ae554e3aa3a190b5083ec
Created January 17, 2017 04:05 — forked from tamoyal/gist:2ea1fcdf99c819b4e07d
Upgrade Postgres 9.3 to 9.4 on Ubuntu
# Be sure to save your config files. Optional but I do:
sudo cp /etc/postgresql/9.3/main/postgresql.conf ~
sudo cp /etc/postgresql/9.3/main/pg_hba.conf ~
# Package repo (for apt-get)
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" >> /etc/apt/sources.list.d/postgresql.list'
# Also probably optional but I like to update sources and upgrade
sudo apt-get update