Skip to content

Instantly share code, notes, and snippets.

# -*- coding: utf-8 -*-
def cross_product(p1, p2, p3):
return ((p1[0] - p3[0]) * (p2[1] - p3[1])) - ((p2[0] - p3[0]) * (p1[1] - p3[1]))
def point_in_triangle(s, p1, p2, p3):
b1 = cross_product(s, p1, p2) < 0
b2 = cross_product(s, p2, p3) < 0
# -*- coding: utf-8 -*-
class QuaternionNumber:
def __init__(self, r, i, j, k):
self.r = r
self.i = i
self.j = j
self.k = k
# -*- coding: utf-8 -*-
import pycurl
from BeautifulSoup import BeautifulSoup
class BruteFrocePinterestCrawler:
def __init__(self):
self.content = ''
self.url = ''
@rightson
rightson / reference-member-is-dangerous.cpp
Last active October 22, 2015 06:30
Take care of your member reference variables
#include <iostream>
#include <string>
class Person {
public:
Person(std::string& reference): _reference(reference) {}
std::string name() { return _reference; }
private:
std::string &_reference;
};
@rightson
rightson / ping-overview.c
Created December 1, 2015 13:26
An overview of ping
// ping.c
int main()
{
// ...
main_loop(icmp_sock, packet, packlen);
}
// ping_common.c
void main_loop(int icmp_sock, __u8 *packet, int packlen)
{
@rightson
rightson / set-screen.sh
Created March 3, 2016 06:12
Add/set screen Full HD resolution on Ubuntu running in VMWare
#!/bin/sh
xrandr --newmode "1920x1080" 173.00 1920 2048 2248 2576 1080 1083 1088 1120 -hsync +vsync
xrandr --addmode Virtual1 1920x1080
xrandr --output Virtual1 --mode 1920x1080
class WebBrowser {
public:
// ...
void clearCache();
void clearHistory();
void removeCookies();
// ...
};
class WebBrowser {
#include <stdio.h>
typedef unsigned int u32;
typedef unsigned long u64;
static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
{
union {
u64 v64;
u32 v32[2];
} d = { dividend };
@rightson
rightson / create-jos-env.sh
Last active May 20, 2016 22:33
A script for creating development environment for MIT JOS
export PFX=$HOME/jos-env
#export PATH=$PFX/bin:$PATH
#export LD_LIBRARY_PATH=$PFX/lib:$LD_LIBRARY_PATH # On Linux, use LD_LIBRARY_PATH
#export DYLD_LIBRARY_PATH=$PFX/lib:$DYLD_LIBRARY_PATH # On Mac OS X, use DYLD_LIBRARY_PATH
export GPM=gmp-5.0.2
export MPFR=mpfr-3.1.2
export MPC=mpc-0.9
export BINUTILS=binutils-2.21.1
export GCCCORE=gcc-core-4.6.3
@rightson
rightson / virtualbox-patch-for-installing-osx.sh
Last active May 20, 2016 21:44
virtualbox patch for installing OS X
VBoxManage modifyvm "OS X 10.11" --cpuidset 00000001 000306a9 04100800 7fbae3ff bfebfbff
VBoxManage setextradata "OS X 10.11" "VBoxInternal/Devices/efi/0/Config/DmiSystemProduct" "MacBookPro11,3"
VBoxManage setextradata "OS X 10.11" "VBoxInternal/Devices/efi/0/Config/DmiSystemVersion" "1.0"
VBoxManage setextradata "OS X 10.11" "VBoxInternal/Devices/efi/0/Config/DmiBoardProduct" "Mac-2BD1B31983FE1663"
VBoxManage setextradata "OS X 10.11" "VBoxInternal/Devices/smc/0/Config/DeviceKey" "ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc"
VBoxManage setextradata "OS X 10.11" "VBoxInternal/Devices/smc/0/Config/GetKeyFromRealSMC" 1