Skip to content

Instantly share code, notes, and snippets.

@andelf
andelf / update3322.sh
Created June 24, 2013 09:02
update 3322.org ddns
#!/bin/bash
USERNAME="YOUR_USERNAME"
PASSWORD="YOUR_PASSWORD"
IP=$(curl -s http://ip.3322.net)
HOSTNAME="YOURDOMAIN.3322.org"
DATE=$(date)
@andelf
andelf / sighup.go
Created June 29, 2013 05:25
golang process SIGHUP, HUP signal to reload configuration
// program
package main
import "os/signal"
import "os"
import "fmt"
import "syscall"
import "time"
@andelf
andelf / monad.js
Created November 25, 2013 06:34
Monad in javascript.
function MONAD(modifier) {
var prototype = Object.create(null);
function unit(value) {
var monad = Object.create(prototype);
monad.bind = function (func, args) {
return func.apply(undefined,
[value].concat(Array.prototype.slice.apply(args || [])));
};
if (typeof modifier == 'function') {
monad = modifier(monad, value);
@andelf
andelf / .ghci
Last active December 29, 2015 07:39
dot.files
:set prompt "λ> "
:set +t
@andelf
andelf / macos_wifi_weak_password_scanner.py
Created January 18, 2014 01:41
macos Wifi 弱密码连接器。因为没写切channel的功能,所以多执行几遍就好。
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
from commands import getstatusoutput, getoutput
WIFI_IF = "en0"
class Wifi(object):
@andelf
andelf / simple_chat.rs
Last active April 13, 2024 15:09
Simple Socket Chat Server in Rust. (TcpListener, TcpStream, SharedChan, RWArc)
extern mod sync;
// str op trait
use std::str::StrSlice;
// for tcp listen
use std::io::{TcpListener, TcpStream};
use std::io::net::ip::SocketAddr;
// for trait
use std::io::{Listener, Writer, Acceptor, Buffer};
// for spawn
@andelf
andelf / cpuid.rs
Created April 18, 2014 10:39
CPUID in Rust
#![feature(asm)]
use std::io;
fn cpuid(info: u32) -> (u32, u32, u32, u32) {
let (mut a, mut b, mut c, mut d) = (0,0,0,0);
unsafe {
asm!("mov $4, %eax
cpuid
// copied from rustdoc
/// Parses, resolves, and typechecks the given crate
fn get_ast_and_resolve(cpath: &Path, libs: HashSet<Path>, cfgs: Vec<~str>) -> (ast::Crate, CrateAnalysis) {
use syntax::codemap::dummy_spanned;
use rustc::driver::driver::{FileInput, build_configuration,
phase_1_parse_input,
phase_2_configure_and_expand,
phase_3_run_analysis_passes};
let input = FileInput(cpath.clone());
@andelf
andelf / proc_diff.py
Last active August 29, 2015 14:02
Monitor Process Creation and Quiting
import os
import commands
import time
def get_process():
procs = set()
for line in commands.getoutput("ps aux").split('\n'):
if not line: # or '%CPU' in line:
continue
proc = ' '.join(line.split()[10:])
@andelf
andelf / HashSet.swift
Last active August 29, 2015 14:02
Generic Hash Set in Swift
struct HashSet<T : Hashable> {
typealias Element = T
var _map: Dictionary<T, ()> = [:]
var count: Int {
return _map.count
}
var isEmpty: Bool {