Skip to content

Instantly share code, notes, and snippets.

@fossil12
fossil12 / comments.c
Last active March 10, 2016 01:58
How do you comment on if/else clauses in C (Objective-C, ...)?
/*
* Variant 1
*/
if (cond) {
// Description of condition holding in if
// code...
} else {
// Description of condition holding in else
// code...
@fossil12
fossil12 / gist:0a7620864b7c0f29bd55
Last active August 29, 2015 14:22
Bug or error?
struct StructWithArray {
var arrayInStruct: [Int]
init() {
arrayInStruct = [Int]()
}
}
var structs = [StructWithArray()]
// playground crashes when using this line
class Test {
let coder: String
convenience init() {
self.init(coder: "default coder")
}
init(coder: String) {
self.coder = coder
}
@fossil12
fossil12 / C.sublime-build
Created January 15, 2014 19:50
Sublime Text 2 Build System for C on OS X. (Just move/copy file to `Packages/User`.)
{
"cmd": ["gcc", "${file}", "-o", "${file_path}/${file_base_name}", "-Wall"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c",
"variants":
[
{
"name": "Run",
@fossil12
fossil12 / archiv.example.com.apacheconf
Last active December 12, 2015 05:08
Apache: mod_rewrite if 404 redirect to archive and back (if 404 - no loop!)
# Redirects for 404 to www.example.com
# adds "?redirected" to url that www.example.com doesn't redirect back
# (basic idea form http://stackoverflow.com/a/11078887/286611)
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) http://www.example.com/$1?redirected [R=301,L,QSA]
# Location of the error document
ErrorDocument 404 /404.html
@fossil12
fossil12 / gist:4719116
Created February 6, 2013 00:28
Apache: Debug mod_rewrite on hosted server
RewriteCond %{QUERY_STRING} !vardump
RewriteRule (.*) http://www.example.com/$1?vardump&thereq=%{THE_REQUEST}&reqhost=%{HTTP_HOST}&rem_host=%{REMOTE_HOST} [R=301,L,QSA]
@fossil12
fossil12 / gist:4644513
Last active December 11, 2015 18:49
Apache: Deny access to git specific files on a webserver (all folders). (from http://serverfault.com/a/251003)
# deny access to the top-level git repository:
RewriteRule "^(.*/)?\.git" - [F,L]
@fossil12
fossil12 / dabblet.css
Last active September 29, 2015 14:17
Web: My first dabblet-test
/**
* My first dabblet-test
*/
background: #f06;
background: linear-gradient(bottom, #ada976, #390);
min-height:100%;