Skip to content

Instantly share code, notes, and snippets.

@ongspxm
ongspxm / travelling.py
Last active May 8, 2018 02:45
genetic adaption for travelling salesman
import math
import random
import matplotlib.pyplot as plt
import pickle
FNAME = "data.obj"
# generate 30 towns in a 1000*1000 grid
TOWN = 30
GRID = 1000
@ongspxm
ongspxm / antstack_Solution.java
Last active May 8, 2018 05:12
codejam 2018 1C
import java.util.*;
class Solution{
ArrayList<Integer> weights, minWeights;
void run(){
Scanner cin = new Scanner(System.in);
int T = cin.nextInt();
for(int t=0; t<T; t++){
@ongspxm
ongspxm / dload
Last active October 30, 2018 05:52
download videos from viu using youtube-dl
# run with the starting index like so: `dload 5`
# first url on the list will be index-ed 5
# pipe in list of urls
i=$1
if [ -d $1 ]; then i=1; fi
while read f; do
name=$(echo $f | tr "/" "\n" | tail -n 1)
@ongspxm
ongspxm / script.js
Last active November 26, 2018 11:50
vortex space terrain rendering
const WIDTH = 128;
const COLOUR = document.getElementById("colour").getContext("2d");
const HEIGHT = document.getElementById("height").getContext("2d");
const COMBIN = document.getElementById("combin").getContext("2d");
var X=WIDTH/2, Y=WIDTH/2;
var ANGLE=0, DOP=WIDTH/2;
var img_height = "https://cdn.glitch.com/3bb25b2e-fb56-49fd-96e9-a9af83d391d2%2Fheight.jpg?1513785075480";
var img_color = "https://cdn.glitch.com/3bb25b2e-fb56-49fd-96e9-a9af83d391d2%2Fcolor.jpg?1513785075766";
@ongspxm
ongspxm / dec.py
Created August 11, 2019 09:38
using pillow to encode and decode files into images
import sys
from PIL import Image
try:
ifile = sys.argv[1]
ofile = sys.argv[2]
except:
print ('usage: dec.py [input file] [out file]\n\n')
img = Image.open(ifile)
@ongspxm
ongspxm / bplate.cpp
Created March 18, 2020 05:10
Boilerplate for cpp problems
#include <bits/stdc++.h>
#define let const auto
#define REP(var, i) for (int var = 0; var < i; ++var)
using namespace std;
using Int = int;
//using Int = long long;
using vi = vector<Int>;
using vvi = vector< vector<Int> >;
void solve() {