Skip to content

Instantly share code, notes, and snippets.

"use strict";
// appended odd string to avoid shadowing existing vars
function chatroomwidget_88ed71a($) {
if ($ === undefined) {
throw "chatroomwidget.js requires jQuery";
}
// TODO: get from query string
if (chatroomwidgetServerUrl === undefined) {
throw "chatroomwidgetServerUrl must be defined";
@hraban
hraban / poc.js
Last active August 29, 2015 14:04
encode array of strings literal in js by length
// Copyright © 2014 Hraban Luyat <hraban@0brg.net>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
@hraban
hraban / getrandomparagraph.scala
Created February 6, 2015 00:31
Get a random paragraph from a file
import scala.io
import scala.util.Random
object RandomQuote {
private def splitParagraphs(r: io.BufferedSource) =
r.mkString.split("\n\n")
private def getRandomElement[T](ar: Array[T]): Option[T] = ar.length match {
case 0 => None
case _ => Some(ar(Random.nextInt(ar.length)))
@hraban
hraban / test.c
Last active August 29, 2015 14:16
Memcpy vs pointer dereference
/**
* Memcpy demonstration. Try compiling with:
*
* $ gcc -Wall -Werror -pedantic -std=c99 -S test.c -o test-deref.s
* $ gcc -Wall -Werror -pedantic -std=c99 -S test.c -DMEMCPY -o test-memcpy.s
* $ diff -u test-deref.s test-memcpy.s
*
* And play with -O0 to -O3 flags to see the effect of optimizations.
*/
@hraban
hraban / config.guess
Last active August 29, 2015 14:20
Building opus with emscripten
#! /bin/sh
# Attempt to guess a canonical system name.
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
# 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
# 2011, 2012 Free Software Foundation, Inc.
timestamp='2012-02-10'
# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
@hraban
hraban / pre-commit.md
Last active April 18, 2024 06:46
Prevent accidentally committing debug code in Git
@hraban
hraban / faviconchanger.html
Created July 7, 2015 11:48
animated favicon without gif
<!doctype html>
<html>
<head>
<link rel=icon id=favicon >
<script>
var i = 0;
setInterval(function () {
i=(i+1)%4;
@hraban
hraban / deploy-utils.sh
Last active August 29, 2015 14:27
Bash utils for deploy scripts
#!/bin/bash
# Copyright (c) Hraban Luyat 2015 <hraban@0brg.net>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
@hraban
hraban / .bash_aliases
Last active June 12, 2018 22:37
bash aliases
#!/bin/bash
#### GIT STUFF
# gitlog only the specified revision(s), e.g. $ gitlog1 master some-feature-branch
alias gitlog1='git log --color --graph --format="format:%C(normal bold)%h%Creset %s%C(red)%d%Creset (%C(yellow)%aN%Creset, %C(green)%ar%Creset)"'
# Entire git commit history with tree and colors and branch names
alias gitlog='gitlog1 --all --branches=\* --remotes=\*'
@hraban
hraban / import-finder.py
Created February 11, 2016 16:41
Find the full import chain from one go package to another
#!/usr/bin/env python3
'''
Find the full import chain from one go package to another.
Usage:
import-finder.py source_package target_package
This is useful in large codebases to figure out why, for example, the testing package is
included in a resulting binary.