Skip to content

Instantly share code, notes, and snippets.

anonymous
anonymous / gist:1101017
Created July 23, 2011 04:28
-- [Lua] The classic card game, War (v.2.1) --
TheDeck = {}
carddeck = {}
player = { hand={} }
opponent = { hand={} }
arena = { hand={} }
-- Standard seed based on time, called once
math.randomseed(os.time())
@TheBuzzSaw
TheBuzzSaw / palindrome.cpp
Created December 12, 2011 05:18
MyPalindrome
#include <iostream>
using namespace std;
bool isPalindrome(const char* inText)
{
if (!inText || !*inText)
return false; // Empty strings fail. OK?
const char* a = inText - 1;
const char* b = inText;
@maxrice
maxrice / us-state-names-abbrevs.php
Created May 23, 2012 18:32
US State Names & Abbreviations as PHP Arrays
<?php
/* From https://www.usps.com/send/official-abbreviations.htm */
$us_state_abbrevs_names = array(
'AL'=>'ALABAMA',
'AK'=>'ALASKA',
'AS'=>'AMERICAN SAMOA',
'AZ'=>'ARIZONA',
'AR'=>'ARKANSAS',
@jboner
jboner / latency.txt
Last active July 17, 2024 03:12
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@MohamedAlaa
MohamedAlaa / tmux-cheatsheet.markdown
Last active July 16, 2024 16:59
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@roxlu
roxlu / SSLBuffer.cpp
Created November 2, 2012 11:38
libuv + openssl + SSLBuffer
#include "SSLBuffer.h"
SSLBuffer::SSLBuffer()
:ssl(NULL)
,read_bio(NULL)
,write_bio(NULL)
,write_to_socket_callback(NULL)
,write_to_socket_callback_data(NULL)
,read_decrypted_callback(NULL)
,read_decrypted_callback_data(NULL)
@ssylvan
ssylvan / gist:5654932
Last active December 17, 2015 18:39
Stupid C++ lib for trying to avoid null pointers
// Class for non-nullable pointers
template<class T>
class ptr
{
private:
T* m_ptr;
ptr(nullptr_t); // avoids init with nullptr
ptr(int); // avoids init with 0 or NULL
public:
explicit ptr(T* ptr) throw() : m_ptr(ptr) { assert(ptr != nullptr); };
@aras-p
aras-p / preprocessor_fun.h
Last active July 16, 2024 02:50
Things to commit just before leaving your job
// Just before switching jobs:
// Add one of these.
// Preferably into the same commit where you do a large merge.
//
// This started as a tweet with a joke of "C++ pro-tip: #define private public",
// and then it quickly escalated into more and more evil suggestions.
// I've tried to capture interesting suggestions here.
//
// Contributors: @r2d2rigo, @joeldevahl, @msinilo, @_Humus_,
// @YuriyODonnell, @rygorous, @cmuratori, @mike_acton, @grumpygiant,
@KoaxialKable
KoaxialKable / Cardz.cpp
Last active December 23, 2015 06:59
Basic card shuffler featuring the random library (v2.20)
#include <iostream>
#include <random>
#include <algorithm>
#include <vector>
using namespace std;
enum suits {SPADES, DIAMONDS, CLUBS, HEARTS};
enum modes {ACES_LOW, ACES_HIGH};