Skip to content

Instantly share code, notes, and snippets.

View bradbaris's full-sized avatar

Brad Baris bradbaris

View GitHub Profile
@bradbaris
bradbaris / spiralarray.js
Last active August 16, 2018 19:35
Spiral Array
function createSpiral(dimension) {
console.time();
// square array generator
const matrix = (dimension) => {
return new Array(dimension).fill(0).map((obj, idx) => {
return obj[idx] = new Array(dimension).fill(0);
});
}
@bradbaris
bradbaris / solar.svg
Last active June 26, 2017 22:52
Recently found an old backup of files from 2004, during my freshman year in college. I had worked on an SVG animation in class, and I remember my professor saying that SVGs were going to be a big thing. He was right.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bradbaris
bradbaris / slackspotify.sh
Last active January 12, 2018 22:01
Sets the current song playing on Spotify to your Slack status
#!/bin/bash
# https://api.slack.com/custom-integrations/legacy-tokens
APIKEY="<INSERT_LEGACY_API_TOKEN>"
while true
do
SONG=$(osascript -e 'tell application "Spotify" to name of current track as string')
ARTIST=$(osascript -e 'tell application "Spotify" to artist of current track as string')
URLSONG=$(echo "$SONG" | perl -MURI::Escape -ne 'chomp;print uri_escape($_),"\n"')
URLARTIST=$(echo "$ARTIST" | perl -MURI::Escape -ne 'chomp;print uri_escape($_),"\n"')
curl -X POST -s -d "payload=$json" "https://slack.com/api/users.profile.set?token="$APIKEY"&profile=%7B%22status_text%22%3A%22"$URLARTIST"%20%2D%20"$URLSONG"%22%2C%22status_emoji%22%3A%22%3Aheadphones%3A%22%7D" > /dev/null
const fs = require("fs");
const Uint64BE = require("int64-buffer").Uint64BE;
let offset = 0;
let arr;
fs.readFile("txnlog.dat", function(err, data) {
arr = Buffer.from(data);
// Header
const header = arr.slice(offset,offset+=4).toString('utf8');
const version = arr.slice(offset,offset+=1).toString('hex');
const fs = require("fs");
const eol = require("os").EOL;
const plans_data = convertCSVtoJSON(fs.readFileSync("plans.csv", "utf8"));
const zips_data = convertCSVtoJSON(fs.readFileSync("zips.csv", "utf8"));
solve("slcsp.csv");
// CSV to JSON parser
function convertCSVtoJSON(csv) {
let result = [];
@bradbaris
bradbaris / TacoSpolsky.js
Last active March 12, 2019 22:01
Trello TacoSpolsky Exploit Challenge (Verbose Comment Draft)
//
// PROBLEM
//
// Taco (our mascot) is pretty terrible at writing code, but his recommendation still // carries a lot of weight.
// He's put together a page that we can use to get his latest # recommendations: https://taco-spolsky.github.io/
//
// To complete your application, please include a link to Taco's recommendation page
// in the field below (hopefully a link that leads to a page where you are the one
// being recommended!)
//
@bradbaris
bradbaris / FogCreek Algo CharSort.js
Last active January 18, 2017 15:41
Stumbled across this algo problem on one of Fog Creek Software's now-defunct job postings. Thought I'd try it out for practice. Fairly simple problem.
// PROBLEM:
//
// Sort the characters in the following string:
//
// abcdefghijklmnopqrstuvwxyz_
//
// by the number of times the character appears in the following text (descending):
//
// Note: the text scrolls.
@bradbaris
bradbaris / FogCreek Algo Brute-Force.js
Last active January 18, 2017 15:42
Stumbled across this algo problem on one of Fog Creek Software's ancient now-defunct job postings. Thought I'd try it out for practice. Turns out this problem could be solved by simply reversing the hashing algo (my first hunch), but here's a brute-force solution.
// PROBLEM:
//
// Find a 9 letter string of characters that contains only letters from
//
// acdegilmnoprstuw
//
// such that the hash(the_string) is
//
// 945924806726376
/**
* @fileoverview Utility functions related to the user agent.
*/
function isIOS() {
return /iPhone|iPad|iPod/i.test(navigator.userAgent);
}
@bradbaris
bradbaris / image-to-ansi.py
Last active May 3, 2016 10:18 — forked from klange/image-to-ansi.py
Convert images to ANSI escape sequences
#! /usr/bin/env python
""" Convert an image (argv[1]) to an ANSI text string (xterm-256color)
Original readme from colortrans.py follows:
Nice long listing of all 256 colors and their codes. Useful for
developing console color themes, or even script output schemes.
Resources: