Skip to content

Instantly share code, notes, and snippets.

@pankpan
pankpan / adsense-v2.php
Last active Oct 15, 2021
PHP Adsnese API v2
View adsense-v2.php
<?php
require __DIR__ . '/vendor/autoload.php';
function getClient()
{
$client = new Google_Client();
$client->setApplicationName('Adsense PHP Client');
$client->addScope('https://www.googleapis.com/auth/adsense.readonly');
$client->setAccessType('offline');
$client->setApprovalPrompt('force');
@pankpan
pankpan / volley_post_data_with_header.kt
Last active Aug 29, 2021
Android Kotlin Volley POST data with header
View volley_post_data_with_header.kt
// implementation 'com.android.volley:volley:1.2.1'
import com.android.volley.Response
import com.android.volley.toolbox.StringRequest
import com.android.volley.toolbox.Volley
var apiUrl="https://your-api-url.com/"
val request: StringRequest = object : StringRequest(
Method.POST, apiUrl,
Response.Listener { response ->
if (response != null) {
@pankpan
pankpan / LINE_SCALE.bat
Created Jul 27, 2021
LINE loader with QT_SCALE_FACTOR variable
View LINE_SCALE.bat
set QT_SCALE_FACTOR=1.25
start %LOCALAPPDATA%\LINE\bin\LineLauncher.exe
@pankpan
pankpan / get-tw-ips.sh
Created Jul 10, 2021
Get Taiwan IPv4 Addresses from APNIC
View get-tw-ips.sh
#!/bin/sh
# netmask from http://trap.mtview.ca.us/~talby/netmask_2.4.tar.gz
netmask `curl -s http://ftp.apnic.net/stats/apnic/delegated-apnic-latest | awk -F'|' '/TW\|ipv4/ {print $4":+"($5-1)}'`
@pankpan
pankpan / kick-out-user-by-ip.sh
Last active Jul 5, 2021
Force kick out user by IP address for Linux
View kick-out-user-by-ip.sh
#!/bin/sh
if [ -z $1 ] ; then
echo "`basename $0` {ip}"
else
TEMP=/tmp/psauxw.tmp
ps auxw > $TEMP
for T in `w | grep -w $1 | awk '{print $2}'`
do
echo Logout $T
grep -w $T $TEMP | awk '{print $2}' | xargs kill -9
@pankpan
pankpan / linux-auto-login.sh
Created Jul 3, 2021
enable Linux console auto login script
View linux-auto-login.sh
#!/bin/sh
sed -i 's/ExecStart.*/ExecStart=-\/sbin\/agetty -a root %I \$TERM/' /usr/lib/systemd/system/getty@.service
@pankpan
pankpan / alexa-top-50-sites-dns-bench.sh
Created Jun 25, 2021
Measure DNS speed by query Alexa top 50 sites NS and A record
View alexa-top-50-sites-dns-bench.sh
#!/bin/bash
TEMP=/tmp/alexa.html
if [ -z $1 ] ; then
echo "`basename $0` {dns}"
else
DNS=$1
[ -f $TEMP ] || curl -s https://www.alexa.com/topsites > $TEMP
T1=`date +%s.%N`
for HOST in `awk -F[\"\/] '/href=..siteinfo\// {print $4}' $TEMP`
@pankpan
pankpan / skype-get-token.sh
Last active Jun 1, 2021
Skype Bot API get token BASH script
View skype-get-token.sh
#!/bin/bash
# Get skype bot token to send message, fill your CLIENT_ID and CLIENT_SECRET
CLIENT_ID=
CLIENT_SECRET=
TOKEN=`curl -sd "client_id=$CLIENT_ID&client_secret=$CLIENT_SECRET&grant_type=client_credentials&scope=https://api.botframework.com/.default" https://login.microsoftonline.com/common/oauth2/v2.0/token | jq -r .request_token`
echo $TOKEN
@pankpan
pankpan / skype-send-message.sh
Last active Jun 1, 2021
Skype Bot API send message BASH script
View skype-send-message.sh
#!/bin/bash
# To get TOKEN, ref this gist https://gist.github.com/pankpan/ad68f50cd44c1dae9203d29964d579e5
# TO is personal uid or conversation id
TOKEN=
TO=
curl -sd '{"type":"message","text":"Test 20210601"}' -H "Authorization: Bearer $TOKEN" https://smba.trafficmanager.net/apis/v3/conversations/$TO/activities
@pankpan
pankpan / iptables.sh
Created May 3, 2021
iptables security policy for Cloudflare
View iptables.sh
#!/bin/bash
iptables -F
iptables -P INPUT DROP
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -i lo -j ACCEPT
for IP in `curl -s https://www.cloudflare.com/ips-v4`
do
iptables -A INPUT -s $IP -p tcp -m multiport --dport 80,443 -j ACCEPT
done