Skip to content

Instantly share code, notes, and snippets.

@jacks205
jacks205 / launch.sh
Last active August 29, 2015 14:10
Schedules server restart script
#!/bin/bash
#NOTE: USE `bash launch` not `sh launch`
timestamp(){
(date)
}
server_name="schedules-backend"
log_file="crash_log.txt"
server_log="server_log.txt"
time=$(timestamp)
crash_message="Restarting server. Logging scripted restart. (Add successful restart log);\n"
@jacks205
jacks205 / restart.sh
Last active August 29, 2015 14:10
Bash script to restart server on crash
#https://www.digitalocean.com/community/tutorials/how-to-use-a-simple-bash-script-to-restart-server-programs
#!/bin/sh
ps auxw | grep apache2 | grep -v grep > /dev/null
if [ $? != 0 ]
then
/etc/init.d/apache2 start > /dev/null
fi
@jacks205
jacks205 / process.sh
Created November 23, 2014 08:11
How to find a process on a port and kill it
#http://superuser.com/a/322365
#lsof -t -i:4444
kill `lsof -t -i:4444`
@jacks205
jacks205 / CitizenCrossfitViewController.swift
Created November 20, 2014 09:46
Basic Example of creating a SOAP request with AEXML and through a normal NSMutableURLRequest
//
// CitizenViewController.swift
// citizencrossfit
//
// Created by Mark Jackson on 19/11/2014.
// Copyright (c) 2014 Mark Jackson. All rights reserved.
//
import UIKit
@jacks205
jacks205 / GifBackground.swift
Created November 19, 2014 02:40
Gif Background in Swift
//
// ViewController.swift
// VideoBackground.swift
//
// Created by Peng Jin on 25/7/14.
// Copyright (c) 2014 elvinjin. All rights reserved.
//
import UIKit
@jacks205
jacks205 / VideoBlurBackground.swift
Last active September 18, 2020 08:58
Video Blur Background in Swift
//
// ViewController.swift
// citizencrossfit
//
// Created by Mark Jackson on 17/11/2014.
// Copyright (c) 2014 Mark Jackson. All rights reserved.
//
import UIKit
import Alamofire
@jacks205
jacks205 / TriangleNumber.java
Created May 24, 2013 05:04
Project Euler #12. What is the value of the first triangle number to have over five hundred divisors? I felt that this problem was easier than the last two, but I got stuck on line 29 and had to look up online for help. I want to come back to this problem and make it smoother. It is about 1.1 seconds, but it should be able to run at like 50ms wi…
public class TriangleNumber {
private int numDivisors;
public TriangleNumber(int numDivisors){ //takes in how many divisors
this.numDivisors = numDivisors;
}
public int firstOccurance(){ //returns the first occurance of the number of divisors you want the triangle number to have
int i = 1;
@jacks205
jacks205 / GridProduct.java
Created May 23, 2013 07:44
Project Euler #11. What is the greatest product of four adjacent numbers in the same direction (up, down, left, right, or diagonally) in the 20x20 grid? I made the program so any grid X by X (must be equal dimensions) could be used. I originally thought of using normal arrays, but it would just require more code, and someone could make a method …
public class GridProduct {
private int[][] grid = new int[][]{
{8, 02, 22, 97, 38, 15, 00, 40, 00, 75, 04, 05, 07, 78, 52, 12, 50, 77, 91, 8},
{49, 49, 99, 40, 17, 81, 18, 57, 60, 87, 17, 40, 98, 43, 69, 48, 04, 56, 62, 00},
{81, 49, 31, 73, 55, 79, 14, 29, 93, 71, 40, 67, 53, 88, 30, 03, 49, 13, 36, 65},
{52, 70, 95, 23, 04, 60, 11, 42, 69, 24, 68, 56, 01, 32, 56, 71, 37, 02, 36, 91},
{22, 31, 16, 71, 51, 67, 63, 89, 41, 92, 36, 54, 22, 40, 40, 28, 66, 33, 13, 80},
{24, 47, 32, 60, 99, 03, 45, 02, 44, 75, 33, 53, 78, 36, 84, 20, 35, 17, 12, 50},
{32, 98, 81, 28, 64, 23, 67, 10, 26, 38, 40, 67, 59, 54, 70, 66, 18, 38, 64, 70},
{67, 26, 20, 68, 02, 62, 12, 20, 95, 63, 94, 39, 63, 8, 40, 91, 66, 49, 94, 21},
@jacks205
jacks205 / SumOfPrimes.java
Created May 22, 2013 06:14
Project Euler #10 I made this method off the idea off of Project Euler's #10 of finding the sum of all primes up to two million, and made the method compatible with any limit you enter in the parameters. I started out doing the obvious thing and going through each number and finding if it was divisible by anything other than itself and 1, but ra…
public class SumOfPrimes {
public SumOfPrimes(){
System.out.println(sum(2000000)); //running the sum of primes limit to 2,000,000 [For Project Euler's answer]
}
public long sum(int limit){ //Project Euler wanted it for 2,000,000 but this method can do it for any limit given
boolean[] boolPrimes = new boolean[limit]; //initializing an array of booleans to the limit
boolPrimes[0] = false; //I know 0 isn't a prime
boolPrimes[1] = false;// I know 1 isn't a prime
@jacks205
jacks205 / Quiz1.py
Last active December 17, 2015 07:39
Quiz Handler gives out a quiz to the users, and then calculates the score and other information.
[
{ #question 1
'type' : 'multiple-choice',
'text' :
'Who was the first U.S. President?\n' +
'(1) Abraham Lincoln\n' +
'(2) George Washington\n' +
'(3) John Lennon\n' +
'(4) Franklin Roosevelt',