Skip to content

Instantly share code, notes, and snippets.

@faryne
faryne / sample.py
Created May 9, 2023 14:54
sample.py
import requests
from flask import Flask, render_template
app = Flask(__name__)
API_KEY = ""
ENDPOINT = "https://newsapi.org/v2/top-headlines"
@app.route("/")
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@faryne
faryne / yq.sh
Created February 16, 2020 10:59
# :~ faryne$ cat sample.yaml | yq r - a; echo
1
#:~ faryne$ yq w -i sample.yaml 'c' "aaaA"
@faryne
faryne / jo.sh
Created February 16, 2020 10:57
# :~ faryne$ jo -p a=1 b=2
{
"a": 1,
"b": 2
}
# :~ faryne$ jo -p a=$(jo b=1 c=2)
{
@faryne
faryne / jq.sh
Created February 16, 2020 10:55
# :~ faryne$ echo '{}' | jq
{}
#:~ faryne$ echo '{"a":1}' | jq '.a'
1
#:~ faryne$ echo '{"a":1, "b": [1, 2, 3]}' | jq '.b[2]'
3
@faryne
faryne / taipower.json
Last active March 18, 2018 04:39
台電公關費用
/**
* term:期別
* num:案件數目
* total:總金額
*/
[
{
"term": "2003-01",
"num": "166",
"total": "3760000"
@faryne
faryne / Program.cs
Last active February 24, 2017 10:23
C# Regexp Retrieved
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using System.Diagnostics;
namespace ConsoleApplication1
@faryne
faryne / chinese.php
Created December 6, 2016 10:48
中文正簡體轉換
<?php
// 正體轉簡體
function big5_gb2312($in)
{
return iconv('GB2312', 'UTF-8', iconv('BIG5', 'GB2312', iconv('UTF-8', 'BIG5', $in)));
}
// r簡體轉正體
function gb2312_big5($in)
@faryne
faryne / sample.html
Created August 22, 2016 03:15
URI.js sample
<!doctype html>
<html>
<head>
<title>xxx</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/URI.js/1.18.1/URI.min.js"></script>
</head>
<body>
<script type="text/javascript">
$uri = URI("").addSearch("a[]", 1)
.addSearch("b[]", 1).toString();
{
"responses": [
{
"labelAnnotations": [
{
"mid": "/m/03q69",
"description": "hair",
"score": 0.96216953
},
{