Skip to content

Instantly share code, notes, and snippets.

View ex's full-sized avatar
💭
I may be slow to respond.

me ex

💭
I may be slow to respond.
View GitHub Profile
@ex
ex / gist:4010867
Created November 4, 2012 09:11
Euler 393 using bitwise operators in Killa
var USE_BC = true // Set this to false if you don't have bc library.
var one = (USE_BC)? require("bc").number(1) : 1
var IN = 1
var OUT = 2
// Insert board to state.
// If the board is already present just increase the board counter.
function insertBoard(state, board, boardCount) {
if (state[board] == null) {
@ex
ex / gist:4010400
Created November 4, 2012 05:07
Bug bitwise operators precedence correction
#define FILE_ATTRIBUTE_DIRECTORY 0x00000010
bool GetPlatformFileInfo(PlatformFile file, PlatformFileInfo* info) {
...
info->is_directory =
(file_info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
...
}
@ex
ex / gist:4010386
Created November 4, 2012 04:59
Bug bitwise operators precedence explanation
info->is_directory =
file_info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY != 0;
info->is_directory =
file_info.dwFileAttributes & (0x00000010 != 0);
info->is_directory =
file_info.dwFileAttributes & (true);
info->is_directory =
@ex
ex / gist:4010317
Created November 4, 2012 04:43
Bug bitwise operators precedence
#define FILE_ATTRIBUTE_DIRECTORY 0x00000010
bool GetPlatformFileInfo(PlatformFile file, PlatformFileInfo* info) {
...
info->is_directory =
file_info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY != 0;
...
}
@ex
ex / gist:3978133
Created October 30, 2012 03:23
looping from 1 to 1000000000
#include <stdio.h>
#include <time.h>
int main() {
int i;
unsigned int q = 0xbabecafe;
// Get start time
clock_t tm = clock();
@ex
ex / euler_393.js
Created October 29, 2012 03:50
Dynamic Pragramming solution for Euler 393 in Killa
var USE_BC = true // Set this to false if you don't have bc library.
var one = (USE_BC)? require("bc").number(1) : 1
var IN = 1
var OUT = 2
// Insert board to state.
// If the board is already present just increase the board counter.
// Board data is stored as: [boardCount, boardArray]
function insertBoard(state, boardArray, boardCount) {
For me, the purpose of life is, at least partly, to have joy.
Programmers often feel joy when they can concentrate on the creative
side of programming, So Ruby is designed to make programmers happy.
Ruby inherited the Perl philosophy of having more than one way
to do the same thing. I inherited that philosophy from Larry Wall,
who is my hero actually. I want to make Ruby users free. I want to
give them the freedom to choose. People are different. People choose
different criteria. But if there is a better way among many
alternatives, I want to encourage that way by making it comfortable.
So that's what I've tried to do.
Fxr nb, ekb dmrdxjb xf upfb pj, ie ubije direuo, ex kizb txo.
Drxlrinnbrj xfeby fbbu txo akby ekbo qiy qxyqbyerieb xy ekb qrbiepzb
jpwb xf drxlrinnpyl, Jx Rmho pj wbjplybw ex nigb drxlrinnbrj kiddo.
Rmho pykbrpebw ekb Dbru dkpuxjxdko xf kizpyl nxrb ekiy xyb aio
ex wx ekb jinb ekpyl. P pykbrpebw ekie dkpuxjxdko frxn Uirro Aiuu,
akx pj no kbrx iqemiuuo. P aiye ex nigb Rmho mjbrj frbb. P aiye ex
lpzb ekbn ekb frbbwxn ex qkxxjb. Dbxdub irb wpffbrbye. Dbxdub qkxxjb
wpffbrbye qrpebrpi. Hme pf ekbrb pj i hbeebr aio inxyl niyo
iuebryiepzbj, P aiye ex byqxmrilb ekie aio ho nigpyl pe qxnfxreihub.
Jx ekie'j akie P'zb erpbw ex wx.
// The text to decipher. It was created using a substitution cipher
var text = "Fxr nb, ekb dmrdxjb xf upfb pj, ie ubije direuo, ex kizb txo.\n"
+ "Drxlrinnbrj xfeby fbbu txo akby ekbo qiy qxyqbyerieb xy ekb qrbiepzb\n"
+ "jpwb xf drxlrinnpyl, Jx Rmho pj wbjplybw ex nigb drxlrinnbrj kiddo.\n"
+ "Rmho pykbrpebw ekb Dbru dkpuxjxdko xf kizpyl nxrb ekiy xyb aio\n"
+ "ex wx ekb jinb ekpyl. P pykbrpebw ekie dkpuxjxdko frxn Uirro Aiuu,\n"
+ "akx pj no kbrx iqemiuuo. P aiye ex nigb Rmho mjbrj frbb. P aiye ex\n"
+ "lpzb ekbn ekb frbbwxn ex qkxxjb. Dbxdub irb wpffbrbye. Dbxdub qkxxjb\n"
+ "wpffbrbye qrpebrpi. Hme pf ekbrb pj i hbeebr aio inxyl niyo\n"
+ "iuebryiepzbj, P aiye ex byqxmrilb ekie aio ho nigpyl pe qxnfxreihub.\n"
@ex
ex / gist:3838263
Created October 5, 2012 05:32
Decrypt a message
-- The text to decipher. It was created using a substitution cipher
local text = [[
Fxr nb, ekb dmrdxjb xf upfb pj, ie ubije direuo, ex kizb txo.
Drxlrinnbrj xfeby fbbu txo akby ekbo qiy qxyqbyerieb xy ekb qrbiepzb
jpwb xf drxlrinnpyl, Jx Rmho pj wbjplybw ex nigb drxlrinnbrj kiddo.
Rmho pykbrpebw ekb Dbru dkpuxjxdko xf kizpyl nxrb ekiy xyb aio
ex wx ekb jinb ekpyl. P pykbrpebw ekie dkpuxjxdko frxn Uirro Aiuu,
akx pj no kbrx iqemiuuo. P aiye ex nigb Rmho mjbrj frbb. P aiye ex
lpzb ekbn ekb frbbwxn ex qkxxjb. Dbxdub irb wpffbrbye. Dbxdub qkxxjb