Skip to content

Instantly share code, notes, and snippets.

@elleryq
elleryq / enconvert.py
Created February 5, 2014 03:33
Code clip from puddletag
# Contributed by Stjujsckij Nickolaj
def enconvert(text, enc_name):
''' Convert from non-standard encoding, "Convert to encoding: $0, Encoding: $1"
&Encoding, combo, cp1250, cp1251, cp1252, cp1253, cp1254, cp1255, cp1256, cp1257, cp1258'''
return text.encode("latin1", 'replace').decode(enc_name, 'replace')
@elleryq
elleryq / .npmrc
Last active August 29, 2015 13:57
nodejs/npm setup. HOME=/home/user
prefix = /home/user/.local
root = /home/user/.local/lib/node_modules
binroot = /home/user/.local/bin
manroot = /home/user/.local/share/man
@elleryq
elleryq / string_references.php
Created April 8, 2014 09:02
To reproduce "PHP Fatal error: Cannot create references to/from string offsets nor overloaded objects"
<?php
$widgets = array();
$widgets['a'] = 'hello';
print($widgets['a'][0]); // show 'h'
print("\n");
$o = & $widgets['a'][0]; // Show "Cannot create references to/from string offsets"
//print($o);
?>
@elleryq
elleryq / 0_reuse_code.js
Created June 5, 2014 07:20
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@elleryq
elleryq / Feednix.patch
Created June 25, 2014 02:56
Simple patch for Feednix. This patch fix compile error in clang.
diff --git a/src/FeedlyProvider.cpp b/src/FeedlyProvider.cpp
index 5303901..d345613 100644
--- a/src/FeedlyProvider.cpp
+++ b/src/FeedlyProvider.cpp
@@ -194,8 +194,14 @@ const std::vector<PostData>* FeedlyProvider::giveStreamPosts(const std::string&
return NULL;
}
- for(unsigned int i = 0; i < root["items"].size(); i++)
- feeds.push_back(PostData{root["items"][i]["summary"]["content"].asString(), root["items"][i]["title"].asString(), root["items"][i]["id"].asString(), root["items"][i]["originId"].asString()});
@elleryq
elleryq / reverse.c
Created July 7, 2014 03:15
reverse a string in C
#include <stdlib.h>
#include <string.h>
#include <assert.h>
char* reverse(char* s) {
assert(s!=NULL);
char *r = (char*)strdup(s);
int len = strlen(s);
if(r==NULL) {
@elleryq
elleryq / toupper.cpp
Created July 7, 2014 03:21
Upper a string in C++
#include <string>
#inculde <sstream>
std::string toupper(std::string& s) {
for(std::string::iterator c=s.begin(); c!=s.end(); c++) {
*c = std::toupper(*c);
}
return s;
}
@elleryq
elleryq / rpmqa.py
Last active August 29, 2015 14:03
rpmqa.py from Fedora RPM guide.
#!/usr/bin/python
# https://docs.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html/RPM_Guide/ch-rpm-programming-python.html
# Acts like rpm -qa and lists the names of all the installed packages.
# Usage:
# python rpmqa.py
import rpm
ts = rpm.TransactionSet()
mi = ts.dbMatch()
#for p in mi:
@elleryq
elleryq / tokenize.cpp
Created July 8, 2014 06:44
Split string according to space and convert each token to uppercase.
#include <sstream>
#include <iostream>
#include <string>
#include <algorithm>
std::string toupper(std::string& s) {
for(std::string::iterator c=s.begin(); c!=s.end(); c++) {
*c = std::toupper(*c);
}
return s;
@elleryq
elleryq / checksum.c
Created July 8, 2014 06:48
For each 512 bytes in the input binary file, calculate the 16-bit checksum and write the 512 bytes with the checksum as the 512th byte to the output binary file. At the end of the file, pad bytes might need to be added if the remaining byes in the input binary file is less then 512 bytes. If present, each pad byte shall be set to 0xff.
#include <stdio.h>
#include <stdlib.h>
#define BUFFER_SIZE 512
int doPadding(char* buffer, int startOffset) {
int i;
for(i = startOffset; i<BUFFER_SIZE; ++i) {
*(buffer+i) = 0xff;