Skip to content

Instantly share code, notes, and snippets.

View srph's full-sized avatar
🛠️
Building @Stride-Labs Frontend

Kier Borromeo srph

🛠️
Building @Stride-Labs Frontend
View GitHub Profile
@srph
srph / index.js
Created October 13, 2018 02:53
JS: Sort by h4 text
x.sort((a, b) => z(a) > z(b))
function z(str) {
return (<h4 style="text-align: center;">)[A-Za-z\,\s]+(<\/h4>)/.exec(str)[0].replace('<h4 style="text-align: center;">', '').replace('</h4>', '').replace(', CA', '')
}
@srph
srph / Tree.json
Last active September 3, 2018 16:31
JS: Flatten tree
{
"id": 1,
"name": "sample 1",
"child": [
{
"id": 12,
"name": "sample 12",
"child": [],
"parentId": 1
},
@srph
srph / index.js
Created September 1, 2018 07:29
JS: Get all 1080 magnet links from HorribleSubs
var els = Array.from(
document.querySelectorAll(".rls-info-container .link-1080p .hs-magnet-link a")
);
var links = ''
for (let i = 0; i < els.length; i++) {
var prefix = i === 0 ? '' : '\n\n'
var magnet = els[i];
links += `${prefix}${magnet.href}`
@srph
srph / chunk-pattern.js
Last active December 18, 2020 14:54
JS: Chunk an array in a pattern (Initial implementation of https://github.com/srph/chunk-pattern)
/* @flow */
/**
* Chunks an array in a specific pattern
* @example chunkPattern(['haha', 'haha', 'haha', 'haha', 'haha', 'haha', 'haha', 'haha', 'haha'], [2, 3])
* @return Array<Array<*>>
*/
function chunkPattern(array: Array<*>, pattern: Array<number>): Array<Array<*>> {
const result: Array<Array<*>> = []
@srph
srph / main.go
Created August 11, 2018 03:48
Go: Decode SOAP XML
package main
import (
"encoding/xml"
"fmt"
)
const data = `<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
@srph
srph / main.go
Created August 10, 2018 22:10
Go: PascalSnake (e.g., Hello_World) un/marshaller
package main
import (
"bytes"
"regexp"
"encoding/json"
)
type PascalSnakeMarshaller struct {
Value interface{}
@srph
srph / main.go
Last active August 10, 2018 22:07
Go: Get today time.Time instance with given hour and minutes
package main
import (
"time"
)
func nowWithGivenTime(hour int, minutes int) (time.Time, error) {
today := time.Now()
l, err := time.LoadLocation("Local")
if err != nil {
@srph
srph / main.go
Created August 10, 2018 22:04
Go: Parse 3:00 AM into military time
package main
import (
"strconv"
"strings"
)
func parseTime(t string) (int, int) {
split := strings.Split(t, " ")
time := split[0]
@srph
srph / main.go
Created August 10, 2018 22:03
Go: Extract image from css style url
package main
import (
"strings"
"regexp"
)
func getThumbnailFromStyle(style string) string {
r := regexp.MustCompile("url\\((.+)\\)")
return strings.TrimRight(strings.TrimLeft(r.FindString(style), "url("), ")")
<DataTable endpoint="api.myapp.com/users">
<DataTable.Column>
{(data) =>
<span>{data.firstName} {data.lastName}</span>
)}
</DataTable.Column>
<DataTable.Column>
{(data) =>
<a href={`/user/${data.id}`}>View</a>