Skip to content

Instantly share code, notes, and snippets.

@toboqus
toboqus / base64.c
Last active September 2, 2022 06:09
Base64 in C
#include <stdlib.h>
#include "base64.h"
static char values[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
static int indexOf(char * array, char value){
int i;
for(i = 0; *array; ++i, ++array)
if(*array == value)
return i;
@toboqus
toboqus / Base64.java
Created February 23, 2016 08:46
Encoding and Decoding in base64
package base64;
public class Base64 {
private static String CODES = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "abcdefghijklmnopqrstuvwxyz"
+ "0123456789+/=";
public static String encode(byte[] input){
@toboqus
toboqus / Reverse.java
Created January 8, 2016 08:35
Rotating a string 180 degrees
public static String Reverse(String sentence){
String normal = "abcdefghijklmnopqrstuvwxyz_,;.?!/\\'";
String split = "ɐqɔpǝɟbɥıظʞןɯuodbɹsʇnʌʍxʎz‾'؛˙¿¡/\\,";
normal += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
split += "∀qϽᗡƎℲƃHIſʞ˥WNOԀὉᴚS⊥∩ΛMXʎZ";
normal += "0123456789";
split += "0ƖᄅƐㄣϛ9ㄥ86";
@toboqus
toboqus / Delete.java
Created January 4, 2016 08:18
Deleting empty directories
import java.io.File;
public class Delete {
public static void main(String[] args) {
if(args.length != 1){
System.out.println("ERROR: A path must be specified.");
System.exit(0);
}else{
@toboqus
toboqus / Backup.java
Created December 31, 2015 14:49
Simple method of replicating the file structure inc files from one drive/directory to another.
package backup;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
public class Backup {
@toboqus
toboqus / Count.java
Last active January 4, 2016 08:18
counting number of files within a given directory (Breadth first)
public int count(File root){
if(root == null || !root.exists()){
System.out.println("ERROR: The source drive/directory does not exist.");
return -1;
}
Queue<File> files = new Queue<>();
files.push(root);
@toboqus
toboqus / Cache-Spec.js
Created December 18, 2015 08:32
Cache for angularjs
/**
* Created by Alex on 20/10/2014.
*/
describe("Service: Cache", function () {
var $interval,
cacheService,
scope,
lo;
import sqlite3
import calendar
import time
class Database:
_conn = None
def __init__(self):
self._conn = sqlite3.connect("url.db")
cur = self._conn.cursor()
@toboqus
toboqus / pushingToTemplate.js
Created December 2, 2015 13:23
Pushing an object onto another object if the element names match
/**
* @name pushToTemplate
* @param template
* @param object
* @returns {object}
* @description will push the object onto the template
*/
var pushToTemplate = function pushToTemplate(template, object){
var result = angular.copy(template);
#include <stdio.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
int main(void)
{
int fd = open("/dev/sdd", O_WRONLY);
if (fd < 0) {