Skip to content

Instantly share code, notes, and snippets.

Avatar
🕶️
😃

petitviolet petitviolet

🕶️
😃
View GitHub Profile
@petitviolet
petitviolet / Cargo.toml
Last active Sep 6, 2020
Simple logger implementation in Rust
View Cargo.toml
[dependencies]
log = { version = "0.4", features = [ "std" ] }
@petitviolet
petitviolet / main.dig
Created Apr 30, 2020
digdag's `http_call>` operator sample
View main.dig
+run_workflow:
http_call>: http://$(ip):8000/http_call_dig
retry: false
_retry: 2
@petitviolet
petitviolet / route.go
Created Apr 29, 2020
oEmbed API for blog.petitviolet.net
View route.go
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"regexp"
@petitviolet
petitviolet / rstruct.rb
Last active Jan 12, 2020
Struct implemented with Ruby
View rstruct.rb
module Rstruct
def self.new(*attributes)
names = caller.map do |stack|
# ".../hoge.rb:7:in `<module:Hoge>'"
if (m = stack.match(/\A.+in `<(module|class):(.+)>.+/))
m[2]
end
end.reject(&:nil?)
file_name, line_num = caller[0].split(':')
line_executed = File.readlines(file_name)[line_num.to_i - 1]
@petitviolet
petitviolet / graphiql.html
Created Dec 21, 2019
GraphQL Web UI with text box to edit AccessToken
View graphiql.html
<!-- https://github.com/howtographql/sangria/blob/master/src/main/resources/graphiql.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="robots" content="noindex" />
<meta name="referrer" content="origin" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>GraphiQL</title>
<style>
@petitviolet
petitviolet / tracer.rb
Created Dec 17, 2019
Tracing method calls using TracePoint
View tracer.rb
class Debugger
def initialize(events)
@tp = TracePoint.new(*(events || %i[call b_call raise])) do |tp|
tp.binding.irb
end
@tp.disable
end
def trace(&block)
@tp.enable
View cvimrc.vim
" general
set autoupdategist " gistの設定を自動反映
let scrollstep = 150
let fullpagescrollpercent = 100
set smoothscroll
set noautofocus " サイトを開いた時に入力欄にフォーカスが奪われるのを抑止
let searchlimit = 20
let barposition = "bottom"
@petitviolet
petitviolet / FileServer.go
Last active Apr 5, 2019
static file server written in golang.
View FileServer.go
package main
import (
"log"
"net/http"
)
func main() {
log.Println("Server started. 0.0.0.0:8080")
http.ListenAndServe(":8080", http.HandlerFunc(fileHandler))
@petitviolet
petitviolet / GenericDiff.scala
Created Nov 17, 2018
generic diff of case class instances
View GenericDiff.scala
import shapeless._
import shapeless.labelled.FieldType
object ClassDiff extends App {
sealed abstract class Field(name: String)
case class FieldSame(name: String) extends Field(name)
case class FieldDiff[A](name: String, before: A, after: A) extends Field(name)
trait GenericDiff[HL <: HList] {
@petitviolet
petitviolet / main.go
Last active Sep 10, 2018
benchmark for select from MySQL
View main.go
package main
import (
"database/sql"
"fmt"
_ "github.com/go-sql-driver/mysql"
"github.com/google/uuid"
"os"
"strings"
)
You can’t perform that action at this time.