Skip to content

Instantly share code, notes, and snippets.

View Kangaroux's full-sized avatar
🌈
feeling colorful

Jessie Kangaroux

🌈
feeling colorful
  • US
View GitHub Profile
@henriquebastos
henriquebastos / secret_gen.py
Created December 23, 2015 13:50
SECRET_KEY generator.
#!/usr/bin/env python
"""
Django SECRET_KEY generator.
"""
from django.utils.crypto import get_random_string
chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)'
print(get_random_string(50, chars))
@xcsrz
xcsrz / server.go
Created January 2, 2016 07:12
A golang web server on a randomly (os) chosen port.
package main
import (
"fmt"
"github.com/skratchdot/open-golang/open"
"net"
"net/http"
)
func main() {
@Kangaroux
Kangaroux / .go
Created May 20, 2021 02:40
Golang: Parse JSON field name from a struct field
// ParseFieldName takes a reflected struct field and returns the JSON name for the field,
// as well if the field is ignored by JSON (using `json:"-"`).
func ParseFieldName(f reflect.StructField) (name string, ignore bool) {
tag := f.Tag.Get("json")
if tag == "" {
return f.Name, false
}
if tag == "-" {
@Kangaroux
Kangaroux / observable.ts
Created August 17, 2021 18:43
Observable class for typescript
/**
* Simple class for managing callable observers.
*/
export class Observable<Fn extends (...args) => any> {
private observers: Set<Fn> = new Set();
add(o: Fn): void {
this.observers.add(o);
}
@Kangaroux
Kangaroux / hex_to_rgba.go
Last active April 19, 2022 18:22
Golang: Hex to RGB/RGBA
// HexToRGB converts a 24 bit hex number into its corresponding RGB color
// with 100% alpha
//
// clr := HexToRGB(0xFFAA00)
// fmt.Printf("%+v\n", clr) // {R:255 G:170 B:0 A:255}
func HexToRGB(hex uint32) color.RGBA {
r := uint8((hex & 0xFF0000) >> 16)
g := uint8((hex & 0xFF00) >> 8)
b := uint8(hex & 0xFF)