This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
while sleep 60; do if [[ $(curl -s "https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v2" -d'{"query": "{tokenDayDatas(first: 1, orderBy: date, orderDirection: desc, where: { token: \"0xf7413489c474ca4399eee604716c72879eea3615\"}) { priceUSD } }"}' | jq -r '.data.tokenDayDatas[0].priceUSD' | tee /dev/tty | sed 's/$/ <= 1.2/' | bc) -eq "1" ]]; then say "buy APYS now"; fi; done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
IF(package_line = 'main', 'main', 'non_main') AS is_main, COUNT(1) AS count, LEFT(GROUP_CONCAT(UNIQUE(package_line)), 100) AS package_names | |
FROM ( | |
SELECT | |
REGEXP_EXTRACT(content, r'package\s+([^\s]+)\s') AS package_line | |
FROM | |
( | |
SELECT | |
id, | |
content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Parallel processing with ordered output in Go | |
(you can use this pattern by importing https://github.com/MarianoGappa/parseq) | |
This example implementation is useful when the following 3 conditions are true: | |
1) the rate of input is higher than the rate of output on the system (i.e. it queues up) | |
2) the processing of input can be parallelised, and overall throughput increases by doing so | |
3) the order of output of the system needs to respect order of input | |
- if 1 is false, KISS! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This snippet is an example of backpressure implementation in Go. | |
It doesn't run in Go Playground, because it starts an HTTP Server. | |
The example starts an HTTP server and sends multiple requests to it. The server starts denying | |
requests by replying an "X" (i.e. a 502) when its buffered channel reaches capacity. | |
This is not the same as rate-limiting; you might be interested in https://github.com/juju/ratelimit | |
or https://godoc.org/golang.org/x/time/rate. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The following one-liner calculates the average weekly rent price for a carpark on Auckland City Centre (New Zealand) | |
curl -s 'http://www.trademe.co.nz/Browse/CategoryAttributeSearchResults.aspx?search=1&cid=5748&sidebar=1&132=FLAT&selected135=7&134=1&135=7&136=89&216=0&216=0&217=0&217=0&153=&29=Car+park&59=0&59=0&178=0&178=0' | grep 'per week</' | sed 's/.*\$\(.*\) per week.*/\1/g' | awk '{ sum += $1; n++ } END { if (n > 0) print "$" sum / n " based on " n " advertised items."; }' | |
# Example output (2016-08-20): $77.7917 based on 24 advertised items. | |
# | |
# | |
# Note that this script doesn't consider pagination, but I tried a whole-country search | |
# of carparks and there were only 78 results, and Trademe didn't paginate, so I think | |
# it's not necessary. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# (requires jq) | |
# USER=your_github_username | |
# ACCESS_TOKEN=your_github_access_token | |
# ORGANIZATION=your_organization | |
curl -u $USER:$ACCESS_TOKEN -s "https://api.github.com/orgs/$ORGANIZATION/members?per_page=100" | \ | |
jq -r '.[] | "\(.repos_url)?per_page=100"' | \ | |
while read line; do echo -n "$(curl -s $line | jq --raw-output '.[] | {a:.stargazers_count,b:.full_name} | .[] ' | paste -s -d ' \n' - )"; done | \ | |
sort -rn | grep -v '^0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USER=my_github_username | |
ACCESS_TOKEN=my_github_access_token | |
curl -u $USER:$ACCESS_TOKEN -s "https://api.github.com/user/repos" | jq -r 'map(.languages_url) | .[]' | xargs curl -s -u $USER:$ACCESS_TOKEN | jq -r '. as $in| keys[] | [.+ " "]+[$in[.] | tostring] | add' | awk '{arr[$1]+=$2} END {for (i in arr) {print i,arr[i]}}' | awk '{print $2, $1}' | sort -nr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Echoes the build.sbt project version to STDOUT. | |
# | |
# NOTES: | |
# - place this script on the root of your project | |
# - this script will then work on the first build.sbt found anywhere on your project | |
# - this script assumes your project version setting is a literal e.g.: `version := "0.1-SNAPSHOT"` | |
# Exit on unset variables or if any of the following commands returns non-zero |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function big_rand_decimal($integerDigits, $decimalDigits, $decimalSeparator = ".") { | |
if(!is_numeric($integerDigits) || $integerDigits <= 0) | |
$integerDigits = 0; | |
else if(!is_integer($integerDigits)) | |
$integerDigits = (int)ceil($integerDigits); | |
if(!is_numeric($decimalDigits) || $decimalDigits <= 0) | |
$decimalDigits = 0; | |
else if(!is_integer($decimalDigits)) | |
$decimalDigits = (int)ceil($decimalDigits); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function big_rand_integer($digits) { | |
if(!is_numeric($digits) || $digits <= 0) | |
return '0'; | |
if(!is_integer($digits)) | |
$digits = (int)ceil($digits); | |
$multiplier = (int)ceil($digits / 9.0); | |
$function = function() { |
NewerOlder