Skip to content

Instantly share code, notes, and snippets.

def color_wrap(msg, color='blue'):
end_color = '\033[0m'
color_dict = {
'blue': '\033[94m',
'green': '\033[92m',
'yellow': '\033[93m',
'red': '\033[91m',
'purple':'\033[95m'
}
color = color_dict.get(color)
@adrianmoses
adrianmoses / myip.sh
Last active August 29, 2015 14:08
Find public ip of instance
#!/bin/bash
curl --silent "http://httpbin.org/ip" | jq '.origin' | sed -e 's/\"//g'
@adrianmoses
adrianmoses / string_to_permalink.rb
Created April 15, 2014 18:52
String to permalink - ruby
(ns command-line-args.core
(:gen-class)
(:require [org.httpkit.client :as http]
[net.cgrand.enlive-html :as html])
(:use clojure.java.browse)
(:import java.io.StringReader)
(:import java.lang.Integer))
(def base-url "https://news.ycombinator.com")
@adrianmoses
adrianmoses / goquery-example.go
Last active April 20, 2018 03:13
goquery example
package main
/*
* Script that scrapes google front page
* Usage: ./google [<query>]
* e.g. ./google hacker news
*/
import (
"fmt"
#!/bin/sh
while true; do { echo -e 'HTTP/1.1 200 OK\r\n'; cat index.html; } | nc -l 8080; done
# one line function that reverses integers
reverse = lambda n: int(''.join(list(str(n))[::-1]))
plotShares <- function(){
sharesData <- read.csv('shares.csv')
sharesData$Date <- as.Date(sharesData$Date, '%b %d, %Y')
plot(sharesData$Date, sharesData$Shares)
}
module Tackit
class User
def initialize(user, pass)
@user = user
@pass = pass
@token = Token.new.find_token(@user, @pass)
end
def has_token?
#include <stdio.h>
#include <time.h>
#define TIME_SIZE 100
char * getcurrenttime(){
char *buffer = malloc(TIME_SIZE);
struct tm *ts;
size_t size;
time_t timestamp = time(NULL);