Skip to content

Instantly share code, notes, and snippets.

View baltpeter's full-sized avatar

Benjamin Altpeter baltpeter

View GitHub Profile
@baltpeter
baltpeter / script.sh
Last active July 5, 2016 11:00
Setting up locale correctly on new Ubuntu/Debian servers
apt-get update # if this is the first boot on e.g. OpenVZ containers
apt-get install language-pack-en
update-locale LANG=en_US.UTF-8
shutdown -rf 0 # reboot to ensure new locale is applied
# when lang is "(undefinded)"; also preferred anyway
export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
locale-gen en_US.UTF-8
@baltpeter
baltpeter / script.sh
Created March 22, 2014 23:02
Find out system architecture on Unix
uname -m
@baltpeter
baltpeter / script.sh
Created March 22, 2014 23:09
System Update with apt/aptitude
apt-get update # update repositories first
# then do either
apt-get dist-upgrade
aptitude safe-upgrade # about equiv. to above, safer though
# alternative, doesn't install or uninstall any packages
apt-get upgrade
# reference: http://askubuntu.com/questions/194651/why-use-apt-get-upgrade-instead-of-apt-get-dist-upgrade
@baltpeter
baltpeter / script.sh
Created April 4, 2014 20:22
Find a file
find /path/here -name "what to look for"
@baltpeter
baltpeter / script.sh
Created April 27, 2014 12:54
Format and mount new hard drive
#1. Figure out the device name for the new device
fdisk -l
#This will give you output similar to this:
#Disk /dev/sda: 17.2 GB, 17179869184 bytes
#255 heads, 63 sectors/track, 2088 cylinders, total 33554432 sectors
#Units = sectors of 1 * 512 = 512 bytes
#Sector size (logical/physical): 512 bytes / 512 bytes
#I/O size (minimum/optimal): 512 bytes / 512 bytes
@baltpeter
baltpeter / UIColor_NSLog
Created May 3, 2014 22:49
Use NSLog to output a UIColor
CGFloat red, green, blue, alpha;
[color getRed: &red
green: &green
blue: &blue
alpha: &alpha];
NSLog(@"red = %f. Green = %f. Blue = %f. Alpha = %f",
red,
green,
blue,
alpha);
@baltpeter
baltpeter / UIImage_from_color
Created May 3, 2014 22:56
Create UIImage rectangle from color
+ (UIImage *)imageWithColor:(UIColor *)color {
CGRect rect = CGRectMake(0, 0, 1, 1);
// Create a 1 by 1 pixel context
UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0);
[color setFill];
UIRectFill(rect); // Fill it with your color
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
@baltpeter
baltpeter / interfaces.sh
Created June 1, 2014 14:32
Configure Debian/Ubuntu to use static IP instead of DHCP
nano /etc/network/interfaces
iface eth0 inet static
address 10.42.4.4
netmask 255.0.0.0
gateway 10.10.10.1
dns-nameservers 10.10.10.1 8.8.8.8 8.8.4.4
dns-search altpeter.me
/etc/init.d/networking restart
@baltpeter
baltpeter / treetagger.js
Last active August 29, 2015 14:08
Given a plain text wordlist, output all words from that list that are nouns
var Treetagger = require('treetagger');
var tagger = new Treetagger({ language: "french" });
var fs = require('fs'), filename = "/Users/benni/coding/tt-nodejs/french.txt";
fs.readFile(filename, 'utf8', function(err, data) {
if(err) throw err;
tagger.tag(data, function (err, results) {
results.forEach(function(e) {
if(e.pos == "NOM") {
console.log(e.t);
@baltpeter
baltpeter / checkdomain.php
Last active August 29, 2015 14:08
Use freedomainapi.com to check whether a domain is available as both .de and .com
<?php
function checkdomain($domain) {
$api_req = file_get_contents('http://freedomainapi.com/?key=YOURAPIKEY&domain=' . $domain);
$api_req = json_decode($api_req, true);
if($api_req['available'] == 'true') return true;
return false;
}