Skip to content

Instantly share code, notes, and snippets.

@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() {
@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 / 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 / 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 / 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 / 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 / gopher_Solution.java
Last active April 10, 2018 01:34
codejam 2018 qualifications
import java.util.*;
class Solution{
boolean allDone(boolean[][] grid, int c){
for(int i=0; i<3; i++){
for(int j=0; j<3; j++){
if(!grid[i][c+j]) return false;
}
}
@ongspxm
ongspxm / bathroom.java
Created April 1, 2018 05:59
2018 codejam practice
import java.util.*;
class Solution{
void run(){
Scanner cin = new Scanner(System.in);
int T = cin.nextInt();
for(int t=0; t<T; t++){
int N = cin.nextInt(),
K = cin.nextInt();
@ongspxm
ongspxm / .vimrc
Last active December 15, 2019 10:14
vimrc
" Colorscheme
colorscheme desert
syntax on
" Spaces & Tabs
set tabstop=4 shiftwidth=4 softtabstop=4 expandtab
set autoindent
retab
" Wrapping
@ongspxm
ongspxm / binaryTree_pre-in-generation.c
Last active March 15, 2018 15:48
generate binary tree from pre and in order
#include "stdio.h"
void postorder(int idx, int vals[], int left[], int right[]){
if(left[idx]>-1){ postorder(left[idx], vals, left, right); }
if(right[idx]>-1){ postorder(right[idx], vals, left, right); }
printf("%d ", vals[idx]);
}
int main(void){
int n; scanf("%d", &n);