Skip to content

Instantly share code, notes, and snippets.

View Wilfred's full-sized avatar

Wilfred Hughes Wilfred

View GitHub Profile
@Wilfred
Wilfred / logstash-conf.el
Last active August 29, 2015 14:07
logstash-conf.el
;;; logstash-conf.el -- basic mode for editing logstash configuration
;; Copyright (C) 2014 Wilfred Hughes <me@wilfred.me.uk>
;;
;; Author: Wilfred Hughes <me@wilfred.me.uk>
;; Created: 21 October 2014
;; Version: 0.2
;;; Commentary:
;; `conf-mode' offers adequate highlighting for Logstash configuration

Macros Crash Course

Firstly, a macro is evaluated at compile-time, not runtime.

;; Define a function and macro that both
;; return the current time.
(defun get-current-time-fn ()
  (second (current-time)))

(defmacro get-current-time-mac ()

;; http://lists.gnu.org/archive/html/emacs-devel/2014-10/msg00962.html
;; eval this buffer and then start modifying the data in the table below.
;;
;; ------------
;; Alpha | 50
;; Beta | 35
;; Gamma | 64
;; Delta | 20
;; Epsilon | 80
;;
@Wilfred
Wilfred / sourcegraph_feedback.md
Last active August 29, 2015 14:10
Sourcegraph feedback

So, I've played with Sourcegraph, and I love the concept. I love the idea of being able to explore usage of functions and jumping to the original version.

I'm a Python programmer who likes Django, so I chose render_to_response as a function to try. It's a function I've used plenty and it's pure-python, so I assume it must be indexed.

https://sourcegraph.com/search?q=render_to_response shows the django-nonrel fork, but not the official django sources.

@Wilfred
Wilfred / main.c
Created January 21, 2015 23:24
Unexpected clang build warning
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <alloca.h>
void eval_program(char *program) {
int program_len = strlen(program);
int data_index = 0, instruction_index = 0;
@Wilfred
Wilfred / iterators.rs
Created May 29, 2015 23:09
Adding methods to Iterator
trait Greet {
fn say_hello(&self) -> ();
}
impl Greet for Iterator {
fn say_hello(&self) {
println!("hello from an iterator!");
}
}
class DiningPhilosophers {
public static void main(String[] args) {
Fork[] forks = new Fork[5];
for (int i=0; i<forks.length; i++) {
forks[i] = new Fork();
}
Philosopher p1 = new Philosopher(1,forks[0],forks[1]);
Philosopher p2 = new Philosopher(2,forks[1],forks[2]);
Philosopher p3 = new Philosopher(3,forks[2],forks[3]);
; don't show the tool bar, should use keyboard anyway
(if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
; auctex stuff for latex editing
(load "auctex.el" nil t t)
(load "preview-latex.el" nil t t)
; auto-fill (linewrap) on by default
(setq-default auto-fill-function 'do-auto-fill)
<?php
//based on http://lists.w3.org/Archives/Public/www-validator/2007Jul/0208.html
$mime = 'text/html'; //fallback
// set xhtml mimetype if browser claims it accepts it:
if(!empty($_SERVER['HTTP_ACCEPT']) && stristr($_SERVER['HTTP_ACCEPT'],'application/xhtml+xml')) {
$mime = 'application/xhtml+xml';
}
// or if it is the validator:
if (stristr($_SERVER["HTTP_USER_AGENT"],"W3C_Validator") OR stristr($_SERVER["HTTP_USER_AGENT"],"W3C_CSS_Validator") OR
stristr($_SERVER["HTTP_USER_AGENT"],"WDG_Validator")) {
(* church booleans *)
fun True x y = x;
fun False x y = y;
(*conditionals*)
fun If b x y = b x y;
fun Or b1 b2 x y = b1 x (b2 x y);
fun Xor b1 b2 x y = b1 (b2 y x) (b2 x y);
fun And b1 b2 x y = b1 (b2 x y) y;
fun Nand b1 b2 x y = b1 (b2 y x) x;