Skip to content

Instantly share code, notes, and snippets.

View kana-ph's full-sized avatar

KaNa kana-ph

  • Metro Manila, PH
View GitHub Profile
ForEach ($file in $args)
{
Write-Host "Converting: $file"
((Get-Content $file) -join "`n") + "`n" | Set-Content -NoNewline $file
}
#include <stdio.h>
void print_matrix(int m, int n, int matrix[m][n]);
void multiply(int n, int m, int p, int a[n][m], int b[m][p], int c[n][p]);
int main() {
int x[3][2] = {
{1, 2},
{3, 4},
@kana-ph
kana-ph / stdin-password.c
Created September 15, 2017 21:20
Password input from stdin using curse getch()
#include <stdio.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
int getch();
const char ENTER_KEY = '\n';
const char BACKSPACE_KEY = (char) 127;
@kana-ph
kana-ph / avl-tree.c
Last active August 28, 2017 03:03
Simple AVL Tree Insert
#include <stdio.h>
#include <stdlib.h>
typedef struct node {
int value;
int height;
struct node *left;
struct node *right;
} Node;
@kana-ph
kana-ph / bash-echo.md
Created March 15, 2017 13:58
Format text and add color to bash echo

Echo

echo -e "\033[X;YYmFORMATTED TEXT HERE!\033[0;0m"

Where:

  • X is the Format,
  • YY is the colour code, and
  • \033[0;0m clears the formatting

Formats

@kana-ph
kana-ph / TimedAction.cs
Last active January 19, 2017 13:16
Utility class/functions for measuring code execution time.
using System.Diagnostics;
public sealed class TimedAction
{
private TimedAction() { }
public delegate void Action();
public static long Run(Action action)
{
@kana-ph
kana-ph / Fibo.java
Last active January 19, 2017 08:17
Solution to https://projecteuler.net/problem=2 using Java8 streams/optionals
import java.util.Arrays;
import java.util.stream.Stream;
public class Fibo {
public static void main(String[] args) {
Arrays
.stream(args)
.findFirst()
.map(Long::parseLong)
.map(Fibo::computeFiboSum)
@kana-ph
kana-ph / ogv2gif.sh
Last active November 25, 2016 03:46
Convert OGV to GIF using ffmpeg
#!/bin/sh
# Sources: http://unix.stackexchange.com/questions/35282/convert-ogv-video-to-gif-animation
# http://superuser.com/questions/556029/how-do-i-convert-a-video-to-gif-using-ffmpeg-with-reasonable-quality/556031#556031
if [ "$#" -gt 0 ]; then
input=$1
output=${input/.ogv/-ogv.gif}
if [ -f $output ]; then
@kana-ph
kana-ph / ApplePen.java
Created September 28, 2016 02:19
Sample Applet (yuck)
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class ApplePen extends JApplet {
public void init() {
this.setLayout(new GridLayout(3, 1));
using System;
using System.IO;
string downloads = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\Downloads\";
string[] files = Directory.GetFiles(downloads);
foreach (string file in files)
{
AddToGridView(file);
}