View rPi_backup.sh
### Modified by Hersh Bhargava from user Jaac on Raspberry Pi Forum ### | |
#!/bin/bash | |
# Setup directories | |
SUBDIR=pi_system_backups | |
DIR=/hdd/$SUBDIR | |
echo "Starting Raspberry Pi backup process." | |
# First check if pv package is installed, if not, install it first |
View RandomStringWithLength.m
/* Created by Hersh Bhargava of H2 Micro (www.h2micro.com) */ | |
@interface NSString (Randomize) | |
+ (NSString *)randomStringWithLength:(int)length; | |
@end | |
@implementation NSString (Randomize) | |
+ (NSString *)randomStringWithLength:(int)length | |
{ |
View SieveOfEratosthenes.py
# Created by Hersh Bhargava of H2 Micro (www.h2micro.com) | |
#sieve for primes between 1 and cap. | |
def prime_sieve(cap): | |
n = cap + 1 | |
nprime = set() | |
prime = [] | |
for i in range(2, n): | |
print("Sieve Operation Completion: " + str((i/n) * 100)) | |
if i in nprime: |
View ESCArduinoDriver.ino
/* Created by Hersh Bhargava of H2 Micro (www.h2micro.com) */ | |
#include <Servo.h> | |
Servo esc1; //Create a servo object to control a servo. | |
int xPotPin = 0; //Pins for analog potentiometers. | |
int esc1Value; | |
void setup() { | |
Serial.begin(9600); |
View DynamicallyExpandingForm.js
/* Created by Hersh Bhargava of H2 Micro (www.h2micro.com) */ | |
//Keep track of dynamically added text inputs in 'i' | |
var i = $('#items p').size() + 1; | |
//Keyup function to add text input on tab release from last field | |
$(document).on('keyup', 'input[type="text"]:last', function (e) { | |
//check if the released key was the tab key | |
if (e.which == 9) { | |
//append additional fields to items div | |
var targetDiv = $('#items'); |
View OptimizeAndEncodeUIImage.m
/* Created by Hersh Bhargava of H2 Micro (www.h2micro.com) */ | |
- (NSString *)compressAndEncodeToBase64String:(UIImage *)image | |
{ | |
//Scale Image to some width (xFinal) | |
float ratio = image.size.width/image.size.height; | |
float xFinal = 700; //Desired image width | |
float yFinal = xFinal/ratio; | |
UIImage *scaledImage = [self imageWithImage:image scaledToSize:CGSizeMake(xFinal, yFinal)]; |
View SendDictionaryToScript.m
/* Created by Hersh Bhargava of H2 Micro (www.h2micro.com) */ | |
- (void)sendDictionary:(NSDictionary *)dictionary toScript:(NSString *)scriptName completion:(void (^) (id response))completionBlock | |
{ | |
//Convert the passed dictionary into JSON. | |
NSString *JSONStringfromDictionary = [self JSONfromDictionary:dictionary]; | |
//Set up the query string for the Server with the API Key inline. | |
NSString *URLString = YOUR_URL_STRING; | |
NSString *queryString = [NSString stringWithFormat:@"%@key=%@", URLString, YOUR_OPTIONAL_API_KEY]; | |
//Create a URLRequest using the query string. |
View ProcessTiming.m
/* Created by Hersh Bhargava of H2 Micro (www.h2micro.com) */ | |
NSDate *processStart = [NSDate date]; | |
//Process Here! | |
NSDate *methodFinish = [NSDate date]; | |
NSTimeInterval executionTime = [methodFinish timeIntervalSinceDate:methodStart]; | |
NSLog(@"Process Execution Time (s): %f", executionTime); |
View UIRefreshControlImplementation.m
/* Created by Hersh Bhargava of H2 Micro (www.h2micro.com) */ | |
//Header | |
UIRefreshControl *refreshControl; | |
//Main Load | |
refreshControl = [[UIRefreshControl alloc] init]; | |
[tableView addSubview:refreshControl]; | |
//Main Begin Refresh | |
[refreshControl beginRefreshing]; | |
[refreshControl setHidden:false]; |