Skip to content

Instantly share code, notes, and snippets.

View csabatini's full-sized avatar

Caleb Sabatini csabatini

View GitHub Profile
#!/bin/bash
# increase max open files
echo -e "root soft nofile 32768\nroot hard nofile 32768" >> /etc/security/limits.conf
echo -e "session required pam_limits.so" >> /etc/pam.d/common-session
echo -e "session required pam_limits.so" >> /etc/pam.d/common-session-noninteractive
# create swap
fallocate -l 56G /mnt/swapfile
chmod 600 /mnt/swapfile
mkswap /mntswapfile
swapon /mnt/swapfile
@csabatini
csabatini / nginx.conf
Created August 23, 2015 02:05
nginx conf to block agents from scraping REST API
server {
# Workaround for multiple nginx conditions:
# https://gist.github.com/jrom/1760790
## White list dev machine ##
if ($remote_addr = YOUR_IP_HERE) {
set $flag isdev;
}
# Block wget/mozilla/ie/chrome agents
@csabatini
csabatini / db_write.py
Last active August 29, 2015 14:16
MySQLdb
import MySQLdb
db = MySQLdb.connect("localhost", "user", "pw", "census")
cursor = db.cursor()
sql = 'INSERT INTO name (name, gender) VALUES (\'Bob\', \'M\')'
try:
cursor.execute(sql)
db.commit()
except:
@csabatini
csabatini / db_read.py
Created March 9, 2015 19:39
MySQL-python
import MySQLdb
db = MySQLdb.connect("localhost", "user", "pw", "census")
cursor = db.cursor()
sql = 'SELECT * FROM name'
cursor.execute(sql)
results = cursor.fetchall()
print len(results)
@csabatini
csabatini / db_setup.py
Last active August 29, 2015 14:16
MySQL-python
# MySQLdb - http://sourceforge.net/projects/mysql-python. Download MySQL-python-1.2.4b4.win32-py2.7.exe
# MySQL 5.6 Community. Download mysql-installer-web-community-5.6.23.0
import MySQLdb
db = MySQLdb.connect("localhost", "user", "pw")
cursor = db.cursor()
sql = 'CREATE DATABASE census'
cursor.execute(sql)
db.close()
from __future__ import print_function
from bs4 import BeautifulSoup
from urlparse import urlparse
from urlparse import parse_qs
import sys, logging
import mechanize
import time
import csv
import sqlite3
import requests
import java.util.Scanner;
public class Power {
public static int pow(int x, int n) {
if (n == 0)
return 1;
else
return x * pow(x, n-1);
}
import java.util.Scanner;
import java.util.Arrays;
public class Square {
public static void drawSquare(int dim) {
// Create an array with one string element to contain each row
String arr[] = new String[dim];
Arrays.fill(arr, "");
@csabatini
csabatini / Animated.java
Created April 20, 2013 04:13
Animated.java
/** PROGRAM ASSIGNMENT 5 Animated.java
*
* Program Description
* This is the Animated class, a subclass of the Movie class.
*
*/
package library.films;
public final class Animated extends Movie {
@csabatini
csabatini / CalebSabatiniP5.java
Created April 20, 2013 02:10
CalebSabatiniP5.java
/** PROGRAM ASSIGNMENT 5 CalebSabatiniP5.java
*
* Program Description
* This is the client code for the Movie class and its subclasses, which
* allows the user to navigate a Warren movie theater menu.
*
*/
import library.films.*;
import java.util.Scanner;