Skip to content

Instantly share code, notes, and snippets.

@janosgyerik
janosgyerik / rearrange.cpp
Created March 1, 2013 08:12
A program to print all possible arrangements of `n` numbers. It accepts `n` as a command line parameter. Be careful, as there are `n!` possible permutations. With `n=10` or greater the program will be extremely slow.
#include <stdio.h>
#include <stdlib.h>
void rearrange(int *numbers, int index, int num) {
int tmp;
for (int i = index; i < num; ++i) {
tmp = numbers[index];
numbers[index] = numbers[i];
numbers[i] = tmp;
rearrange(numbers, index + 1, num);

10 cool features of GitHub even if you don't know Git (yet...)

  1. Gists: random notes, code snippets, syntax highlighting, version control, clone
  2. Embedding Gists in your blog, syntax highlighting
  3. New repo at an instance
  4. wiki
  5. In-browser editing
  6. issue tracking even for projects NOT on github
  7. code reviews
  8. gh-pages
@janosgyerik
janosgyerik / 10-cool-features-of-vim.md
Last active December 17, 2015 17:09
Collecting ideas for a presentation about how awesome is Vim

Cool things other editors can't do or not easily, but easy in vim.

Create a macro to replace all occurences of:

{% url package.module.method %}

with:

{% url 'package.module.method' %}
@janosgyerik
janosgyerik / playercorefactory.xml
Last active December 17, 2015 17:49
Custom configuration for XBMC to use VLC for local video files only, and continue to use the built-in player for others.
<playercorefactory>
<players>
<player name="VLC" type="ExternalPlayer" video="true">
<filename>/usr/bin/vlc</filename>
<args>--play-and-exit --video-on-top --fullscreen</args>
<forceontop>false</forceontop>
<hidexbmc>false</hidexbmc>
<hideconsole>false</hideconsole>
<hidecursor>false</hidecursor>
</player>
@janosgyerik
janosgyerik / convert-deployment-to-release-mirror.sh
Last active December 18, 2015 04:19
Create a mirror Git repository from an existing Git project directory for the purpose of release management using a post-receive hook
# go to the directory where the site is deployed
cd ~/project/dir
# initialize empty Git repo for release purposes
git init --bare ~/repos/git/releases/project.git
# add the repo as a remote called "releases"
git remote add releases ~/repos/git/releases/project.git
# create the "beta" branch locally and switch to it
@janosgyerik
janosgyerik / post-receive
Last active November 2, 2016 06:57
A post-receive hook that runs a script if changes were pushed to a specific branch. (Hook scripts are in the hooks/ directory of a Git repository, and must be executable.)
#!/bin/sh
# 1. Create symlinks to the real upgrade scripts for each branch, for example:
# ./upgrade-beta.sh # will only be called when "beta" branch is updated
# ./upgrade-prod.sh # will only be called when "prod" branch is updated
#
# 2. Put these symlinks in the repository root, NOT in the hooks/ directory
# the post-receive hook receives parameters on stdin
while read oldrev newrev refname
@janosgyerik
janosgyerik / upgrade.sh
Created June 9, 2013 22:44
Site upgrade script for a Django site using mod_passenger with Apache.
#!/bin/sh -e
#
# Put this script in /path/to/project/local/upgrade.sh
# and customize if necessary
cd $(dirname "$0")/..
projectname=$(basename $(pwd))
. ~/virtualenv/$projectname/bin/activate
@janosgyerik
janosgyerik / multilang.md
Last active December 18, 2015 12:59
syntax highlighting with multiple languages

HTML5 boilerplate

<!DOCTYPE html>
<html lang="en-us">
    <head>
        <meta charset="utf-8">
        <title>HTML5 Boilerplate: The web's most popular front-end template</title>
        <meta name="description" content="HTML5 Boilerplate is a professional front-end template for building fast, robust, and adaptable web apps or sites. Spend more time developing and less time reinventing the wheel.">
 
@janosgyerik
janosgyerik / connect-to-bluetooth.java
Last active December 18, 2015 13:09
Connect to a Bluetooth device from Android
// connect to a Bluetooth device from Android
Socket socket = null;
try {
device.createRfcommSocketToServiceRecord(MY_UUID);
Method m = device.getClass().getMethod("createRfcommSocket", new Class[] {int.class});
socket = (BluetoothSocket) m.invoke(device, 1);
} catch (IOException e) {
Log.e(TAG, "create() failed", e);
}
@janosgyerik
janosgyerik / multilang2.md
Last active December 18, 2015 13:09
Demonstrate syntax highlighting of multiple languages within the same gist.
// where the hell my log4j settings come from??
System.out.println(Loader.getResource("log4j.properties"));
System.out.println(Loader.getResource("log4j.xml"));
-- "create" a user in MySQL
GRANT ALL PRIVILEGES ON dbname.* TO 'dbuser'@localhost IDENTIFIED BY 'userpass';