Skip to content

Instantly share code, notes, and snippets.

View edwinlab's full-sized avatar
🐢
run

Edwin edwinlab

🐢
run
View GitHub Profile
@edwinlab
edwinlab / build.gradle
Created June 8, 2018 07:47
Setup sonarqube on travis
dependencies {
classpath 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.5'
}
apply plugin: 'org.sonarqube'
sonarqube {
properties {
property "sonar.host.url", "http://sonarserver.com"
}
package main
import (
"fmt"
)
type usd int64
func USD(f float64) usd {
return usd((f * 100) + 0.5)
wget --no-cookies \
--no-check-certificate \
--header "Cookie: oraclelicense=accept-securebackup-cookie" \
"http://download.oracle.com/otn-pub/java/jdk/8u161-b12/2f38c3b165be4555a1fa6e98c45e0808/jdk-8u161-linux-x64.rpm" \
-O jdk-8-linux-x64.rpm
1. Download the file
2. mkdir installer && cd installer && mv jdk-8u161-linux-x64.rpm* jdk-8u161-linux-x64.rpm
3. yum list installed java* && sudo yum remove java-1.7.0-openjdk.x86_64

Run SonarQube with a PostgreSQL database

Requirements

  • Docker Engine 1.9
  • Docker Compose 1.6

Compose file

Create this docker-compose.yml file:

CREATE ROLE your_role NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN;
ALTER ROLE your_role WITH PASSWORD ‘your_password';
GRANT USAGE ON schema public TO your_role;
GRANT SELECT, UPDATE, INSERT, DELETE ON your_table TO your_role;
func split(buf []int, lim int) [][]int {
var chunk []int
chunks := make([][]int, 0, len(buf)/lim+1)
for len(buf) >= lim {
chunk, buf = buf[:lim], buf[lim:]
chunks = append(chunks, chunk)
}
if len(buf) > 0 {
chunks = append(chunks, buf[:len(buf)])
}
1609-09-12 19:02:35 PM +03:00 Sep Sat PDT 
--------------- + ------------ + ------------ 
Type            | Placeholder  |        Value 
--------------- + ------------ + ------------ 
Year            | 2006         | 1609         
Year            | 06           | 09           
Month           | 01           | 09           
Month           | 1            | 9            
Month           | Jan          | Sep          
package main
import (
"fmt"
"io"
"os"
)
var path = "/Users/novalagung/Documents/temp/test.txt"
@edwinlab
edwinlab / union_scope.rb
Created November 7, 2017 08:24 — forked from tlowrimore/union_scope.rb
Unions multiple scopes on a model, and returns an instance of ActiveRecord::Relation.
module ActiveRecord::UnionScope
def self.included(base)
base.send :extend, ClassMethods
end
module ClassMethods
def union_scope(*scopes)
id_column = "#{table_name}.#{primary_key}"
sub_query = scopes.map { |s| s.select(id_column).to_sql }.join(" UNION ")
where "#{id_column} IN (#{sub_query})"
require 'timeout'
def a_method(iterations)
Timeout::timeout(1) do # 1 second
iterations.times { |i| print("#{i} "); sleep(0.1) }
end
rescue Timeout::Error
print("TIMEOUT")
ensure
puts