Skip to content

Instantly share code, notes, and snippets.

@trevershick
trevershick / CMakeLists.txt
Last active November 21, 2023 06:54
Simple client and server using libuv and unix domain sockets...
set(CMAKE_BUILD_TYPE Debug)
cmake_minimum_required(VERSION 2.8.12)
project(libuv1)
add_definitions("-std=c++11")
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
add_executable(server server.cpp)
// thanks https://gist.github.com/thomseddon/3511330
function formatBytes(bytes, precision) {
if (isNaN(parseFloat(bytes)) || !isFinite(bytes)) return '-';
if (typeof precision === 'undefined') precision = 1;
var units = ['bytes', 'kB', 'MB', 'GB', 'TB', 'PB'],
number = Math.floor(Math.log(bytes) / Math.log(1024));
return (bytes / Math.pow(1024, Math.floor(number))).toFixed(precision) + ' ' + units[number];
}
@trevershick
trevershick / adverbs.txt
Last active January 17, 2021 21:47
Word List
aback
abaft
abaxially
abeam
abed
abjectly
ably
abnormally
aboard
abominably
@trevershick
trevershick / test.cpp
Last active February 7, 2019 03:40
test.cpp
#include <cstring>
#include <functional>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
class MyBuf : public std::streambuf {
public:
MyBuf(int maxLength, std::function<void(const char *, int)> callbackFn);
@trevershick
trevershick / StatementExecutingDataSource.java
Created July 2, 2011 20:35
DataSource wrapper that executes statements on getConnection to fix an issue with Activiti not supporting fully qualified table names.
package com.railinc.spring.jdbc;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import javax.sql.DataSource;
@trevershick
trevershick / svn_short_log
Last active September 12, 2018 22:13 — forked from plexus/svn_short_log
svn log, one line per commit
#!/usr/bin/awk -f
# Convert the "svn log" output into a one liner format, which is easier to grep
# or use in scripts. Pipe "svn log" into this script
# When we get a line that starts with a revision number, put the data in variables
/^r[0-9]+/ {
rev=$1
user=$3
date=$5
@trevershick
trevershick / WatchMe.java
Created October 16, 2013 13:56
Sample code showing how even after a Guava transform, the underlying collection may still be altered.
import static com.google.common.collect.Collections2.transform;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import com.google.common.base.Function;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
@trevershick
trevershick / MakeYojimboNoteFromFlaggedEmail.applescript
Last active December 22, 2015 01:19
Applescript to take flagged e-mail in Apple Mail and create Yojimbo items tagged with 'todo'. I sourced quite a bit of this from multiple places. I apologize for not keeping the references...
#! /usr/bin/osascript
set _count to 0
if not (application "Mail" is running and application "Yojimbo" is running) then
return
end if
tell application "Mail"
repeat with _account in accounts
try
set _inbox to _account's mailbox "Inbox"
@trevershick
trevershick / gist:4648928
Last active December 11, 2015 19:29
Simple Python List Comprehension Example
>>> [ (e.id, e.title) for e in Entry.objects.all() if e.status == Entry.STATUS_LIVE ]
[(5, u'Test Entry 2'), (3, u'Test Title 0')]
var bucket = "a-bucket";
var filename = "logs/abc";
var event = {
"Records": [
{
"s3": {
"object": {