Skip to content

Instantly share code, notes, and snippets.

View larzconwell's full-sized avatar

Larz Conwell larzconwell

View GitHub Profile
@larzconwell
larzconwell / gist:2870863
Created June 4, 2012 21:08
Convert pdf to text and read it out loud
#!/bin/bash
if [[ "$1" != "" ]]; then
pdf_file="$1"
shift
rm /tmp/pdf_file.txt >> /dev/null 2>&1
if [[ ! -f $(which pdftotext) ]]; then
echo "You do not have xpdf installed, please install it to convert pdfs to text..."
exit 1
ports () {
local items="$(sudo lsof -n -i -P | tr -s " " | cut -d " " -f 2,9,10 | \grep "LISTEN")"
printf "%-10s %-20s %s\n" "PID" "ADDRESS" "COMMAND"
if [[ "${items}" == "" ]]
then
return
fi
while read item
do
pid="$(echo "${item}" | awk '{print $1}')"
package main
import (
"fmt"
"sync"
"time"
)
var tasks []int
var wg sync.WaitGroup
@larzconwell
larzconwell / gist:2002893
Created March 8, 2012 19:38
Rails sessions with Redis, the output.
### Gemfile
gem "redis"
gem "redis-rails", "~> 3.2.1.rc"
### app/controllers/sessions_controller.rb
def create
user = User.where(email: params[:email]).first
# 'authenticate' comes from the 'has_secure_password' method in the User model
if user && user.authenticate(params[:password])
session[:user_id] = user.id # Set a session from the id
alias update="sudo apt-get update"
alias upgrade="update && sudo apt-get upgrade"
alias dist-upgrade="upgrade && sudo apt-get dist-upgrade"
alias install="sudo apt-get install ${@:2}"
alias uninstall="sudo apt-get purge ${@:2}"
alias search="apt-cache search ${@:2}"
; Write contents from stdin to a given file
section .rodata
errnofile: db "No filename given", 10
errnofilelen: equ $ - errnofile
errnocreate: db "Couldn't create file", 10
errnocreatelen: equ $ - errnocreate
errnowrite: db "Couldn't write file", 10
errnowritelen: equ $ - errnowrite
section .bss
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static char *strs[] = {"example", "another", "hi"};
static int strc = 3;
int main(void) {
int i = 0;
int size = 1;
global _start
extern main
section .text
_start:
call main
mov ebx, eax ; EAX HOLDS THE FUCKING RETURN STATUS, OMG
mov eax, 1
int 0x80
@larzconwell
larzconwell / gist:7629514
Created November 24, 2013 17:05
Binary Clock(update minute and hour variable with current time before writing to device).
/*
Layout of pins:
3 10
4 7 11
1 5 8 12
2 6 9 13
*/
#include <EEPROM.h>
int startupDone = 0;
@larzconwell
larzconwell / gist:6941140
Created October 11, 2013 20:02
Moln Client example
package main
import (
"encoding/json"
"errors"
"flag"
"fmt"
"net/http"
"net/url"
"os"