Skip to content

Instantly share code, notes, and snippets.

View clux's full-sized avatar
:shipit:

Eirik A clux

:shipit:
View GitHub Profile
@clux
clux / gist:3823024
Last active October 11, 2015 07:18
Prevent JavaScript extensions/replacement of native objects because implicit dependencies and evil.js are bad things
var classes = [Object, Array, String, RegExp, Date, Number, Function];
var nonClasses = [Math, JSON, console];
classes.concat(nonClasses).forEach(function (o) {
Object.freeze(o);
});
classes.forEach(function (o) {
Object.freeze(o.prototype);
});
@clux
clux / jeesh.js
Created December 4, 2012 08:25
jeesh commonjs wrapper
var domready = require('domready')
, bean = require('bean') // events
, bonzo = require('bonzo') // DOM wrapper/manipulation
, request = require('superagent/superagent')
, qwery = require('qwery') // css selectors
, slice = Array.prototype.slice;
// Attach events API to the prototype of DOM wrapper:
var aug = {};
['on', 'off', 'one', 'add', 'fire', 'clone'].forEach(function (k) {
@clux
clux / mail-forwarder.js
Last active December 26, 2015 06:19
Forward posts to email
// Create a SMTP transport object
var nodemailer = require('nodemailer');
var transport = nodemailer.createTransport("SMTP", {
service: 'Gmail',
auth: {
user: "clux.nodemailer@gmail.com",
pass: "mailpass"
}
});
var mailStr = function (str) {
var r1 = /foo/ // 207
, r2 = /k$/ // 208
, r3 = /^[a-f]*$/ // 202
, r4 = /.(..).*\1/ // 201
, r5 = /^(?!.*(.)(.)\2\1)/ // 193
, r6 = /^(.)[^p].*\1$/ // 177
, r7 = /^(?!(xx+)\1+$)/ // 286
, r8 = /(.)(.\1){3}/ // 199
, r9 = /^.{5}[^e]?$/ // 199
, r10 = /^[378][12479]|00($|[369]|1[25])|55|2[347]/ // 589
@clux
clux / gs-vs-fifa2014.js
Created June 16, 2014 14:46
groupstage module vs fifa2014
var seeds = [
// top 8 seeds
'BRZ', // brazil
'SPA', // spain
'GER', // germany
'ARG', // argentina
'COL', // columbia
'BEL', // belgium
'URU', // uruguay
'SWI', // switzerland
FROM debian:jessie
RUN apt-get update && apt-get install -y \
build-essential \
ca-certificates \
curl \
binutils-dev \
libmad0-dev \
libgtk2.0-dev \
libasound-dev \
#!/bin/bash
set -e
# Export the main window:
XWINDOW=$(xdotool search --class Magicka)
# helpers
mousemove() {
xdotool mousemove --window $XWINDOW $1 $2
}
@clux
clux / enable-notifications.sh
Last active February 6, 2016 23:14
mass edit .travis.yml
#!/bin/bash
set -e
dir="$1"
cd "$dir"
file=".travis.yml"
# ensure we have an empty staging area before we start committing
cache=$(git diff --cached)
if [[ -n "${cache// }" ]]; then
#!/bin/bash
exit 1
# 30GB flash device on /dev/sdb
sgdisk -Z \
-n 1:0:+512M -t 1:ef00 -c 1:bootefi \
-n 2:0:+2G -t 2:8200 -c 2:swap \
-n 3:0:0 -t 3:8303 -c 3:root \
-p /dev/sdb
#!/usr/bin/env node
/**
* Small program to figure solve the challenge and response based polynomial problem:
* Adversary generates p(x) = a_0 + a_1*x + a_2*x^2 + ... + a_n*x^n
* where a_i are non-negative integers.
*
* This program will compute all the a_i given only two inputs (challenges)
* - p1 = p(1) (equal to the sum of coefficients by assumption of a_i)
* - pN = p(p(1) + 1)