Skip to content

Instantly share code, notes, and snippets.

View aramperes's full-sized avatar
🕊️

Aram Peres aramperes

🕊️
View GitHub Profile
@aramperes
aramperes / example.sh
Created June 3, 2023 19:43
A leaner __git_ps1 function (~50%) for slow systems
# Original __git_ps1
$ time orig__git_ps1 || 0
(my-branch)
real 0m1.102s
user 0m0.000s
sys 0m0.140s
# Lean function
$ time __git_ps1 || 0
(my-branch)
@aramperes
aramperes / vimnotes.md
Last active May 25, 2021 07:21
My personal notebook for day-to-day vim usage

vimnotes

My personal notebook for day-to-day vim usage.

Individual commands (normal mode)

  • i / [Insert] enters insert mode at current character
  • I enters insert mode at beginning of line
  • a enters insert mode at next character
  • A enters insert mode at end of line
  • $ goto end of line
@aramperes
aramperes / sorting.rs
Created January 22, 2020 06:01
Some sorting algorithms implemented in Rust, with tests
/// Some sorting algorithms written in Rust.
fn insertion_sort(vec: &mut Vec<i32>) {
let length: i32 = vec.len() as i32;
if length < 2 {
// Vector is already sorted if of length 0 or 1
return;
}
package tictactoegame.ui;
import javax.swing.*;
import java.awt.*;
public class SwingTicTacToe extends JFrame {
/**
* The font used for the buttons.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <limits.h>
#include <sys/mount.h>
extern char * ffmount(char *path)
{
int rc;
@aramperes
aramperes / road_navigation.py
Created June 17, 2018 01:01
My solution to the "Road navigation" edabit challenge
# coding=utf-8
import json
import os
def neighbours_of(edges, node):
neighbours = []
for edge in edges:
if node in edge:
neighbours.append(edge[0 if edge[1] == node else 1])
@aramperes
aramperes / sort.py
Last active May 10, 2018 00:34
Selection, Insertion, Bubble and Merge sort in Python 3
def selection_sort(array):
for index in range(len(array)):
currentMin = array[index]
currentMinIndex = index
# check the minimum value in the sub-array after the current index
for subIndex in range(index + 1, len(array)):
if array[subIndex] < currentMin:
currentMin = array[subIndex]
currentMinIndex = subIndex
@aramperes
aramperes / add_tf.py
Last active March 13, 2018 02:12
A python TensorFlow script that uses supervised learning to sum scalars
import numpy as np
import tensorflow as tf
batch_size = 1
data_size = 10000
batches = int(data_size / batch_size)
# X is a (n 2) matrix with random positive floats between 0 and 100
X = np.random.rand(data_size, 2)
# Y is a (n 1) matrix with the sum of the two columns of X
@aramperes
aramperes / stm-curl-realtime.sh
Created February 8, 2018 19:04
curl request to find real-time STM bus times at a certain stop.
# This is a curl command to get live/real-time STM bus schedules for a stop.
# Note that the "Origin" request header set to "http://beta.stm.info" is necessary.
curl -H "Accept: application/json" -H "Origin: http://beta.stm.info" "https://api.stm.info/pub/i3/v1c/api/en/lines/{BUS_LINE}/stops/{STOP_ID}/arrivals?d={DATE_YYYY_MM_DD}&t={24H_TIME_HHMM}&direction={DIRECTION}&wheelchair=0&limit=5"
# {BUS_LINE} = Line number (e.g. 123)
# {STOP_ID} = Stop number (e.g. 12345)
# {DATE_YYYY_MM_DD} = The date, in the YYYYMMDD format (e.g. 20180208)
# {24H_TIME_HHMM} = The time, in 24-hour format (HHMM) (e.g. 1348)
# {DIRECTION} = Line direction, E/W/N/S
// the shortest JS code to create and run an HTTP server, using the least amount of different characters possible.
// this only works on node.js for obvious reasons.
require('http').createServer((e,r)=>{r.write('r');r.end()}).listen(80)
// if you don't want any response body (just accept the connection):
require('http').createServer((e,r)=>r.end()).listen(80)