Skip to content

Instantly share code, notes, and snippets.

@bofh19
bofh19 / currency.html
Created October 2, 2016 22:53
jquery currency format
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<input class="number">
<script type="text/javascript">
function setCurrencyFormat(elem){
elem.on('focusin', function(){
//console.log("Saving value " + $(this).val());
$(this).data('val', $(this).val());
});
elem.on('focusout', function(){
@bofh19
bofh19 / ng-really.js
Created October 2, 2015 14:33 — forked from asafge/ng-really.js
ng-really? An AngularJS directive that creates a confirmation dialog for an action.
/**
* A generic confirmation for risky actions.
* Usage: Add attributes: ng-really-message="Are you sure"? ng-really-click="takeAction()" function
*/
angular.module('app').directive('ngReallyClick', [function() {
return {
restrict: 'A',
link: function(scope, element, attrs) {
element.bind('click', function() {
var message = attrs.ngReallyMessage;
@bofh19
bofh19 / .screenrc
Created September 15, 2015 19:17
screenrc - copied from web
autodetach on
shell -${SHELL}
defscrollback 2024
startup_message off
hardstatus on
vbell off
hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %d/%m %{W}%c %{g}]'
// create table query for sqlite generated dynamically
private static String getDynamicTableName(Object temp) {
String table_name = temp.getClass().getSimpleName();
Field[] fields = temp.getClass().getDeclaredFields();
String out = "CREATE TABLE " + table_name + "(";
boolean contains_id = false;
boolean first_time = true;
for (Field field : fields) {
class JSONMiddleware(object):
"""
Process application/json requests data from GET and POST requests.
"""
def process_request(self, request):
if 'application/json' in request.META['CONTENT_TYPE']:
# load the json data
data = json.loads(request.body)
# for consistency sake, we want to return
# a Django QueryDict and not a plain Dict.
@bofh19
bofh19 / arch_install
Last active August 29, 2015 14:16 — forked from anonymous/arch_install
passwd
systemctl enable sshd.service
systemctl start sshd.service
parted -s /dev/sda mklabel gpt
parted -s /dev/sda mkpart "primary" "fat16" "50MB" "60MB"
parted -s /dev/sda mkpart "primary" "ext4" "1%" "99%"
parted -s /dev/sda set 1 bios_grub on
mkfs.ext4 /dev/sda2
@bofh19
bofh19 / client.py
Last active August 29, 2015 14:13 — forked from dbehnke/client.py
"""
client.py - AsyncIO Server using StreamReader and StreamWriter
This will create 200 client connections to a server running server.py
It will handshake and run similar to this:
Server: HELLO
Client: WORLD
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.graphics.Canvas;
// from https://gist.github.com/exavolt/2360410
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_opengl.h>
#include "OpenGL/glu.h"
@bofh19
bofh19 / java_hash_code.py
Created February 1, 2014 08:40
Java String.hashCode() in python
def java_string_hashcode(s):
h = 0
for c in s:
h = (31 * h + ord(c)) & 0xFFFFFFFF
return ((h + 0x80000000) & 0xFFFFFFFF) - 0x80000000