Skip to content

Instantly share code, notes, and snippets.

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
View gist:2870863
#!/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
View ports.sh
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}')"
View cond_var.go
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.
View gist:2002893
### 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
View gist:8305641
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}"
View gist:7997198
; 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
View gist:7904573
#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;
View gist:7653454
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).
View gist:7629514
/*
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
View gist:6941140
package main
import (
"encoding/json"
"errors"
"flag"
"fmt"
"net/http"
"net/url"
"os"