Skip to content

Instantly share code, notes, and snippets.

View danhper's full-sized avatar

Daniel Perez danhper

View GitHub Profile
@danhper
danhper / .xinitrc
Created February 16, 2013 13:41
X ibus config
export XMODIFIERS="@im=ibus"
export XIM=ibus
export XIM_PROGRAM=/usr/bin/ibus-daemon
export XIM_ARGS="--xim"
export GTK_IM_MODULE="ibus"
export QT_IM_MODULE="ibus"
ibus-daemon --xim -d
-> % echo 3 | _ tee /proc/sys/vm/drop_caches
3
-> % cat /proc/meminfo | grep -i memfree
MemFree: 5603952 kB
-> % time diff -crBNp linux-source-2.6.32 linux-source-2.6.32-prolog-scache-check > k06+ccheck+reset.patch
diff -crBNp linux-source-2.6.32 linux-source-2.6.32-prolog-scache-check > 1.51s user 2.93s system 21% cpu 20.849 total
-> % cat /proc/meminfo | grep -i memfree
@danhper
danhper / union_example.c
Created February 17, 2013 08:51
Example usage of union
#include <stdio.h>
#include <stdlib.h>
typedef union {
int i;
double d;
} int_or_double;
typedef enum {
INT,
@danhper
danhper / types.hpp
Created February 20, 2013 16:05
C++ implementation of X protocol events
#include <iostream>
//namespace protocol {
//namespace type {
struct event {
enum event_enum {
key_press = 0x00000001,
key_release = 0x00000002,
button_press = 0x00000004,
// many others
@danhper
danhper / httpd-vhosts.conf
Created March 17, 2013 18:52
httpd-vhosts.conf
NameVirtualHost *:80
<VirtualHost *:80>
<Directory "E:/Documents/blog">
Require all granted
</Directory>
DocumentRoot "E:/Documents/blog"
ServerName localhost
DirectoryIndex index.html
ErrorLog "logs/localhost-error.log"
@danhper
danhper / ImplicitTest.scala
Created May 5, 2013 10:03
Scala implicit method
object Foo {
implicit def foo(): Unit = println("foo")
def bar(implicit f: () => Unit) = f()
}
object Main {
def main(args: Array[String]): Unit = {
Foo.bar
}
@danhper
danhper / foo.js
Last active December 18, 2015 04:08
JS static method
function Foo() {}
Foo.myStaticMethod = function() {
console.log("what a cool method!");
};
Foo.myStaticMethod();
#include <stdio.h>
int main(void)
{
int a, i = 2;
printf("enter num: ");
scanf("%d", &a);
printf("%d = ", a);
while(a > 1) {
int n = 0;
// wrong
switch(foo) {
case 1:
NSString* bar = @"foobar"; // expected expression
// use bar
}
// compiles
switch(foo) {
case 1: {

switch文について

Objective-C(に限りませんけど)では、条件を書く手段がいくつかある。一番よく使うのはおそらくif文。例えば

int a = 10;
if(a < 10) {
    NSLog(@"a is small");
} else {
 NSLog(@"a is big");