Skip to content

Instantly share code, notes, and snippets.

#include "tweetnacl.h"
#define FOR(i,n) for (i = 0;i < n;++i)
#define sv static void
typedef unsigned char u8;
typedef unsigned int u32;
typedef unsigned long long u64;
typedef long long i64;
typedef i64 gf[16];
@lyoshenka
lyoshenka / calvinball.js
Last active December 23, 2015 03:49
Count the total length of all the player names on my ESPN fantasy football team
jQuery(function(){
var regex = new RegExp("[^A-Za-z0-9]+",'g'),
playerNameSelector = 'td.playertablePlayerName a:first-child',
teamAId = '#playertable_0',
teamBId = jQuery('#playertable_6').length ? '#playertable_6' : '#playertable_1',
teamA = jQuery(teamAId)
.closest('div')
.find(playerNameSelector)
.filter(function(){ return jQuery(this).closest('.hideableGroup').length === 0 && jQuery(this).text().length > 0; }),
teamAPlayers = teamA.length,
@lyoshenka
lyoshenka / aws_s3_single_bucket_policy.json
Created September 18, 2013 17:01
AWS S3 User Policy that limits access to just one bucket
{
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:ListBucket",
"s3:GetBucketLocation",
"s3:ListBucketMultipartUploads"
],
"Resource": "arn:aws:s3:::BUCKETNAME",

How not to rm yourself

Copied from https://github.com/sindresorhus/guides/blob/master/how-not-to-rm-yourself.md

The rm command is inherently dangerous and should not be used directly. It can at worst let you accidentally remove everything. Here's how you can protect you from yourself.

Use trash

The trash command-line tool will move stuff to the trash instead of permanently deleting it. You should not alias rm to trash as it will break external scripts relaying on the behavior of rm. Instead use it directly: trash image.jpg.

@lyoshenka
lyoshenka / localhost_dns.md
Last active December 25, 2015 05:39
Localhost DNS. All traffic for *.localhost will be sent to 127.0.0.1
  • Install dnsmasq
  • Add these lines to /etc/dnsmasq.conf
    • listen-address=127.0.0.1
    • address=/localhost/127.0.0.1
  • Add to /etc/dhcp3/dhclient.conf
    • prepend domain-name-servers 127.0.0.1;
  • sudo service dnsmasq restart
@lyoshenka
lyoshenka / togglToHipchat.php
Last active December 25, 2015 12:59
Run this in cron every 5 minutes. Sends a message to HipChat when you start and stop your Toggl timer.
#!/usr/bin/env php
<?php
const
TOGGL_API_KEY = '',
HIPCHAT_API_KEY = '',
HIPCHAT_ROOM_ID = '',
HIPCHAT_FROM = 'Toggl',
HIPCHAT_COLOR = 'yellow', // One of "yellow", "red", "green", "purple", "gray", or "random".
START_MSG = 'NAME is doing work, yo',
@lyoshenka
lyoshenka / print_table.php
Last active December 26, 2015 16:38
Print data as a table
<?php
function echoBanner($text)
{
$len = strlen($text);
$line = str_pad('', $len + 4, '#');
echo "\n\n" . $line . "\n# " . $text . " #\n" . $line . "\n\n\n";
}
function printTable($data, $columnNames = [])
{
@lyoshenka
lyoshenka / index.html
Last active December 26, 2015 16:39
Who threw to who during AMP's 2013 season (from Philly Invite through Nationals)
<html><head>
<link rel="stylesheet" type="text/css" href="//ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/css/jquery.dataTables.css">
<style type="text/css">
.dataTables_filter { float: left; }
</style>
</head><body>
<h1>Throws</h1><table><thead><tr><td></td><td>Alex</td><td>Ben</td><td>BenJ</td><td>Bill</td><td>Birdo</td><td>Bulb</td><td>Butter</td><td>Devlin</td><td>Diana</td><td>Dre</td><td>Furf</td><td>Grin</td><td>Jessie</td><td>Jill</td><td>Katie</td><td>Kelly</td><td>Maddie</td><td>Mel</td><td>Miggs</td><td>Panna</td><td>Papa</td><td>Purifico</td><td>Raha</td><td>Satell</td><td>Stacy</td><td>Wheez</td><td>Zumba</td></tr></thead><tbody><tr><th>Alex</th><td>-</td><td>8</td><td>7</td><td>1</td><td>25</td><td>12</td><td>2</td><td>12</td><td>2</td><td>1</td><td>2</td><td>5</td><td>2</td><td>0</td><td>19</td><td>2</td><td>1</td><td>31</td><td>73</td><td>8</td><td>4</td><td>1</td><td>24</td><td>7</td><td>19</td><td>7</td><td>4</td></tr><tr><th>Ben</th><td>11</td><td>-</td><td>4</td><td>2</td><td>1
@lyoshenka
lyoshenka / .gitignore
Created November 20, 2013 23:06 — forked from monde/.gitignore
Gemfile.lock
@lyoshenka
lyoshenka / chromeSearchFix.js
Created November 22, 2013 22:25
Chrome Extension to stop Chrome from trying to search when going to a URL with .localhost domain.
chrome.tabs.onUpdated.addListener(function(tabId, e) {
if (e.url && e.url.match('google.com/search') && e.url.match('localhost')) {
var q = e.url.match(/q=[^&]+&/i);
if (q) {
var localUrl = decodeURIComponent(q[0].substring(2,q[0].length-1));
chrome.tabs.update(tabId, {url: 'http://' + localUrl });
}
}
});