Skip to content

Instantly share code, notes, and snippets.

View jsanders's full-sized avatar

James Sanders jsanders

View GitHub Profile
@jsanders
jsanders / gulpfile.babel.js
Created October 27, 2015 02:15
Gulp + ES 2015 / Babel + PostCSS + Lost + BrowserSync
import gulp from 'gulp';
import postcss from 'gulp-postcss';
import sourcemaps from 'gulp-sourcemaps';
import cssnano from 'cssnano';
import autoprefixer from 'autoprefixer';
import lost from 'lost';
import {create as bsCreate} from 'browser-sync';
const browserSync = bsCreate();
const dirs = {
@jsanders
jsanders / github-trello.md
Created April 10, 2015 22:27
github vs. trello

Github

Pros

  • Pull requests are the thing for getting dev done, seeing what others have done, and discussing it. I love pull requests.

Cons

  • Developer-centric workflow that doesn't provide much value to the rest of the business, because it has no interest in that at all.
  • Not particularly flexible organization of anything, milestones are a bit clunky to use, so it's mostly just labels.

Neutral

  • Individual issues are a pretty good place for discussion, but not a killer feature at all like PRs.
@jsanders
jsanders / prime_sieve.rs
Last active May 19, 2022 16:41
Rust Sieve of Eratosthenes
// Find all prime numbers less than n
fn small_primes(bound: uint) -> ~[uint] {
// num is considered prime as long as primes[num] is true
// Start with all evens besides 2 filtered out
let mut primes = std::vec::from_fn(bound+1, |num| num == 2 || num & 1 != 0);
// Start at 3 and step by 2 because we've already filtered multiples of 2
for num in count(3u, 2).filter(|&num| primes[num]).take_while(|&num| num * num <= bound) {
// Mark prime num's multiples non-prime
// We can start at num^2 because smaller non-primes have already been eliminated
@jsanders
jsanders / aes_ctr_cbc.rb
Last active October 8, 2021 10:45
Implementation of AES with counter (CTR) and cipher-block-chaining (CBC) modes. Based on spec at http://csrc.nist.gov/publications/fips/fips197/fips-197.pdf. ** Disclaimer: For educational purposes only. Obviously, nobody should ever use a hacky un-vetted non-standard (not to mention, non-optimized) implementation of crypto like this **
require File.expand_path('../../utilities', __FILE__)
require 'openssl'
# Set to true to see debug output
DEBUG = false
def debug_puts(s=nil); puts(s) if DEBUG; end
def debug_print(s=nil); print(s) if DEBUG; end
# Encrypt data using given `mode`, `key_b`, `iv_b` and `data_b`, all as byte arrays
# Only uses padding in CBC mode
@jsanders
jsanders / PointDist.java
Last active March 28, 2019 04:11
Java data class / record
public class PointDist {
public static void main(String[] args) {
var point = new Point(3, 4);
System.out.println(String.format("x: %d - y: %d - distance: %f", point.x(), point.y(), point.dist()));
}
static record Point(int x, int y) {
double dist() {
return Math.sqrt(x * x + y * y);
}
@jsanders
jsanders / generate_big_primes.rs
Last active October 30, 2018 22:53
Generate big primes in Rust. This works pretty fast now thanks to https://github.com/jsanders/rust-bignum and https://github.com/jsanders/rust-gmp! I'm still implementing my own mod_exp, but the performance is quite tolerable nonetheless.
extern crate bignum;
extern crate time;
use std::rand::task_rng;
use std::iter::{count,range_step_inclusive};
use std::num::{Zero,One};
use bignum::{BigUint,RandBigInt,ToBigUint};
// Find all prime numbers less than n
fn small_primes(bound: uint) -> ~[uint] {
@jsanders
jsanders / explain_analyze.rb
Created December 18, 2013 22:56
Run EXPLAIN ANALYZE on all select queries and log the results. Definitely don't use this if performance matters...
if Rails.env.development?
require 'active_record/connection_adapters/postgresql_adapter'
class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
def __explain_analyze(sql, command, *args)
meth = "#{command}_without_explain_analyze".to_sym
if /\A\s*SELECT/i.match(sql)
newsql = "EXPLAIN ANALYZE #{sql}"
plan = send(meth, newsql, *args).map { |row| row['QUERY PLAN'] }.join("\n")
Rails.logger.debug("\e[1m\e[31mQUERY PLAN FOR: #{sql.strip};\n#{plan}\e[0m")
@jsanders
jsanders / LICENSE
Last active August 17, 2018 23:38
32-bit x86 SHA1 implementation.
MIT License
Copyright (c) 2017 Martin Buberl
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@jsanders
jsanders / README.md
Created June 21, 2012 21:10 — forked from thinkerbot/README.md
Find and remove old git branches

Description

Find and delete old git branches that are no longer needed.

Usage

Clone the repo and add to your path (just for ease of use):

@jsanders
jsanders / stripe-ctf-1.0.md
Last active May 26, 2017 16:22
Work-through of the Stripe CTF 1.0 focused more on system-level than web-level security.

Stripe CTF 1.0

Level 1

Ok, start by ssh-ing to level01@ec2-23-22-123-94.compute-1.amazonaws.com with password w5kjAsSKEjCT. Our goal is to read the file .password from the level02 user's home directory: /home/level02. Let's look for low-hanging fruit - maybe we can just read the file directly: