Skip to content

Instantly share code, notes, and snippets.

@RSully
RSully / call.php
Created April 24, 2013 14:24
This script can be used with something like `xdg` in order to add `sip:` handling to Chrome or Firefox using SFLphone. It takes a single argument, strips it to numerics and triggers a `dbus-send` to SFLphone's method to place a call. It uses the first account, which may or may not be what you want. `xdg-mime default sip-call-handler.desktop x-sc…
#!/usr/bin/php
<?php
// Requirements:
// sudo apt-get install php5-cli php-pear libyaml-dev
// sudo pecl install yaml
$file = $_SERVER['HOME'] . '/.config/sflphone/sflphoned.yml';
$acct_id = get_account_id($file);
$call_to = preg_replace('/[^0-9]/', '', $argv[1]);
@RSully
RSully / pcl2pdf.sh
Created April 19, 2013 00:37
Function to convert PCL to PDF using `pcl6`
pcl2pdf() {
input=$1
output=${2-$input.pdf}
pcl6 -o $output -sDEVICE=pdfwrite $input
}
@RSully
RSully / input_parse.js
Created March 28, 2013 12:26
Parse input "arrays" in JS
function parseInputs(data) {
var ret = {};
retloop:
for (var input in data) {
var val = data[input];
var parts = input.split('[');
var last = ret;
for (var i in parts) {
@RSully
RSully / update.sh
Created March 22, 2013 14:23
Update file perms for PHP
find . -type f -print0 | xargs -0 chmod 644
find . -type d -print0 | xargs -0 chmod 755
@RSully
RSully / Sublime-Preferences.json
Last active December 10, 2015 22:29
My Sublime Text config file
{
"bold_folder_labels": true,
"caret_style": "phase",
"ensure_newline_at_eof_on_save": true,
"font_face": "Source Code Pro",//"Menlo",
"font_size": 12,
"highlight_line": true,
"highlight_modified_tabs": true,
"scroll_past_end": true,
"theme": "Soda Dark.sublime-theme",
@RSully
RSully / DB.class.php
Last active September 10, 2019 08:21
Database class that extends PDO and adds easier to work with functionality (with prepared query caching)
<?php
/**
* Copyright 2012-2013 Ryan. All rights reserved.
* https://github.com/rsully
* https://gist.github.com/rsully/4162064
* You may use this code provided this message and the above copyright are kept in place.
**/
class DB extends PDO
{
protected $prepared = null;
@RSully
RSully / vector_sum.basic
Created March 9, 2012 11:02
Vector summation calculator
# Get the amount of vectors we need to sum
Input "SUM HOW MANY? ", A
# Clear the previous lists
ClrList lVSUA
ClrList lVSUB
ClrList lVSUX
ClrList lVSUY
# Zero-out each list with A items
@RSully
RSully / byte_freq.rb
Created March 3, 2012 02:17
Byte frequency counter in ruby
if ARGV.count != 1
puts "Usage: [command ...] <file>"
exit
end
f = File.new(ARGV[0], 'r')
hash = Hash.new
f.each_byte do |byte|
@RSully
RSully / primes.py
Created February 12, 2012 00:13
Prime generator - draft concept of 6n±1
prev = []
start = 5
num = start
lastPrime = (0,0)
ctr = 2 # 5 is the 3rd prime
while ctr < 50000:
isPrime = not any(num % n == 0 for n in prev)
if isPrime:
ctr += 1
@RSully
RSully / 6npm1.py
Created February 11, 2012 22:40
6n ± 1
from math import floor
def pp(n):
return (6*(floor(n/2)+1)) + (-1 if n % 2 == 0 else 1)
for i in xrange(0, 50):
print "%d\t\t%d" % (i, pp(i))