Skip to content

Instantly share code, notes, and snippets.

Avatar
☢️

John Andersen pdxjohnny

☢️
View GitHub Profile
@pdxjohnny
pdxjohnny / log.go
Created Aug 28, 2015
Redirect stdout to websocket in go, great for logging in gomobile
View log.go
package main
import (
"bufio"
"fmt"
"io"
"log"
"os"
"time"
@pdxjohnny
pdxjohnny / string_split.cpp
Last active Aug 29, 2015
Split On Substring
View string_split.cpp
std::vector<std::string> split_line(std::string str, std::string sub)
{
std::vector<std::string> vector_split_line;
std::string split_line = "";
std::string sub_line = "";
bool skip = false;
for ( int current_char = 0; current_char < str.length(); current_char++ )
{
if ( str[current_char] == sub[0] )
{
@pdxjohnny
pdxjohnny / mail.py
Created Nov 26, 2014
Send email via gmail
View mail.py
import smtplib
import sys
class gmail(object):
"""docstring for gmail"""
def __init__( self, username, password ):
self.username = username
self.password = password
self.login()
@pdxjohnny
pdxjohnny / resize.py
Last active Aug 29, 2015
Resizes images to whatever sizes are listed in the resize_config.txt file, great for creating iPhone icons
View resize.py
#! /usr/bin/python
from PIL import Image
import sys
import os
imageFile = sys.argv[1]
file_name = imageFile.split(".")[0]
ext = imageFile.split(".")[-1]
sizes = []
@pdxjohnny
pdxjohnny / mysql.py
Created Mar 4, 2015
Ultimate python MySQL functions
View mysql.py
import MySQLdb
db_config = {
"host":"localhost",
"username":"username",
"password":"password",
"name":"name_of_database"
}
def query( query, bindings = False ):
@pdxjohnny
pdxjohnny / AndroidManifest.xml
Last active Aug 29, 2015
Android Socket Server
View AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.intel.camerawebserver" >
<uses-permission android:name="android.permission.INTERNET"
android:required="true" />
<uses-feature android:name="android.hardware.camera"
android:required="true" />
<application
@pdxjohnny
pdxjohnny / image_video.js
Created Apr 9, 2015
Grabs an image over and over to create a video, pass it the id of the Image element you want made into a video
View image_video.js
var image_video = function image_video ( id )
{
this.image_element = document.getElementById( id );
this.page = this.image_element.src;
this.running = false;
return this;
}
image_video.prototype.get_image = function get_image ( page, callback )
{
@pdxjohnny
pdxjohnny / startvms.sh
Created Apr 23, 2015
Start Virtualbox VMs on boot
View startvms.sh
#!/bin/bash
# Run as root
touch /etc/init.d/startvms
chmod +x /etc/init.d/startvms
update-rc.d startvms defaults 99 01
cat <<'EOF' >> /etc/init.d/startvms
#! /bin/sh
# /etc/init.d/startvms
#
@pdxjohnny
pdxjohnny / swap_bits.c
Last active Aug 29, 2015
C Shifting bits in a byte
View swap_bits.c
char swap_bits( char byte, int one, int two )
{
char tmp_1, tmp_2, swap;
int hex_1 = pow(2, one);
int hex_2 = pow(2, two);
tmp_1 = byte & hex_1;
tmp_1 = tmp_1 >> abs( one - two );
tmp_2 = byte & hex_2;
tmp_2 = tmp_2 << abs( one - two );
if ( tmp_1 == 0 && tmp_2 != 0 )
@pdxjohnny
pdxjohnny / sub.sh
Created Apr 30, 2015
Add srt subtitles to mp4
View sub.sh
#!/bin/bash
ffmpeg -i ${1}.srt ${1}.ass
ffmpeg -i ${1}.mp4 -vf ass=${1}.ass ${1}_subtitles.mp4
You can’t perform that action at this time.