Skip to content

Instantly share code, notes, and snippets.

Avatar

James Bos jampola

View GitHub Profile
@jampola
jampola / friendly_date_range.js
Created Nov 1, 2016
Friendly Date Ranges (FreeCodeCamp)
View friendly_date_range.js
function makeFriendlyDates(arr) {
dateArr = [];
months = {
'01':'January','02':'February','03':'March',
'04':'April','05':'May','06':'June',
'07':'July','08':'August','09':'September',
'10':'October','11':'November','12':'December'
};
@jampola
jampola / update_inventory.js
Last active Nov 1, 2016
Inventory update (FreeCodeCamp)
View update_inventory.js
function updateInventory(curArr, newArr) {
// All inventory must be accounted for or you're fired!
// using an object so we can assign k'v values
var curObj = {};
var returnArr = [];
var arr = [];
// add to obj so we can access k,v's
curArr.forEach(function(data){
View cowsandbulls.py
from random import randint, randrange
number = [randrange(1,9) for x in range(4)]
guesscount = 1
def game(guess):
cows = 0
bulls = 0
global guesscount
if guess != ''.join(str(x) for x in number):
@jampola
jampola / randompassword.py
Created Sep 7, 2016
Generate a random password based user selected length. (upper,lower letters, numbers and symbols)
View randompassword.py
from random import randint
def main(passlen = 8):
password = []
for x in range(0,passlen):
r = randint(1, 4)
if r == 1:
password.append(chr(randint(97,122)))
elif r == 2:
password.append(str(randint(0,9)))
@jampola
jampola / gist:0073b8d14dc8d8a3668e716bed44cf9f
Created Apr 11, 2016
Update Java Alternatives (Debian)
View gist:0073b8d14dc8d8a3668e716bed44cf9f
Download/tar xvfz oracle java (somewhere like /opt/java is fine)
# update-alternatives --install /usr/bin/java java /path/to/oracle/install/java 1000
# update-alternatives --install /usr/bin/javac javac /path/to/oracle/install/javac 1000
# update-alternatives --config java
# update-alternatives --config javac
View gist:fc847b0d60d382040696
# -*- coding: utf-8 -*-
#!/usr/bin/python
import urllib2
import json
import time
import os
import sys
import pprint
class weatherData:
@jampola
jampola / alarmclock.py
Last active Nov 5, 2020
Fully functioning mp3/wav/ogg playing Alarm Clock (PyGTK and Gst)
View alarmclock.py
#!/usr/bin/python
'''
jamesbos [at] gmail [dot] com - originally shared at https://gist.github.com/jampola/ad3995e227dc46cfe069
Fully functioning alarm clock. Very primitive I know but this shows how basic events and
"threading" within pygtk[1] and media playback in gst[2] works. The main reason for sharing this on gist.github.org is so
it is searchable via google.
Include a an mp3 file called "alarm.mp3" in the same directory as this file OR supply the
/path/to/whatever.mp3/wav/ogg that you wish to play.
@jampola
jampola / clock.py
Last active Sep 29, 2020
Simple clock using PyGTK and GObject.timeout_add()
View clock.py
#!/usr/bin/python
from gi.repository import Gtk, GObject
from datetime import datetime
class MainWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="app")
self.box = Gtk.Box(spacing=6)
self.add(self.box)
You can’t perform that action at this time.