Skip to content

Instantly share code, notes, and snippets.

View ameliaikeda's full-sized avatar
💜
probably drinking tea

Amelia Wylie ameliaikeda

💜
probably drinking tea
View GitHub Profile
function get_user_array() {
if (isset($_SESSION["id"])) {
$sid = $_SESSION["id"];
if ($query = $db->prepare("SELECT id, name, status from `users` where id=?")) {
$query->bind_param("i", $sid);
$query->execute();
$query->bind_result($id, $name, $status);
if (!$query->fetch()) {
$query->close();
$db->close();
@ameliaikeda
ameliaikeda / commands.py
Last active December 13, 2015 19:08
A gist to stick a push notifications addition into hanyuu, until i clone the repo.
# in Class Song
# -- in method faves
@property
def api_keys(self):
keys_dict = {}
with manager.MySQLCursor as cur:
cur.execute("SELECT enick.apikey, enick.type FROM esong JOIN efave ON "
"efave.isong = esong.id JOIN enick ON efave.inick = "
"enick.id WHERE esong.hash = %s AND "
with MySQLCursor() as cur: # MySQLCursor is an auth wrapper around MySQLdb.cursor
with open('all', 'r') as f:
for line in f: # this file is terrifyingly huge
if line.startswith "#" or not line: # comment, wordlist boundary
continue
cur.execute("INSERT IGNORE INTO wordlist (word) VALUES (%s)", (line,))
<?php
require_once 'downloader/Maged/Controller.php';
define('MAGE_VERSION', Maged_Controller::getVersion());
/**
* @global PDO the database connection used globally
*/
$DB = null;
/**
@ameliaikeda
ameliaikeda / lol.php
Created March 6, 2013 09:13
I have to refactor this.
<?php
/******************************************************************
Configuration Section.
Options: Array of colours, colour codes and option codes.
["colour" => (string) "description",
"colour_code" => (string) "hex_code", "opt_code" => (int) "option_code"]
Fatal error: Cannot redeclare colour_sku() (previously declared in /domains/x/http/SizeCalc.php:531) in /domains/x/http/SizeCalc.php on line 531
<?php
/*
** mage_update:
** Relies on Magento's Varien Object __call() magic method to save to database attribute fields.
** Lack of error-handling™ because this is a batch script and Magento is in Developer Mode.
** Note that this is called in one hell of a loop (~3.4 million iterations), so keep it relatively speedy.
**
** lower_case_with_underscores becomes CamelCase
** UPPERCASE becomes Capitalized, yadda yadda.
**
Use of the `mysql_*` functions in PHP is discouraged in favour of [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli)  ([find out why](http://stackoverflow.com/questions/12859942))

Use of the mysql_* functions in PHP is discouraged in favour of PDO or MySQLi (find out why)

@ameliaikeda
ameliaikeda / sorter.py
Created March 14, 2013 15:58
I was given an hour to mass-rename 100k files in various folders. challenge accepted. (and the script took 5 minutes)
import os
import MySQLdb
import re
class ImageSorter(object):
def __init__(self, base_directory):
self.cur = MySQLdb.connect(host='127.0.0.1', user="root", db="magento").cursor() # come at me
self.skus = {}
self.directory = base_directory
@ameliaikeda
ameliaikeda / hl.py
Created March 17, 2013 15:31
Hexchat highlights script
# Hiroto's HL script.
__module_name__ = "PyHighlights"
__module_version__ = "v0.1"
__module_description__ = "Script to shove highlights into another window."
import urllib2
import urllib
import xchat
context = xchat.get_context()
xchat.command("QUERY highlights")