Skip to content

Instantly share code, notes, and snippets.

@nanch
nanch / propertyMapping.js
Created February 27, 2017 15:30
Mapping properties of javascript objects from under_score to camelCase and back again
String.prototype.toCamel = function () {
return this.replace(/(_[a-zA-Z])/g, function ($1) {
return $1.toUpperCase().replace('_', '');
});
};
String.prototype.toUnderscore = function () {
return this.replace(/([A-Z])/g, function ($1) {
return "_" + $1.toLowerCase();
<?php
function addAll_VariadicFunction(...$rest)
{
return array_reduce($rest, function ($a, $b) {
return $a + $b;
});
}
function add_SimpleReduce($a, $b)
hello geoff
@nanch
nanch / submit.php
Created November 15, 2012 08:39
New submit code
// Create (connect to) SQLite database in file
$file_db = new PDO('sqlite:/usr/local/etc/tarbackup/db/tarbackup.db');
// Set errormode to exceptions
$file_db->setAttribute(PDO::ATTR_ERRMODE,
PDO::ERRMODE_EXCEPTION);
// Array with some test data to insert to database
$users = array(
array('Name' => $name,
'Password' => crypt512($password),
@nanch
nanch / submit.php
Created November 15, 2012 08:37
Old submit code
$myFile = "/usr/local/etc/tarbackup/userstocreate.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = $name . ":" . crypt512($password) . ":" . $email . "\n";
fwrite($fh, $stringData);
fclose($fh);
@nanch
nanch / createusers.py
Created November 15, 2012 05:06
Tarbackup code to create new users
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sqlite3 as lite
import sys
import os
def get_users_to_create():
con = None
try:
@nanch
nanch / createusers.pl
Created November 15, 2012 04:55
Code for creating users on tarbackup
use File::Copy;
$dir = "/usr/local/etc/tarbackup/";
$logfilename = $dir . "createdusers.log";
$infilename = $dir . "userstocreate.txt"; # the queue of users that have signed up since last run
copy($infilename, $infilename . ".copy"); # make a copy to make this process as atomic as possible
#delete and recreate the existing file with the same permissions
unlink($infilename);
open NEWFILE, ">$infilename" or die $!;
@nanch
nanch / initializedb.py
Created November 15, 2012 04:23
Initialize the SQLite database.
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sqlite3 as lite
import sys
def get_users():
with open("createdusers.log") as f:
users = []
lines = f.readlines()
@nanch
nanch / backup_entire_system.sh
Created October 7, 2012 16:31
how to create tar backups and post to tarbackup.com
mkdir /backups
cd /backups/
tar -cvpzf fullbackup.tar.gz --directory=/ --exclude=proc --exclude=sys --exclude=dev/pts --exclude=backups .